C++ main module for mmsd Package  1.0
UI_Class.hpp
Go to the documentation of this file.
1 #ifndef UI_Class_HPP
2 #define UI_Class_HPP
3 
4 
5 
6 template<class T>
8 
9  SP::CORE_ClassFactory factory=getFactory();
10 
11  // verify the factory is set
12  if (factory.get()==null) throw CORE_Exception("UI","UI_Class::saveAssociation","factory not set");
13 
14  // get the number of objects to store
15  int n=objs.getSize();
16 
17  if (n>0) {
18 
19  // create a classes list
20  tBoolean isComposite=true;
21  createClassesList(name,isComposite,n);
22 
23  // fill the field f
24  SP::UI_Class fi;
25  const CORE_Object *object;
26  const UI_Object *uiObject;
27 
28  for (int i=0;i<n;i++) { // loop on objects to store
29  object=objs.get(i);
30  if (object==null) continue;
31  uiObject=dynamic_cast<const UI_Object *>(object);
32 
33 
34  // test if the ui_class corresponding to obj has already been created
35  fi=dynamic_sp_cast<UI_Class>(factory->getClass(object->getIdentityString()));
36  if (fi.get()==null) {
37  // create the UI class to save the class uiObject
38  fi=NewInstance();
39  // set the factory
40  fi->setFactory(factory);
41  // set the interface type
42  fi->setInterfaceType(getInterfaceType());
43  // transfert the kind of copy for array
44  fi->setIsArrayCopied(isArrayCopied());
45  // create the UI structure
46  fi->createClass(object->getIdentityString());
47  // register the UI_Class
48  factory->addClass(object->getIdentityString(),fi);
49  // save the uiObject in the uiClass fi if possible
50  if (uiObject!=null) uiObject->saveToUIClass(*fi.get());
51  // finalize
52  fi->finalize();
53  }
54 
55  // store the fi object in f
56  setClassIntoList(name,i,*fi.get());
57  }
58  } //end loop on n
59 }
60 
61 template<class T>
63 
64  SP::CORE_ClassFactory factory=getFactory();
65  // verify the factory is set
66  if (factory.get()==null) throw CORE_Exception("UI","UI_Class::loadAssociation","factory not set");
67 
68  // return true if no field
69  if (!hasField(name)) return;
70 
71  // object created
72  boost::shared_ptr<T> obj;
73 
74 
75 
76  // create a new ui class for each object to load
77  SP::UI_Class fi=NewInstance();
78 
79  // set the factory
80  fi->setFactory(factory);
81 
82  // set the interface type
83  fi->setInterfaceType(getInterfaceType());
84 
85  // transfert the kind of copy for array
86  fi->setIsArrayCopied(isArrayCopied());
87 
88  // clear the list
89  objects.clear();
90 
91 
92  // get the number of elements
93  int n=getClassesListSize(name);
94 
95  for (int i=0;i<n;i++) { // loop on elements
96 
97  getClassFromList(name,i,*fi.get());
98 
99  // verify if the object already exists in the class factory
100  obj=dynamic_sp_cast<T>(factory->getClass(fi->getClassName()));
101  if (obj.get()==null) {
102  tString id=fi->getClassName();
103  // create the new object
104  obj=dynamic_sp_cast<T>(factory->NewInstance(fi->getClassName()));
105  // register the class
106  if (obj.get()!=null) factory->addClass(fi->getClassName(),obj);
107  // load the attributes if possible
108  UI_Object *uiObject=dynamic_cast<UI_Object *>(obj.get());
109  if (uiObject!=null) {
110  uiObject->setHasBeenLoaded(true);
111  // load the created class
112  uiObject->loadFromUIClass(*fi.get());
113  }
114  } else {
115  UI_Object *uiObject=dynamic_cast<UI_Object *>(obj.get());
116  if ((uiObject!=null) && (!uiObject->hasBeenLoaded())) {
117  // load the created class
118  uiObject->loadFromUIClass(*fi.get());
119  uiObject->setHasBeenLoaded(true);
120  }
121  }
122  // add the created object in the list
123  if (obj.get()!=null) objects.add(obj);
124 
125 
126  } // end loop on elements
127 
128 }
129 
130 
131 template<class T>
133  SP::CORE_ClassFactory factory=getFactory();
134 
135  // verify the factory is set
136  if (factory.get()==null) throw CORE_Exception("UI","UI_Class::saveAssociation","factory not set");
137 
138  // get the number of objects to store
139  int n=objs.getSize();
140 
141  if (n>0) {
142 
143  // create a classes list
144  tBoolean isComposite=false;
145  createClassesList(name,isComposite,n);
146 
147  // fill the field f
148  SP::UI_Class fi;
149  const CORE_Object *object;
150  const UI_Object *uiObject;
151 
152  for (int i=0;i<n;i++) { // loop on objects to store
153  object=objs.get(i);
154  uiObject=dynamic_cast<const UI_Object *>(object);
155 
156 
157  // test if the ui_class corresponding to obj has already been created
158  fi=dynamic_sp_cast<UI_Class>(factory->getClass(object->getIdentityString()));
159  if (fi.get()==null) {
160  // create the UI class to save the class uiObject
161  fi=NewInstance();
162  // set the factory
163  fi->setFactory(factory);
164  // set the interface type
165  fi->setInterfaceType(getInterfaceType());
166  // transfert the kind of copy for array
167  fi->setIsArrayCopied(isArrayCopied());
168  // create the UI structure
169  fi->createClass(object->getIdentityString());
170  // register the UI_Class
171  factory->addClass(object->getIdentityString(),fi);
172  // save the uiObject in the uiClass fi if possible
173  if (uiObject!=null) uiObject->saveToUIClass(*fi.get());
174  // finalize
175  fi->finalize();
176  }
177 
178  // store the fi object in f
179  setClassIntoList(name,i,*fi.get());
180  }
181  } //end loop on n
182 
183 }
184 
185 
186 
187 template<class T>
189  SP::CORE_ClassFactory factory=getFactory();
190  // verify the factory is set
191  if (factory.get()==null) throw CORE_Exception("UI","UI_Class::loadAssociation","factory not set");
192 
193  // return true if no field
194  if (!hasField(name)) return;
195 
196  // object created
197  boost::shared_ptr<T> obj;
198 
199 
200 
201  // clear the list
202  objects.clear();
203 
204 
205 
206 
207  // create a new ui class for each object to load
208  SP::UI_Class fi=NewInstance();
209 
210  // set the factory
211  fi->setFactory(factory);
212  // set the interface type
213  fi->setInterfaceType(getInterfaceType());
214  // transfert the kind of copy for array
215  fi->setIsArrayCopied(isArrayCopied());
216  // get the number of elements
217  int n=getClassesListSize(name);
218 
219  for (int i=0;i<n;i++) { // loop on elements
220 
221  getClassFromList(name,i,*fi.get());
222 
223  // verify if the object already exists in the class factory
224  obj=dynamic_sp_cast<T>(factory->getClass(fi->getClassName()));
225  if (obj.get()==null) {
226  // create the new object
227  obj=dynamic_sp_cast<T>(factory->NewInstance(fi->getClassName()));
228  // register the class
229  factory->addClass(fi->getClassName(),obj);
230  // load the attributes if possible
231  UI_Object *uiObject=dynamic_cast<UI_Object *>(obj.get());
232  if (uiObject!=null) {
233  uiObject->setHasBeenLoaded(false);
234  // load the created class
235  //uiObject->loadFromUIClass(*fi.get());
236  }
237  }
238 
239  // add the created object in the list
240  objects.add(obj);
241 
242 
243  } // end loop on elements
244 
245 
246 }
247 
248 
249 template<class T,class V>
251  SP::CORE_ClassFactory factory=getFactory();
252 
253  // verify the factory is set
254  if (factory.get()==null) throw CORE_Exception("UI","UI_Class::saveAssociation","factory not set");
255 
256  // get the number of objects to store
257  int n=objs.getSize();
258 
259  if (n>0) {
260 
261 
262 
263  // get the id of the association
264  tString id=objs.getIdentityString();
265 
266  // creaete the map
267  SP::UI_Class l=NewInstance();
268 
269  // create the class
270  l->createClass(id);
271 
272  // get the keys
273  vector<T> keys;
274  objs.getKeys(keys);
275 
276  // create the field & save key
277  l->saveField("keys",keys);
278 
279  // create the field value
280  tBoolean isComposite=true;
281  l->createClassesList("values",isComposite,n);
282 
283  // fill the field f
284  SP::UI_Class fi,kf;
285  const CORE_Object *object;
286  const UI_Object *uiObject;
287 
288 
289 
290  for (int i=0;i<n;i++) { // loop on objects to store
291  object=objs.get(keys[i]);
292  uiObject=dynamic_cast<const UI_Object *>(object);
293 
294  // test if the ui_class corresponding to obj has already been created
295  fi=dynamic_sp_cast<UI_Class>(factory->getClass(object->getIdentityString()));
296  if (fi.get()==null) {
297  // create the UI class to save the class uiObject
298  fi=NewInstance();
299  // set the factory
300  fi->setFactory(factory);
301  // set the interface type
302  fi->setInterfaceType(getInterfaceType());
303  // transfert the kind of copy for array
304  fi->setIsArrayCopied(isArrayCopied());
305  // create the UI structure
306  fi->createClass(object->getIdentityString());
307  // register the UI_Class corresponding to object class
308  factory->addClass(object->getIdentityString(),fi);
309  // save the uiObject in the uiClass fi
310  if (uiObject!=null) uiObject->saveToUIClass(*fi.get());
311  }
312  // store the fi object in f
313  l->setClassIntoList("values",i,*fi.get());
314 
315 
316  }
317 
318  // set the association field
319  setField(name,*l.get());
320  }
321 
322 
323 
324 
325 
326 }
327 
328 template<class T, class V>
330  SP::CORE_ClassFactory factory=getFactory();
331  // verify the factory is set
332  if (factory.get()==null) throw CORE_Exception("UI","UI_Class::loadAssociation","factory not set");
333 
334  // return true if no field
335  if (!hasField(name)) return;
336 
337  // object created
338  boost::shared_ptr<V> obj;
339 
340  // clear the list
341  objects.clear();
342 
343 
344 
345  T key;
346 
347  // get the association
348  SP::UI_Class l=NewInstance();
349  getField(name,*l.get());
350 
351  // get the number of elements
352  int n=l->getClassesListSize("values");
353 
354  // get the ui class corresponding to the multiple associations
355  if (n>0) {
356 
357  // create a new ui class for each key
358  SP::UI_Class fk=NewInstance();
359 
360  // transfert the kind of copy for array
361  fk->setIsArrayCopied(isArrayCopied());
362 
363  // set the interface type
364  fk->setInterfaceType(getInterfaceType());
365 
366  // set the factory
367  fk->setFactory(factory);
368 
369  // create a new ui class for each object value to load
370  SP::UI_Class fi=NewInstance();
371 
372  // set the interface type
373  fi->setInterfaceType(getInterfaceType());
374 
375  // transfert the kind of copy for array
376  fi->setIsArrayCopied(isArrayCopied());
377 
378  // set the factory
379  fi->setFactory(factory);
380 
381  // load the keys
382  vector<T> keys;
383  l->loadField("keys",keys);
384 
385  // load the values
386  for (int i=0;i<n;i++) { // loop on objects to load
387 
388  // get the object
389  l->getClassFromList("values",i,*fi.get());
390 
391  // verify if the object already exists in the class factory
392  obj=dynamic_sp_cast<V>(factory->getClass(fi->getClassName()));
393  if (obj.get()==null) {
394  // create the new object
395  obj=dynamic_sp_cast<V>(factory->NewInstance(fi->getClassName()));
396  // register the class
397  factory->addClass(fi->getClassName(),obj);
398  // load the attributes if possible
399  UI_Object *uiObject=dynamic_cast<UI_Object *>(obj.get());
400  if (uiObject!=null) {
401  uiObject->setHasBeenLoaded(true);
402  // load the created class
403  uiObject->loadFromUIClass(*fi.get());
404  }
405  } else {
406  UI_Object *uiObject=dynamic_cast<UI_Object *>(obj.get());
407  if ((uiObject!=null) && (!uiObject->hasBeenLoaded())) {
408  // load the created class
409  uiObject->loadFromUIClass(*fi.get());
410  uiObject->setHasBeenLoaded(true);
411  }
412  }
413 
414  // add the created object in the list
415  objects.put(keys[i],obj);
416 
417 
418 
419  }
420  }
421 }
422 
423 
424 #endif
virtual tBoolean setClassIntoList(const tString &fieldName, const int &index, UI_Class &fieldValue)=0
set the index-th element of the classes list supposed to be composite or not depending on isComposite...
int getSize() const
return the size of the array
Definition: CORE_WeakPointersList.h:215
int getSize() const
return the size of the array
Definition: CORE_SharedPointersVMap.h:94
int getInterfaceType() const
set the interface type
Definition: UI_Class.h:116
class CORE_SharedPointersList is a list of shared pointers
Definition: CORE_SharedPointersList.h:11
void clear()
clear the array
Definition: CORE_SharedPointersList.h:206
This class is the base class of User Interface package.
Definition: UI_Object.h:23
This class describes the main interface class for a soft user interface (R,matlab,python etc...) class.
Definition: UI_Class.h:38
void add(boost::shared_ptr< T > obj)
add an element at the end
Definition: CORE_SharedPointersList.h:134
void setHasBeenLoaded(const tBoolean &v)
set the if the object has completely been loaded
Definition: UI_Object.h:55
virtual tBoolean hasField(const tString &field) const =0
verify if the data of the class is a struct with fields names
virtual void loadFromUIClass(const UI_Class &mclass)
how to load the object from a Meta Model class
Definition: UI_Object.cpp:15
#define tBoolean
Definition: types.h:48
void getKeys(vector< Key > &ks) const
return a vector of keys
Definition: CORE_SharedPointersVMap.hpp:129
void saveAssociation(const tString &name, const tBoolean &isComposite, const CORE_Object *obj)
save the association with single cardinality
Definition: UI_Class.cpp:40
#define null
Definition: types.h:13
tBoolean isArrayCopied() const
return true if the array must be copied
Definition: UI_Class.h:127
void add(const boost::shared_ptr< T > &obj)
add an element at the end
Definition: CORE_WeakPointersList.h:107
tBoolean hasBeenLoaded() const
return true if the object has completely been loaded
Definition: UI_Object.h:60
tString getIdentityString() const
return the identity string of the object of the form className_at_address
Definition: CORE_Object.h:136
This class describes a map: primitive type of Key -> shared pointer of Value.
Definition: CORE_SharedPointersVMap.h:15
this class describes the exceptions raised for CORE package
Definition: CORE_Exception.h:15
virtual tBoolean getField(const tString &field, UI_Class &uiClass) const =0
get the field name of the class
SP::CORE_Object loadAssociation(const tString &name, const tBoolean &isComposite) const
load the association Note that the factory class must be set to create the class If nit the return ob...
Definition: UI_Class.cpp:86
virtual SP::UI_Class NewInstance() const =0
create a new instance of class
virtual int getClassesListSize(const tString &fieldName) const =0
get the number of classes of the list
const Value * get(const Key &k) const
get the value at key k
Definition: CORE_SharedPointersVMap.hpp:59
void clear()
clear the map
Definition: CORE_SharedPointersVMap.h:253
class CORE_WeakPointersList is a list of weak shared pointers
Definition: CORE_WeakPointersList.h:11
abstract base class for most classes.
Definition: CORE_Object.h:30
#define tString
Definition: types.h:49
virtual tBoolean setField(const tString &fieldName, const tBoolean &isComposite, UI_Class &fieldValue)=0
set the field fieldName of the class
const T * get(int i) const
get the pointer at index i ASSERT_IN(i>-1); ASSERT_IN(i<((int)mVector.size()));
Definition: CORE_WeakPointersList.h:187
void clear()
clear the array
Definition: CORE_WeakPointersList.h:164
virtual void saveToUIClass(UI_Class &mclass) const
how to save the object from a mate model class
Definition: UI_Object.cpp:18
tBoolean put(const Key &k, const boost::shared_ptr< Value > &v)
set the value at the index k
Definition: CORE_SharedPointersVMap.h:192
virtual tBoolean getClassFromList(const tString &fieldName, const int &index, UI_Class &uiClass) const =0
get the field of the index-th class in the list
const T * get(const tVectorIndex &i) const
get the pointer at index i
Definition: CORE_SharedPointersList.h:227
virtual void createClassesList(const tString &fieldName, const tBoolean &isComposite, const int &n)=0
create a multiple association of size n with name fieldname of type isComoposite
tVectorIndex getSize() const
return the size of the array
Definition: CORE_SharedPointersList.h:245