xref: /trunk/main/xml2cmp/source/finder/dependy.hxx (revision dd7bc091)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef X2C_DEPENDY_HXX
25 #define X2C_DEPENDY_HXX
26 
27 
28 #include <vector>
29 #include <map>
30 #include <set>
31 #include <../support/sistr.hxx>
32 
33 class Service;
34 class ServiceInfo;
35 
36 typedef std::vector< Simstr> 			StringVector;
37 typedef std::vector< ServiceInfo* > 	List_Implementations;
38 typedef std::map< Simstr, Service* >	Map_Services;
39 
40 class Service
41 {
42   public:
43 						Service(
44 							const char *		i_sName );
45 
46 	ServiceInfo &		AddImplementation(
47 							const char *		i_sLibrary );	/// That is: module-name.
48 
Name() const49 	const Simstr &		Name() const			{ return sName; }
FirstImplementation() const50 	const ServiceInfo &	FirstImplementation() const
51 												{ return *aImplementations[0]; }
52 
53   private:
54 	Simstr				sName;
55 	List_Implementations
56 						aImplementations;
57 };
58 
59 class ServiceInfo
60 {
61   public:
62 	typedef StringVector List_NeededServices;
63 
64 						ServiceInfo(
65 							const char *		i_sLibrary );
66 
67 	void				AddDependency(
68 							const char *		i_sNeededService );
69 
Library() const70 	const Simstr &		Library() const			{ return sImplementingLibrary; }
71 	const List_NeededServices &
NeededServices() const72 						NeededServices() const	{ return aNeededServices; }
73 
74 
75   private:
76 	Simstr				sImplementingLibrary;
77 	List_NeededServices	aNeededServices;
78 };
79 
80 
81 class DependencyFinder
82 {
83   public:
84 						DependencyFinder();
85 						~DependencyFinder();
86 
87 	void				GatherData(
88 							const char *		i_sSearchDirectory );
89 
90 	void				FindNeededServices(
91 							StringVector &		o_rLibraries,
92 							StringVector &		o_rServices,
93 							const Simstr &		i_rService );
94   private:
95 	void				ReadFile(
96 							const char * 		i_sFilename );
97 	void               	Add2Result(
98 							const Service &		i_rService );
99 
100 	// Data
101 	Map_Services		aServices;
102 
103 	// Temporary data
104 	std::set< Simstr >	aResult_Libraries;
105 	std::set< Simstr >	aResult_Services;
106 };
107 
108 
109 
110 #endif
111 
112 
113