1 | #ifndef morpheo_behavioural_configuration_Instance_h |
---|
2 | #define morpheo_behavioural_configuration_Instance_h |
---|
3 | |
---|
4 | /* |
---|
5 | * $Id: Instance.h 88 2008-12-10 18:31:39Z rosiere $ |
---|
6 | * |
---|
7 | * [ Description ] |
---|
8 | * |
---|
9 | */ |
---|
10 | |
---|
11 | #include "Behavioural/Configuration/include/Parameter_affectation.h" |
---|
12 | #include "Behavioural/Configuration/include/Link_affectation.h" |
---|
13 | #include "Behavioural/Configuration/include/Generator.h" |
---|
14 | #include "Behavioural/Configuration/include/Parameters.h" |
---|
15 | #include "Behavioural/Custom/include/Custom.h" |
---|
16 | |
---|
17 | #include <map> |
---|
18 | #include <vector> |
---|
19 | #include <cstdarg> |
---|
20 | |
---|
21 | namespace morpheo { |
---|
22 | namespace behavioural { |
---|
23 | namespace configuration { |
---|
24 | |
---|
25 | class Instance_component; |
---|
26 | |
---|
27 | typedef std::map<std::string, Parameter_affectation *> list_parameters_t; |
---|
28 | typedef std::map<std::string, Link_affectation *> list_link_t; |
---|
29 | typedef std::map<std::string, list_link_t> list_links_t; |
---|
30 | typedef std::map<std::string, Instance_component *> list_instances_t; |
---|
31 | typedef std::map<std::string, list_instances_t> list_components_t; |
---|
32 | |
---|
33 | class Instance_component |
---|
34 | { |
---|
35 | public : const std::string _name; |
---|
36 | public : const std::string _id; |
---|
37 | public : list_parameters_t * _list_parameters; |
---|
38 | //public : list_links_t * _list_links; |
---|
39 | public : list_components_t * _list_components; |
---|
40 | |
---|
41 | public : Instance_component (std::string name, |
---|
42 | std::string id): |
---|
43 | _name (name), |
---|
44 | _id (id) |
---|
45 | { |
---|
46 | _list_parameters = new list_parameters_t; |
---|
47 | // _list_links = new list_links_t ; |
---|
48 | _list_components = new list_components_t; |
---|
49 | } |
---|
50 | |
---|
51 | public : ~Instance_component (void) |
---|
52 | { |
---|
53 | for (list_parameters_t::iterator it = _list_parameters->begin(); |
---|
54 | it != _list_parameters->end(); |
---|
55 | ++it) |
---|
56 | delete it->second; |
---|
57 | delete _list_parameters; |
---|
58 | |
---|
59 | // for (list_links_t::iterator it1 = _list_links->begin(); |
---|
60 | // it1 != _list_links->end(); |
---|
61 | // ++it1) |
---|
62 | // for (list_link_t::iterator it2 = it1->second.begin(); |
---|
63 | // it2 != it1->second.end(); |
---|
64 | // ++it2) |
---|
65 | // delete it2->second; |
---|
66 | // delete _list_links; |
---|
67 | |
---|
68 | for (list_components_t::iterator it1 = _list_components->begin(); |
---|
69 | it1 != _list_components->end(); |
---|
70 | ++it1) |
---|
71 | for (list_instances_t::iterator it2 = it1->second.begin(); |
---|
72 | it2 != it1->second.end(); |
---|
73 | ++it2) |
---|
74 | delete it2->second; |
---|
75 | delete _list_components; |
---|
76 | } |
---|
77 | |
---|
78 | #undef FUNCTION |
---|
79 | #define FUNCTION "Instance_component::toXML" |
---|
80 | public : XML toXML (void) |
---|
81 | { |
---|
82 | log_begin(Configuration,FUNCTION); |
---|
83 | |
---|
84 | XML xml (_name); |
---|
85 | |
---|
86 | xml.balise_open_begin(_name); |
---|
87 | xml. attribut("id" ,_id); |
---|
88 | xml.balise_open_end(); |
---|
89 | |
---|
90 | for (list_parameters_t::iterator it = _list_parameters->begin(); |
---|
91 | it != _list_parameters->end(); |
---|
92 | ++it) |
---|
93 | xml.insert_XML(it->second->toXML(),1); |
---|
94 | |
---|
95 | // for (list_links_t::iterator it1 = _list_links->begin(); |
---|
96 | // it1 != _list_links->end(); |
---|
97 | // ++it1) |
---|
98 | // for (list_link_t::iterator it2 = it1->second.begin(); |
---|
99 | // it2 != it1->second.end(); |
---|
100 | // ++it2) |
---|
101 | // xml.insert_XML(it2->second->toXML(),1); |
---|
102 | |
---|
103 | for (list_components_t::iterator it1 = _list_components->begin(); |
---|
104 | it1 != _list_components->end(); |
---|
105 | ++it1) |
---|
106 | for (list_instances_t::iterator it2 = it1->second.begin(); |
---|
107 | it2 != it1->second.end(); |
---|
108 | ++it2) |
---|
109 | xml.insert_XML(it2->second->toXML(),1); |
---|
110 | |
---|
111 | xml.balise_close(); |
---|
112 | |
---|
113 | log_end(Configuration,FUNCTION); |
---|
114 | return xml; |
---|
115 | } |
---|
116 | |
---|
117 | #undef FUNCTION |
---|
118 | #define FUNCTION "Instance_component::print" |
---|
119 | private : std::string print (uint32_t depth) |
---|
120 | { |
---|
121 | log_begin(Configuration,FUNCTION); |
---|
122 | |
---|
123 | std::string _return = (toXML()).get_body(depth); |
---|
124 | |
---|
125 | log_end(Configuration,FUNCTION); |
---|
126 | return _return; |
---|
127 | }; |
---|
128 | |
---|
129 | #undef FUNCTION |
---|
130 | #define FUNCTION "Instance_component::operator<<" |
---|
131 | public : friend std::ostream& operator<< (std::ostream& output, |
---|
132 | morpheo::behavioural::configuration::Instance_component & x) |
---|
133 | { |
---|
134 | log_begin(Configuration,FUNCTION); |
---|
135 | output << x.print(0); |
---|
136 | log_end(Configuration,FUNCTION); |
---|
137 | return output; |
---|
138 | }; |
---|
139 | }; |
---|
140 | |
---|
141 | |
---|
142 | class Instance |
---|
143 | { |
---|
144 | // -----[ fields ]---------------------------------------------------- |
---|
145 | private : std::string _name; |
---|
146 | private : std::string _filename; |
---|
147 | //private : list_parameters_t * _array; |
---|
148 | |
---|
149 | public : list_parameters_t * _list_parameters; |
---|
150 | public : list_links_t * _list_links; |
---|
151 | public : list_components_t * _list_components; |
---|
152 | |
---|
153 | private : Generator * _generator; |
---|
154 | public : Parameters * _param; |
---|
155 | |
---|
156 | // -----[ methods ]--------------------------------------------------- |
---|
157 | public : Instance (std::string filename, |
---|
158 | Generator * generator, |
---|
159 | behavioural::custom::custom_information_t (*get_custom_information) (void)); |
---|
160 | public : ~Instance (); |
---|
161 | |
---|
162 | public : std::string getName (void); |
---|
163 | private : std::string getParam (const char * name, ...); |
---|
164 | private : std::vector<std::string> getLink (const char * name, ...); |
---|
165 | private : std::vector<std::string> link2array (std::string str); |
---|
166 | |
---|
167 | // Test : parameter, link, component |
---|
168 | public : void test (std::string type, |
---|
169 | std::string value); |
---|
170 | public : void test (std::string type, |
---|
171 | std::string father_name, |
---|
172 | bool father_is_src, |
---|
173 | bool father_is_dest); |
---|
174 | private : void test (std::string link, |
---|
175 | std::vector<std::string> & vect, |
---|
176 | uint32_t nb_elt); |
---|
177 | private : void test_use (void); |
---|
178 | private : void test_use (std::string name, |
---|
179 | list_parameters_t * list_parameters, |
---|
180 | list_components_t * list_components, |
---|
181 | std::vector<std::string> & list_not_use); |
---|
182 | |
---|
183 | private : void fromInternalStructure(void); |
---|
184 | |
---|
185 | private : void fromXMLLight(XML_t * xml, |
---|
186 | attribute_t id, |
---|
187 | list_parameters_t * list_parameters, |
---|
188 | list_links_t * list_links, |
---|
189 | list_components_t * list_component); |
---|
190 | |
---|
191 | private : void fromFile (std::string filename); |
---|
192 | |
---|
193 | public : void toFile (std::string dirname="."); |
---|
194 | private : XML toXML (void); |
---|
195 | private : std::string print (uint32_t depth); |
---|
196 | public : friend std::ostream& operator<< (std::ostream& output, |
---|
197 | morpheo::behavioural::configuration::Instance & x); |
---|
198 | |
---|
199 | }; |
---|
200 | |
---|
201 | }; // end namespace configuration |
---|
202 | }; // end namespace behavioural |
---|
203 | }; // end namespace morpheo |
---|
204 | |
---|
205 | #endif |
---|