]> SALOME platform Git repositories - modules/yacs.git/blob - src/runtime/TypeConversions.cxx
Salome HOME
merge from branch DEV tag mergeto_trunk_04apr08
[modules/yacs.git] / src / runtime / TypeConversions.cxx
1
2 //#define REFCNT
3 #ifdef REFCNT
4 #define private public
5 #define protected public
6 #include <omniORB4/CORBA.h>
7 #include <omniORB4/internal/typecode.h>
8 #endif
9
10 #include "TypeConversions.hxx"
11 #include "ConversionException.hxx"
12 #include "RuntimeSALOME.hxx"
13 #include "Salome_file_i.hxx"
14 #include "TypeCode.hxx"
15 #include "Cstr2d.hxx"
16 #include "SALOME_GenericObj.hh"
17
18 #include <iostream>
19 #include <sstream>
20
21 //#define _DEVDEBUG_
22 #include "YacsTrace.hxx"
23
24 using namespace std;
25
26 namespace YACS
27 {
28   namespace ENGINE
29   {
30     std::string getImplName(ImplType impl)
31       {
32          switch(impl)
33            {
34            case CORBAImpl:
35              return "CORBA";
36            case PYTHONImpl:
37              return "PYTHON";
38            case NEUTRALImpl:
39              return "NEUTRAL";
40            case XMLImpl:
41              return "XML";
42            case CPPImpl:
43              return "CPP";
44            default:
45              return "UNKNOWN";
46            }
47       }
48     /*
49      * Functions to return a CORBA TypeCode equivalent to a YACS TypeCode
50      */
51
52     typedef CORBA::TypeCode_ptr (*getCorbaTCFn)(const TypeCode *);
53
54     CORBA::TypeCode_ptr getCorbaTCNull(const TypeCode *t)
55       {
56         stringstream msg;
57         msg << "Conversion not implemented: kind= " << t->kind();
58         msg << " : " << __FILE__ << ":" << __LINE__;
59         throw YACS::ENGINE::ConversionException(msg.str());
60       }
61
62     CORBA::TypeCode_ptr getCorbaTCDouble(const TypeCode *t)
63     {
64       return CORBA::TypeCode::_duplicate(CORBA::_tc_double);
65     }
66
67     CORBA::TypeCode_ptr getCorbaTCInt(const TypeCode *t)
68     {
69       return CORBA::TypeCode::_duplicate(CORBA::_tc_long);
70     }
71
72     CORBA::TypeCode_ptr getCorbaTCString(const TypeCode *t)
73     {
74       return CORBA::TypeCode::_duplicate(CORBA::_tc_string);
75     }
76
77     CORBA::TypeCode_ptr getCorbaTCBool(const TypeCode *t)
78     {
79       return CORBA::TypeCode::_duplicate(CORBA::_tc_boolean);
80     }
81
82     CORBA::TypeCode_ptr getCorbaTCObjref(const TypeCode *t)
83     {
84       DEBTRACE( t->name() << " " << t->shortName());
85       CORBA::TypeCode_ptr tc= getSALOMERuntime()->getOrb()->create_interface_tc(t->id(),t->shortName());
86 #ifdef REFCNT
87       DEBTRACE("refcount CORBA tc Objref: " << ((omni::TypeCode_base*)tc)->pd_ref_count);
88 #endif
89       return tc;
90     }
91
92     CORBA::TypeCode_ptr getCorbaTCSequence(const TypeCode *t)
93     {
94       CORBA::TypeCode_var content_type=getCorbaTC(t->contentType());
95       CORBA::TypeCode_ptr tc= getSALOMERuntime()->getOrb()->create_sequence_tc(0,content_type);
96 #ifdef REFCNT
97       DEBTRACE("refcount CORBA content_type: " << ((omni::TypeCode_base*)content_type.in())->pd_ref_count);
98       DEBTRACE("refcount CORBA tc: " << ((omni::TypeCode_base*)tc)->pd_ref_count);
99 #endif
100       return tc;
101     }
102
103     CORBA::TypeCode_ptr getCorbaTCStruct(const TypeCode *t)
104     {
105       CORBA::StructMemberSeq mseq;
106       YACS::ENGINE::TypeCodeStruct* tst=(YACS::ENGINE::TypeCodeStruct*)t;
107       int nMember=tst->memberCount();
108       mseq.length(nMember);
109       for(int i=0;i<nMember;i++)
110         {
111           const char * name=tst->memberName(i);
112           TypeCode* tm=tst->memberType(i);
113           mseq[i].name=CORBA::string_dup(name);
114           mseq[i].type=getCorbaTC(tm);
115         }
116       CORBA::TypeCode_ptr tc= getSALOMERuntime()->getOrb()->create_struct_tc(t->id(),t->shortName(),mseq);
117 #ifdef REFCNT
118       DEBTRACE("refcount CORBA tc: " << ((omni::TypeCode_base*)tc)->pd_ref_count);
119 #endif
120       return tc;
121     }
122
123     getCorbaTCFn getCorbaTCFns[]=
124       {
125         getCorbaTCNull,
126         getCorbaTCDouble,
127         getCorbaTCInt,
128         getCorbaTCString,
129         getCorbaTCBool,
130         getCorbaTCObjref,
131         getCorbaTCSequence,
132         getCorbaTCNull,
133         getCorbaTCStruct,
134       };
135
136     CORBA::TypeCode_ptr getCorbaTC(const TypeCode *t)
137     {
138       int tk=t->kind();
139       return getCorbaTCFns[tk](t);
140     }
141
142     /*
143      * End of Functions to return a CORBA TypeCode equivalent to a YACS TypeCode
144      */
145
146     /*
147      * Section that defines functions to check adaptation from one implementation to another
148      * isAdaptable is template function that checks if TypeCode t1 from implementation IMPLIN
149      * can be converted to TypeCode t2 from implementation IMPLOUT
150      * IMPLIN is the implementation of an output port
151      * IMPLOUT is the implementation of an input port
152      * If the check is True, the input port can be adapted to the output port
153      */
154
155     template <ImplType IMPLIN,ImplType IMPLOUT> inline int isAdaptable(const TypeCode *t1,const TypeCode* t2);
156
157     template <ImplType IMPLIN,ImplType IMPLOUT>
158     struct isAdaptableDouble
159       {
160         static inline int apply(const TypeCode *t1,const TypeCode* t2)
161           {
162             if(t1->kind() == Double)return 1;
163             if(t1->kind() == Int)return 1;
164             return 0;
165           }
166       };
167     template <ImplType IMPLIN,ImplType IMPLOUT>
168     struct isAdaptableInt
169       {
170         static inline int apply(const TypeCode *t1,const TypeCode* t2)
171           {
172             if(t1->kind() == Int)return 1;
173             return 0;
174           }
175       };
176     template <ImplType IMPLIN,ImplType IMPLOUT>
177     struct isAdaptableString
178       {
179         static inline int apply(const TypeCode *t1,const TypeCode* t2)
180           {
181             if(t1->kind() == String)return 1;
182             return 0;
183           }
184       };
185     template <ImplType IMPLIN,ImplType IMPLOUT>
186     struct isAdaptableBool
187       {
188         static inline int apply(const TypeCode *t1,const TypeCode* t2)
189           {
190             if(t1->kind() == Bool)return 1;
191             if(t1->kind() == Int)return 1;
192             return 0;
193           }
194       };
195     template <ImplType IMPLIN,ImplType IMPLOUT>
196     struct isAdaptableObjref
197       {
198         static inline int apply(const TypeCode *t1,const TypeCode* t2)
199           {
200             if(t1->kind() == Objref)
201               {
202                 //The inport type must be more general than outport type
203                 if( t1->isA(t2->id()) )
204                   return 1;
205               }
206             return 0;
207           }
208       };
209     template <ImplType IMPLIN,ImplType IMPLOUT>
210     struct isAdaptableSequence
211       {
212         static inline int apply(const TypeCode *t1,const TypeCode* t2)
213           {
214             if(t1->kind() == Sequence)
215               {
216                 if(isAdaptable<IMPLIN,IMPLOUT>(t1->contentType(),t2->contentType()))
217                   {
218                     return 1;
219                   }
220               }
221             return 0;
222           }
223       };
224     template <ImplType IMPLIN,ImplType IMPLOUT>
225     struct isAdaptableArray
226       {
227         static inline int apply(const TypeCode *t1,const TypeCode* t2)
228           {
229             return 0;
230           }
231       };
232     template <ImplType IMPLIN,ImplType IMPLOUT>
233     struct isAdaptableStruct
234       {
235         static inline int apply(const TypeCode *t1,const TypeCode* t2)
236           {
237             if(t1->kind() == Struct)
238               {
239                 if( t1->isA(t2) )
240                   return 1;
241               }
242             return 0;
243           }
244       };
245
246     /*
247      * Function to check adaptation from implementation 1 (IMPLIN,t1) to implementation 2 (IMPLOUT,t2)
248      * t1 is the IMPLIN output port type
249      * t2 is the IMPLOUT input port type
250      */
251     template <ImplType IMPLIN,ImplType IMPLOUT>
252     inline int isAdaptable(const TypeCode *t1,const TypeCode* t2)
253       {
254          switch(t2->kind())
255            {
256            case Double:
257              return isAdaptableDouble<IMPLIN,IMPLOUT>::apply(t1,t2);
258            case Int:
259              return isAdaptableInt<IMPLIN,IMPLOUT>::apply(t1,t2);
260            case String:
261              return isAdaptableString<IMPLIN,IMPLOUT>::apply(t1,t2);
262            case Bool:
263              return isAdaptableBool<IMPLIN,IMPLOUT>::apply(t1,t2);
264            case Objref:
265              return isAdaptableObjref<IMPLIN,IMPLOUT>::apply(t1,t2);
266            case Sequence:
267              return isAdaptableSequence<IMPLIN,IMPLOUT>::apply(t1,t2);
268            case Array:
269              return isAdaptableArray<IMPLIN,IMPLOUT>::apply(t1,t2);
270            case Struct:
271              return isAdaptableStruct<IMPLIN,IMPLOUT>::apply(t1,t2);
272            default:
273              break;
274            }
275          return 0;
276       }
277
278     //xxx to Python adaptations
279     int isAdaptableCorbaPyObject(const TypeCode *t1,const TypeCode *t2)
280     {
281       return isAdaptable<PYTHONImpl,CORBAImpl>(t1,t2);
282     }
283     int isAdaptableNeutralPyObject(const TypeCode * t1, const TypeCode * t2)
284     {
285       return isAdaptable<PYTHONImpl,NEUTRALImpl>(t1,t2);
286     }
287     int isAdaptablePyObjectPyObject(const TypeCode *t1,const TypeCode *t2)
288     {
289       return isAdaptable<PYTHONImpl,PYTHONImpl>(t1,t2);
290     }
291
292     //xxx to Neutral adaptations
293     int isAdaptableCorbaNeutral(const TypeCode *t1,const TypeCode *t2)
294     {
295       return isAdaptable<NEUTRALImpl,CORBAImpl>(t1,t2);
296     }
297     int isAdaptablePyObjectNeutral(const TypeCode *t1,const TypeCode *t2)
298     {
299       return isAdaptable<NEUTRALImpl,PYTHONImpl>(t1,t2);
300     }
301     int isAdaptableXmlNeutral(const TypeCode *t1,const TypeCode *t2)
302     {
303       return isAdaptable<NEUTRALImpl,XMLImpl>(t1,t2);
304     }
305     int isAdaptableNeutralNeutral(const TypeCode *t1, const TypeCode *t2)
306     {
307       return isAdaptableNeutralCorba(t1, t2);
308     }
309
310     //xxx to XML adaptations
311     int isAdaptableNeutralXml(const TypeCode * t1, const TypeCode * t2)
312     {
313       return isAdaptable<XMLImpl,NEUTRALImpl>(t1,t2);
314     }
315
316     //xxx to Corba adaptations
317     int isAdaptableNeutralCorba(const TypeCode *t1,const TypeCode *t2)
318     {
319       return isAdaptable<CORBAImpl,NEUTRALImpl>(t1,t2);
320     }
321     int isAdaptableXmlCorba(const TypeCode *t1,const TypeCode *t2)
322     {
323       return isAdaptable<CORBAImpl,XMLImpl>(t1,t2);
324     }
325     int isAdaptableCorbaCorba(const TypeCode *t1,const TypeCode *t2)
326     {
327       return isAdaptable<CORBAImpl,CORBAImpl>(t1,t2);
328     }
329     int isAdaptablePyObjectCorba(const TypeCode *t1,const TypeCode *t2)
330     {
331       return isAdaptable<CORBAImpl,PYTHONImpl>(t1,t2);
332     }
333
334     //! Basic template convertor from type TIN to Yacs<TOUT> type
335     /*!
336      * This convertor does nothing : throws exception
337      * It must be partially specialize for a specific type (TIN)
338      */
339     template <ImplType IMPLIN,class TIN,class TIN2,ImplType IMPLOUT, class TOUT>
340     struct convertToYacsDouble
341     {
342       static inline double convert(const TypeCode *t,TIN o,TIN2 aux)
343         {
344           stringstream msg;
345           msg << "Conversion not implemented: kind= " << t->kind() << " Implementation: " << IMPLIN << " to: " << IMPLOUT;
346           msg << " : " << __FILE__ << ":" << __LINE__;
347           throw YACS::ENGINE::ConversionException(msg.str());
348         }
349     };
350     template <ImplType IMPLIN,class TIN,class TIN2,ImplType IMPLOUT, class TOUT>
351     struct convertToYacsInt
352     {
353       static inline long convert(const TypeCode *t,TIN o,TIN2 aux)
354         {
355           stringstream msg;
356           msg << "Conversion not implemented: kind= " << t->kind() << " Implementation: " << IMPLIN << " to: " << IMPLOUT;
357           msg << " : " << __FILE__ << ":" << __LINE__;
358           throw YACS::ENGINE::ConversionException(msg.str());
359         }
360     };
361     template <ImplType IMPLIN,class TIN,class TIN2,ImplType IMPLOUT, class TOUT>
362     struct convertToYacsString
363     {
364       static inline std::string convert(const TypeCode *t,TIN o,TIN2 aux)
365         {
366           stringstream msg;
367           msg << "Conversion not implemented: kind= " << t->kind() << " Implementation: " << IMPLIN << " to: " << IMPLOUT;
368           msg << " : " << __FILE__ << ":" << __LINE__;
369           throw YACS::ENGINE::ConversionException(msg.str());
370         }
371     };
372     template <ImplType IMPLIN,class TIN,class TIN2,ImplType IMPLOUT, class TOUT>
373     struct convertToYacsBool
374     {
375       static inline bool convert(const TypeCode *t,TIN o,TIN2 aux)
376         {
377           stringstream msg;
378           msg << "Conversion not implemented: kind= " << t->kind() << " Implementation: " << IMPLIN << " to: " << IMPLOUT;
379           msg << " : " << __FILE__ << ":" << __LINE__;
380           throw YACS::ENGINE::ConversionException(msg.str());
381         }
382     };
383     template <ImplType IMPLIN,class TIN,class TIN2,ImplType IMPLOUT, class TOUT>
384     struct convertToYacsObjref
385     {
386       static inline std::string convert(const TypeCode *t,TIN o,TIN2 aux)
387         {
388           stringstream msg;
389           msg << "Conversion not implemented: kind= " << t->kind() << " Implementation: " << IMPLIN << " to: " << IMPLOUT;
390           msg << " : " << __FILE__ << ":" << __LINE__;
391           throw YACS::ENGINE::ConversionException(msg.str());
392         }
393     };
394     template <ImplType IMPLIN,class TIN,class TIN2,ImplType IMPLOUT, class TOUT>
395     struct convertToYacsSequence
396     {
397       static inline void convert(const TypeCode *t,TIN o,TIN2 aux,std::vector<TOUT>& v)
398         {
399           stringstream msg;
400           msg << "Conversion not implemented: kind= " << t->kind() << " Implementation: " << IMPLIN << " to: " << IMPLOUT;
401           msg << " : " << __FILE__ << ":" << __LINE__;
402           throw YACS::ENGINE::ConversionException(msg.str());
403         }
404     };
405     template <ImplType IMPLIN,class TIN,class TIN2,ImplType IMPLOUT, class TOUT>
406     struct convertToYacsArray
407     {
408       static inline void convert(const TypeCode *t,TIN o,TIN2 aux,std::vector<TOUT>& v)
409         {
410           stringstream msg;
411           msg << "Conversion not implemented: kind= " << t->kind() << " Implementation: " << IMPLIN << " to: " << IMPLOUT;
412           msg << " : " << __FILE__ << ":" << __LINE__;
413           throw YACS::ENGINE::ConversionException(msg.str());
414         }
415     };
416     template <ImplType IMPLIN,class TIN,class TIN2,ImplType IMPLOUT, class TOUT>
417     struct convertToYacsStruct
418     {
419       static inline void convert(const TypeCode *t,TIN o,TIN2 aux,std::map<std::string,TOUT>& v)
420         {
421           stringstream msg;
422           msg << "Conversion not implemented: kind= " << t->kind() << " Implementation: " << IMPLIN << " to: " << IMPLOUT;
423           msg << " : " << __FILE__ << ":" << __LINE__;
424           throw YACS::ENGINE::ConversionException(msg.str());
425         }
426     };
427
428     //! Basic convertor from Yacs<TOUT> type to full TOUT type
429     /*!
430      *
431      */
432     template <ImplType IMPLOUT, class TOUT>
433     struct convertFromYacsDouble
434     {
435       static inline TOUT convert(const TypeCode *t,double o)
436         {
437           stringstream msg;
438           msg << "Conversion not implemented: kind= " << t->kind() << " Implementation: " << IMPLOUT;
439           msg << " : " << __FILE__ << ":" << __LINE__;
440           throw YACS::ENGINE::ConversionException(msg.str());
441         }
442     };
443     template <ImplType IMPLOUT, class TOUT>
444     struct convertFromYacsInt
445     {
446       static inline TOUT convert(const TypeCode *t,long o)
447         {
448           stringstream msg;
449           msg << "Conversion not implemented: kind= " << t->kind() << " Implementation: " << IMPLOUT;
450           msg << " : " << __FILE__ << ":" << __LINE__;
451           throw YACS::ENGINE::ConversionException(msg.str());
452         }
453     };
454     template <ImplType IMPLOUT, class TOUT>
455     struct convertFromYacsString
456     {
457       static inline TOUT convert(const TypeCode *t,std::string o)
458         {
459           stringstream msg;
460           msg << "Conversion not implemented: kind= " << t->kind() << " Implementation: " << IMPLOUT;
461           msg << " : " << __FILE__ << ":" << __LINE__;
462           throw YACS::ENGINE::ConversionException(msg.str());
463         }
464     };
465     template <ImplType IMPLOUT, class TOUT>
466     struct convertFromYacsBool
467     {
468       static inline TOUT convert(const TypeCode *t,bool o)
469         {
470           stringstream msg;
471           msg << "Conversion not implemented: kind= " << t->kind() << " Implementation: " << IMPLOUT;
472           msg << " : " << __FILE__ << ":" << __LINE__;
473           throw YACS::ENGINE::ConversionException(msg.str());
474         }
475     };
476     template <ImplType IMPLOUT, class TOUT>
477     struct convertFromYacsObjref
478     {
479       static inline TOUT convert(const TypeCode *t,std::string o)
480         {
481           stringstream msg;
482           msg << "Conversion not implemented: kind= " << t->kind() << " Implementation: " << IMPLOUT;
483           msg << " : " << __FILE__ << ":" << __LINE__;
484           throw YACS::ENGINE::ConversionException(msg.str());
485         }
486     };
487     template <ImplType IMPLOUT, class TOUT>
488     struct convertFromYacsSequence
489     {
490       static inline TOUT convert(const TypeCode *t,std::vector<TOUT>& v)
491         {
492           stringstream msg;
493           msg << "Conversion not implemented: kind= " << t->kind() << " Implementation: " << IMPLOUT;
494           msg << " : " << __FILE__ << ":" << __LINE__;
495           throw YACS::ENGINE::ConversionException(msg.str());
496         }
497     };
498     template <ImplType IMPLOUT, class TOUT>
499     struct convertFromYacsArray
500     {
501       static inline TOUT convert(const TypeCode *t,std::vector<TOUT>& v)
502         {
503           stringstream msg;
504           msg << "Conversion not implemented: kind= " << t->kind() << " Implementation: " << IMPLOUT;
505           msg << " : " << __FILE__ << ":" << __LINE__;
506           throw YACS::ENGINE::ConversionException(msg.str());
507         }
508     };
509     template <ImplType IMPLOUT, class TOUT>
510     struct convertFromYacsStruct
511     {
512       static inline TOUT convert(const TypeCode *t,std::map<std::string,TOUT>& v)
513         {
514           stringstream msg;
515           msg << "Conversion not implemented: kind= " << t->kind() << " Implementation: " << IMPLOUT;
516           msg << " : " << __FILE__ << ":" << __LINE__;
517           throw YACS::ENGINE::ConversionException(msg.str());
518         }
519     };
520     template <ImplType IMPLIN,class TIN,class TIN2,ImplType IMPLOUT, class TOUT>
521     inline TOUT convertDouble(const TypeCode *t,TIN o,TIN2 aux)
522     {
523       double d=convertToYacsDouble<IMPLIN,TIN,TIN2,IMPLOUT,TOUT>::convert(t,o,aux);
524       DEBTRACE( d );
525       TOUT r=convertFromYacsDouble<IMPLOUT,TOUT>::convert(t,d);
526       return r;
527     }
528     template <ImplType IMPLIN,class TIN,class TIN2,ImplType IMPLOUT, class TOUT>
529     inline TOUT convertInt(const TypeCode *t,TIN o,TIN2 aux)
530     {
531       long d=convertToYacsInt<IMPLIN,TIN,TIN2,IMPLOUT,TOUT>::convert(t,o,aux);
532       DEBTRACE( d );
533       TOUT r=convertFromYacsInt<IMPLOUT,TOUT>::convert(t,d);
534       return r;
535     }
536     template <ImplType IMPLIN,class TIN,class TIN2,ImplType IMPLOUT, class TOUT>
537     inline TOUT convertString(const TypeCode *t,TIN o,TIN2 aux)
538     {
539       std::string d=convertToYacsString<IMPLIN,TIN,TIN2,IMPLOUT,TOUT>::convert(t,o,aux);
540       DEBTRACE( d );
541       TOUT r=convertFromYacsString<IMPLOUT,TOUT>::convert(t,d);
542       return r;
543     }
544     template <ImplType IMPLIN,class TIN,class TIN2,ImplType IMPLOUT, class TOUT>
545     inline TOUT convertBool(const TypeCode *t,TIN o,TIN2 aux)
546     {
547       double d=convertToYacsBool<IMPLIN,TIN,TIN2,IMPLOUT,TOUT>::convert(t,o,aux);
548       DEBTRACE( d );
549       TOUT r=convertFromYacsBool<IMPLOUT,TOUT>::convert(t,d);
550       return r;
551     }
552     template <ImplType IMPLIN,class TIN,class TIN2,ImplType IMPLOUT, class TOUT>
553     inline TOUT convertObjref(const TypeCode *t,TIN o,TIN2 aux)
554     {
555       std::string d=convertToYacsObjref<IMPLIN,TIN,TIN2,IMPLOUT,TOUT>::convert(t,o,aux);
556       DEBTRACE( d );
557       TOUT r=convertFromYacsObjref<IMPLOUT,TOUT>::convert(t,d);
558       return r;
559     }
560
561     template <ImplType IMPLIN,class TIN,class TIN2,ImplType IMPLOUT, class TOUT>
562     inline TOUT convertSequence(const TypeCode *t,TIN o,TIN2 aux)
563     {
564       std::vector<TOUT> v;
565       convertToYacsSequence<IMPLIN,TIN,TIN2,IMPLOUT,TOUT>::convert(t,o,aux,v);
566       TOUT r=convertFromYacsSequence<IMPLOUT,TOUT>::convert(t,v);
567       return r;
568     }
569     template <ImplType IMPLIN,class TIN,class TIN2,ImplType IMPLOUT, class TOUT>
570     inline TOUT convertArray(const TypeCode *t,TIN o,TIN2 aux)
571     {
572       std::vector<TOUT> v;
573       convertToYacsArray<IMPLIN,TIN,TIN2,IMPLOUT,TOUT>::convert(t,o,aux,v);
574       TOUT r=convertFromYacsArray<IMPLOUT,TOUT>::convert(t,v);
575       return r;
576     }
577     template <ImplType IMPLIN,class TIN,class TIN2,ImplType IMPLOUT, class TOUT>
578     inline TOUT convertStruct(const TypeCode *t,TIN o,TIN2 aux)
579     {
580       std::map<std::string,TOUT> v;
581       convertToYacsStruct<IMPLIN,TIN,TIN2,IMPLOUT,TOUT>::convert(t,o,aux,v);
582       TOUT r=convertFromYacsStruct<IMPLOUT,TOUT>::convert(t,v);
583       return r;
584     }
585
586     template <ImplType IMPLIN,class TIN,class TIN2,ImplType IMPLOUT, class TOUT>
587     inline TOUT YacsConvertor(const TypeCode *t,TIN o,TIN2 aux)
588       {
589          int tk=t->kind();
590          switch(t->kind())
591            {
592            case Double:
593              return convertDouble<IMPLIN,TIN,TIN2,IMPLOUT,TOUT>(t,o,aux);
594            case Int:
595              return convertInt<IMPLIN,TIN,TIN2,IMPLOUT,TOUT>(t,o,aux);
596            case String:
597              return convertString<IMPLIN,TIN,TIN2,IMPLOUT,TOUT>(t,o,aux);
598            case Bool:
599              return convertBool<IMPLIN,TIN,TIN2,IMPLOUT,TOUT>(t,o,aux);
600            case Objref:
601              return convertObjref<IMPLIN,TIN,TIN2,IMPLOUT,TOUT>(t,o,aux);
602            case Sequence:
603              return convertSequence<IMPLIN,TIN,TIN2,IMPLOUT,TOUT>(t,o,aux);
604            case Array:
605              return convertArray<IMPLIN,TIN,TIN2,IMPLOUT,TOUT>(t,o,aux);
606            case Struct:
607              return convertStruct<IMPLIN,TIN,TIN2,IMPLOUT,TOUT>(t,o,aux);
608            default:
609              break;
610            }
611          stringstream msg;
612          msg << "Conversion not implemented: kind= " << tk << " Implementation: " << IMPLOUT;
613          msg << " : " << __FILE__ << ":" << __LINE__;
614          throw YACS::ENGINE::ConversionException(msg.str());
615       }
616
617     //! ToYacs Convertor for PYTHONImpl
618     /*!
619      * This convertor converts Python object to YACS<TOUT> types
620      * Partial specialization for Python implementation with type PyObject* (PYTHONImpl)
621      */
622     template <ImplType IMPLOUT, class TOUT>
623     struct convertToYacsDouble<PYTHONImpl,PyObject*,void*,IMPLOUT,TOUT>
624     {
625       static inline double convert(const TypeCode *t,PyObject* o,void*)
626         {
627           double x;
628           if (PyFloat_Check(o))
629             x=PyFloat_AS_DOUBLE(o);
630           else if (PyInt_Check(o))
631             x=PyInt_AS_LONG(o);
632           else if(PyLong_Check(o))
633             x=PyLong_AsLong(o);
634           else
635             {
636               stringstream msg;
637               msg << "Not a python double. kind=" << t->kind() ;
638               msg << " ( " << __FILE__ << ":" << __LINE__ << ")";
639               throw YACS::ENGINE::ConversionException(msg.str());
640             }
641           return x;
642         }
643     };
644     template <ImplType IMPLOUT, class TOUT>
645     struct convertToYacsInt<PYTHONImpl,PyObject*,void*,IMPLOUT,TOUT>
646     {
647       static inline long convert(const TypeCode *t,PyObject* o,void*)
648         {
649           long l;
650           if (PyInt_Check(o))
651             l=PyInt_AS_LONG(o);
652           else if(PyLong_Check(o))
653             l=PyLong_AsLong(o);
654           else
655             {
656               stringstream msg;
657               msg << "Not a python integer. kind=" << t->kind() ;
658               msg << " ( " << __FILE__ << ":" << __LINE__ << ")";
659               throw YACS::ENGINE::ConversionException(msg.str());
660             }
661           return l;
662         }
663     };
664     template <ImplType IMPLOUT, class TOUT>
665     struct convertToYacsString<PYTHONImpl,PyObject*,void*,IMPLOUT,TOUT>
666     {
667       static inline std::string convert(const TypeCode *t,PyObject* o,void*)
668         {
669           if (PyString_Check(o))
670             return PyString_AS_STRING(o);
671           else
672             {
673               stringstream msg;
674               msg << "Not a python string. kind=" << t->kind() ;
675               msg << " ( " << __FILE__ << ":" << __LINE__ << ")";
676               throw YACS::ENGINE::ConversionException(msg.str());
677             }
678         }
679     };
680     template <ImplType IMPLOUT, class TOUT>
681     struct convertToYacsBool<PYTHONImpl,PyObject*,void*,IMPLOUT,TOUT>
682     {
683       static inline bool convert(const TypeCode *t,PyObject* o,void*)
684         {
685           bool l;
686           if (PyBool_Check(o))
687               l=(o==Py_True);
688           else if (PyInt_Check(o))
689               l=(PyInt_AS_LONG(o)!=0);
690           else if(PyLong_Check(o))
691               l=(PyLong_AsLong(o)!=0);
692           else
693             {
694               stringstream msg;
695               msg << "Not a python boolean. kind=" << t->kind() ;
696               msg << " ( " << __FILE__ << ":" << __LINE__ << ")";
697               throw YACS::ENGINE::ConversionException(msg.str());
698             }
699           return l;
700         }
701     };
702     template <ImplType IMPLOUT, class TOUT>
703     struct convertToYacsObjref<PYTHONImpl,PyObject*,void*,IMPLOUT,TOUT>
704     {
705       static inline std::string convert(const TypeCode *t,PyObject* o,void*)
706         {
707           if (PyString_Check(o))
708             {
709               // the objref is used by Python as a string (prefix:value) keep it as a string
710               return PyString_AS_STRING(o);
711             }
712           PyObject *pystring=PyObject_CallMethod(getSALOMERuntime()->getPyOrb(),"object_to_string","O",o);
713           if(pystring==NULL)
714             {
715               PyErr_Print();
716               throw YACS::ENGINE::ConversionException("Problem in convertToYacsObjref<PYTHONImpl");
717             }
718           std::string mystr=PyString_AsString(pystring);
719           Py_DECREF(pystring);
720           return mystr;
721         }
722     };
723     template <ImplType IMPLOUT, class TOUT>
724     struct convertToYacsSequence<PYTHONImpl,PyObject*,void*,IMPLOUT,TOUT>
725     {
726       static inline void convert(const TypeCode *t,PyObject* o,void*,std::vector<TOUT>& v)
727         {
728           if(!PySequence_Check(o))
729             {
730               stringstream msg;
731               msg << "Problem in conversion: the python object is not a sequence " << std::endl;
732               msg << " (" << __FILE__ << ":" << __LINE__ << ")";
733               throw YACS::ENGINE::ConversionException(msg.str());
734             }
735           int length=PySequence_Size(o);
736           DEBTRACE("length: " << length );
737           v.resize(length);
738           for(int i=0;i<length;i++)
739             {
740               PyObject *item=PySequence_ITEM(o,i);
741 #ifdef _DEVDEBUG_
742               std::cerr <<"item[" << i << "]=";
743               PyObject_Print(item,stderr,Py_PRINT_RAW);
744               std::cerr << std::endl;
745 #endif
746               DEBTRACE( "item refcnt: " << item->ob_refcnt );
747               TOUT ro=YacsConvertor<PYTHONImpl,PyObject*,void*,IMPLOUT,TOUT>(t->contentType(),item,0);
748               v[i]=ro;
749               Py_DECREF(item);
750             }
751         }
752     };
753     template <ImplType IMPLOUT, class TOUT>
754     struct convertToYacsStruct<PYTHONImpl,PyObject*,void*,IMPLOUT,TOUT>
755     {
756       static inline void convert(const TypeCode *t,PyObject* o,void*,std::map<std::string,TOUT>& m)
757         {
758           DEBTRACE( "o refcnt: " << o->ob_refcnt );
759           PyObject *key, *value;
760           YACS::ENGINE::TypeCodeStruct* tst=(YACS::ENGINE::TypeCodeStruct*)t;
761           int nMember=tst->memberCount();
762           DEBTRACE("nMember="<<nMember);
763           for(int i=0;i<nMember;i++)
764             {
765               std::string name=tst->memberName(i);
766               DEBTRACE("Member name="<<name);
767               TypeCode* tm=tst->memberType(i);
768               value=PyDict_GetItemString(o, name.c_str());
769               if(value==NULL)
770                 {
771                   //member name not present
772                   //TODO delete all allocated objects in m
773 #ifdef _DEVDEBUG_
774                   PyObject_Print(o,stderr,Py_PRINT_RAW);
775                   std::cerr << std::endl;
776 #endif
777                   stringstream msg;
778                   msg << "Problem in conversion: member " << name << " not present " << endl;
779                   msg << " (" << __FILE__ << ":" << __LINE__ << ")";
780                   throw YACS::ENGINE::ConversionException(msg.str());
781                 }
782               DEBTRACE( "value refcnt: " << value->ob_refcnt );
783               TOUT ro=YacsConvertor<PYTHONImpl,PyObject*,void*,IMPLOUT,TOUT>(tm,value,0);
784               m[name]=ro;
785             }
786         }
787     };
788     /* End of ToYacs Convertor for PYTHONImpl */
789
790     //! FromYacs Convertor for PYTHONImpl
791     /*!
792      * Convert YACS<PyObject*> intermediate types to PyObject* types (PYTHONImpl)
793      */
794     template <>
795     struct convertFromYacsDouble<PYTHONImpl,PyObject*>
796     {
797       static inline PyObject* convert(const TypeCode *t,double o)
798         {
799           PyObject *pyob=PyFloat_FromDouble(o);
800           return pyob;
801         }
802     };
803     template <>
804     struct convertFromYacsInt<PYTHONImpl,PyObject*>
805     {
806       static inline PyObject* convert(const TypeCode *t,long o)
807         {
808           PyObject *pyob=PyLong_FromLong(o);
809           return pyob;
810         }
811     };
812     template <>
813     struct convertFromYacsString<PYTHONImpl,PyObject*>
814     {
815       static inline PyObject* convert(const TypeCode *t,std::string& o)
816         {
817           return PyString_FromString(o.c_str());
818         }
819     };
820     template <>
821     struct convertFromYacsBool<PYTHONImpl,PyObject*>
822     {
823       static inline PyObject* convert(const TypeCode *t,bool o)
824         {
825           return PyBool_FromLong ((long)o);
826         }
827     };
828     template <>
829     struct convertFromYacsObjref<PYTHONImpl,PyObject*>
830     {
831       static inline PyObject* convert(const TypeCode *t,std::string& o)
832         {
833           if(t->isA(Runtime::_tc_file))
834             {
835               //It's an objref file. Convert it specially
836               return PyString_FromString(o.c_str());
837             }
838           /* another way
839           PyObject* ob= PyObject_CallMethod(getSALOMERuntime()->getPyOrb(),"string_to_object","s",o.c_str());
840           DEBTRACE( "Objref python refcnt: " << ob->ob_refcnt );
841           return ob;
842           */
843
844           //Objref CORBA. prefix=IOR,corbaname,corbaloc
845           CORBA::Object_var obref;
846           try
847             {
848               obref = getSALOMERuntime()->getOrb()->string_to_object(o.c_str());
849 #ifdef REFCNT
850               DEBTRACE("obref refCount: " << obref->_PR_getobj()->pd_refCount);
851 #endif
852             }
853           catch(CORBA::Exception& ex) 
854             {
855               DEBTRACE( "Can't get reference to object." );
856               throw ConversionException("Can't get reference to object");
857             }
858
859           if( CORBA::is_nil(obref) )
860             {
861               DEBTRACE( "Can't get reference to object (or it was nil)." );
862               throw ConversionException("Can't get reference to object");
863             }
864
865           if(!obref->_is_a(t->id()))
866             {
867               stringstream msg;
868               msg << "Problem in conversion: an objref " << t->id() << " is expected " << endl;
869               msg << "An objref of type " << obref->_PD_repoId << " is given " << endl;
870               msg << " (" << __FILE__ << ":" << __LINE__ << ")";
871               throw YACS::ENGINE::ConversionException(msg.str());
872             }
873 #ifdef REFCNT
874           DEBTRACE("obref refCount: " << obref->_PR_getobj()->pd_refCount);
875 #endif
876 #ifdef _DEVDEBUG_
877           std::cerr << "_PD_repoId: " << obref->_PD_repoId << std::endl;
878           std::cerr << "_mostDerivedRepoId: " << obref->_PR_getobj()->_mostDerivedRepoId()  << std::endl;
879 #endif
880
881           //hold_lock is true: caller is supposed to hold the GIL.
882           //omniorb will not take the GIL
883           PyObject* ob= getSALOMERuntime()->getApi()->cxxObjRefToPyObjRef(obref, 1);
884
885 #ifdef _DEVDEBUG_
886           PyObject_Print(ob,stderr,Py_PRINT_RAW);
887           std::cerr << std::endl;
888           std::cerr << "obref is a generic: " << obref->_is_a("IDL:SALOME/GenericObj:1.0") << std::endl;
889           PyObject_Print(getSALOMERuntime()->get_omnipy(),stderr,Py_PRINT_RAW);
890           std::cerr << std::endl;
891 #endif
892
893           //ob is a CORBA::Object. Try to convert it to more specific type SALOME/GenericObj
894           if(obref->_is_a("IDL:SALOME/GenericObj:1.0"))
895             {
896               PyObject *result = PyObject_CallMethod(getSALOMERuntime()->get_omnipy(), "narrow", "Osi",ob,"IDL:SALOME/GenericObj:1.0",1);
897               if(result==NULL)
898                 PyErr_Clear();//Exception during narrow. Keep ob
899               else if(result==Py_None)
900                 Py_DECREF(result); //Can't narrow. Keep ob
901               else
902                 {
903                   //Can narrow. Keep result
904 #ifdef _DEVDEBUG_
905                   PyObject_Print(result,stderr,Py_PRINT_RAW);
906                   std::cerr << std::endl;
907 #endif
908                   Py_DECREF(ob);
909                   ob=result;
910                 }
911             }
912
913 #ifdef REFCNT
914           DEBTRACE("obref refCount: " << obref->_PR_getobj()->pd_refCount);
915 #endif
916           return ob;
917         }
918     };
919
920     template <>
921     struct convertFromYacsSequence<PYTHONImpl,PyObject*>
922     {
923       static inline PyObject* convert(const TypeCode *t,std::vector<PyObject*>& v)
924         {
925           std::vector<PyObject*>::const_iterator iter;
926           PyObject *pyob = PyList_New(v.size());
927           int i=0;
928           for(iter=v.begin();iter!=v.end();iter++)
929             {
930               PyObject* item=*iter;
931               DEBTRACE( "item refcnt: " << item->ob_refcnt );
932               PyList_SetItem(pyob,i,item);
933               DEBTRACE( "item refcnt: " << item->ob_refcnt );
934               i++;
935             }
936           return pyob;
937         }
938     };
939     template <>
940     struct convertFromYacsStruct<PYTHONImpl,PyObject*>
941     {
942       static inline PyObject* convert(const TypeCode *t,std::map<std::string,PyObject*>& m)
943         {
944           PyObject *pyob = PyDict_New();
945           std::map<std::string, PyObject*>::const_iterator pt;
946           for(pt=m.begin();pt!=m.end();pt++)
947             {
948               std::string name=(*pt).first;
949               PyObject* item=(*pt).second;
950               DEBTRACE( "item refcnt: " << item->ob_refcnt );
951               PyDict_SetItemString(pyob,name.c_str(),item);
952               Py_DECREF(item);
953               DEBTRACE( "item refcnt: " << item->ob_refcnt );
954             }
955           DEBTRACE( "pyob refcnt: " << pyob->ob_refcnt );
956           return pyob;
957         }
958     };
959     /* End of FromYacs Convertor for PYTHONImpl */
960
961     //! ToYacs Convertor for XMLImpl
962     /*!
963      * Partial specialization for XML implementation (XMLImpl)
964      * This convertor converts xml object to YACS<TOUT> types
965      */
966     template <ImplType IMPLOUT, class TOUT>
967     struct convertToYacsDouble<XMLImpl,xmlDocPtr,xmlNodePtr,IMPLOUT,TOUT>
968     {
969       static inline double convert(const TypeCode *t,xmlDocPtr doc,xmlNodePtr cur)
970         {
971           double d=0;
972           cur = cur->xmlChildrenNode;
973           while (cur != NULL)
974             {
975               if ((!xmlStrcmp(cur->name, (const xmlChar *)"double")))
976                 {
977                   //wait a double, got a double
978                   xmlChar * s = NULL;
979                   s = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
980                   if (s)
981                     {
982                       DEBTRACE( "convertToYacsDouble " << (const char *)s );
983                       d=Cstr2d((const char *)s);
984                       xmlFree(s);
985                     }
986                   else
987                     {
988                       DEBTRACE("############### workaround to improve...");
989                     }
990                   return d;
991                 }
992               else if ((!xmlStrcmp(cur->name, (const xmlChar *)"int")))
993                 {
994                   //wait a double, got an int
995                   xmlChar * s = NULL;
996                   s = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
997                   if (s)
998                     {
999                       DEBTRACE( "convertToYacsDouble " << (const char *)s );
1000                       d=Cstr2d((const char *)s);
1001                       xmlFree(s);
1002                     }
1003                   else
1004                     {
1005                       DEBTRACE("############### workaround to improve...");
1006                     }
1007                   return d;
1008                 }
1009               cur = cur->next;
1010             }
1011           stringstream msg;
1012           msg << "Problem in conversion from Xml to " << getImplName(IMPLOUT) << " with type:  " << t->id() ;
1013           msg << " (" << __FILE__ << ":" << __LINE__ << ")";
1014           throw YACS::ENGINE::ConversionException(msg.str());
1015         }
1016     };
1017     template <ImplType IMPLOUT, class TOUT>
1018     struct convertToYacsInt<XMLImpl,xmlDocPtr,xmlNodePtr,IMPLOUT,TOUT>
1019     {
1020       static inline long convert(const TypeCode *t,xmlDocPtr doc,xmlNodePtr cur)
1021         {
1022           long d=0;
1023           cur = cur->xmlChildrenNode;
1024           while (cur != NULL)
1025             {
1026               if ((!xmlStrcmp(cur->name, (const xmlChar *)"int")))
1027                 {
1028                   xmlChar * s = NULL;
1029                   s = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1030                   if (s)
1031                     {
1032                       DEBTRACE( "convertToYacsInt " << (const char *)s );
1033                       d=atol((const char *)s);
1034                       xmlFree(s);
1035                     }
1036                   else
1037                     {
1038                       DEBTRACE("############### workaround to improve...");
1039                     }
1040                   return d;
1041                 }
1042               cur = cur->next;
1043             }
1044           stringstream msg;
1045           msg << "Problem in conversion from Xml to " << getImplName(IMPLOUT) << " with type:  " << t->id() ;
1046           msg << " (" << __FILE__ << ":" << __LINE__ << ")";
1047           throw YACS::ENGINE::ConversionException(msg.str());
1048         }
1049     };
1050     template <ImplType IMPLOUT, class TOUT>
1051     struct convertToYacsString<XMLImpl,xmlDocPtr,xmlNodePtr,IMPLOUT,TOUT>
1052     {
1053       static inline std::string convert(const TypeCode *t,xmlDocPtr doc,xmlNodePtr cur)
1054         {
1055           cur = cur->xmlChildrenNode;
1056           while (cur != NULL)
1057             {
1058               if ((!xmlStrcmp(cur->name, (const xmlChar *)"string")))
1059                 {
1060                   //wait a string, got a string
1061                   xmlChar * s = NULL;
1062                   s = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1063                   if(s==0)return "";
1064                   DEBTRACE( "convertToYacsString " << (const char *)s );
1065                   std::string mystr=std::string((const char *)s);
1066                   xmlFree(s);
1067                   return mystr;
1068                 }
1069               cur = cur->next;
1070             }
1071           stringstream msg;
1072           msg << "Problem in conversion from Xml to " << getImplName(IMPLOUT) << " with type:  " << t->id() ;
1073           msg << " (" << __FILE__ << ":" << __LINE__ << ")";
1074           throw YACS::ENGINE::ConversionException(msg.str());
1075         }
1076     };
1077     template <ImplType IMPLOUT, class TOUT>
1078     struct convertToYacsBool<XMLImpl,xmlDocPtr,xmlNodePtr,IMPLOUT,TOUT>
1079     {
1080       static inline bool convert(const TypeCode *t,xmlDocPtr doc,xmlNodePtr cur)
1081         {
1082           cur = cur->xmlChildrenNode;
1083           while (cur != NULL)
1084             {
1085               if ((!xmlStrcmp(cur->name, (const xmlChar *)"boolean")))
1086                 {
1087                   //wait a boolean, got a boolean
1088                   xmlChar * s = NULL;
1089                   s = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1090                   bool ob =false;
1091                   if (s)
1092                     {
1093                       DEBTRACE( "convertToYacsBool " << (const char *)s );
1094                       ob=atoi((const char*)s)!=0;
1095                       xmlFree(s);
1096                     }
1097                   else
1098                     {
1099                       DEBTRACE("############### workaround to improve...");
1100                     }
1101                   return ob;
1102                 }
1103               cur = cur->next;
1104             }
1105           stringstream msg;
1106           msg << "Problem in conversion from Xml to " << getImplName(IMPLOUT) << " with type:  " << t->id() ;
1107           msg << " (" << __FILE__ << ":" << __LINE__ << ")";
1108           throw YACS::ENGINE::ConversionException(msg.str());
1109         }
1110     };
1111     template <ImplType IMPLOUT, class TOUT>
1112     struct convertToYacsObjref<XMLImpl,xmlDocPtr,xmlNodePtr,IMPLOUT,TOUT>
1113     {
1114       static inline std::string convert(const TypeCode *t,xmlDocPtr doc,xmlNodePtr cur)
1115         {
1116           cur = cur->xmlChildrenNode;
1117           while (cur != NULL)
1118             {
1119               if ((!xmlStrcmp(cur->name, (const xmlChar *)"objref")))
1120                 {
1121                   //we wait a objref, we have got a objref
1122                   xmlChar * s = NULL;
1123                   std::string mystr = "";
1124                   s = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1125                   if (s)
1126                     {
1127                       DEBTRACE( "convertToYacsObjref " << (const char *)s );
1128                       mystr = (const char *)s;
1129                       xmlFree(s);
1130                     }
1131                   else
1132                     {
1133                       DEBTRACE("############### workaround to improve...");
1134                     }
1135                   return mystr;
1136                 }
1137               cur = cur->next;
1138             }
1139           stringstream msg;
1140           msg << "Problem in conversion from Xml to " << getImplName(IMPLOUT) << " with type:  " << t->id() ;
1141           msg << " (" << __FILE__ << ":" << __LINE__ << ")";
1142           throw YACS::ENGINE::ConversionException(msg.str());
1143         }
1144     };
1145     template <ImplType IMPLOUT, class TOUT>
1146     struct convertToYacsSequence<XMLImpl,xmlDocPtr,xmlNodePtr,IMPLOUT,TOUT>
1147     {
1148       static inline void convert(const TypeCode *t,xmlDocPtr doc,xmlNodePtr cur,std::vector<TOUT>& v)
1149         {
1150           cur = cur->xmlChildrenNode;
1151           while (cur != NULL)
1152             {
1153               if ((!xmlStrcmp(cur->name, (const xmlChar *)"array")))
1154                 {
1155                   DEBTRACE( "parse sequence " );
1156                   xmlNodePtr cur1=cur->xmlChildrenNode;
1157                   while (cur1 != NULL)
1158                     {
1159                       if ((!xmlStrcmp(cur1->name, (const xmlChar *)"data")))
1160                         {
1161                           DEBTRACE( "parse data " );
1162                           xmlNodePtr cur2=cur1->xmlChildrenNode;
1163                           while (cur2 != NULL)
1164                             {
1165                               //collect all values
1166                               if ((!xmlStrcmp(cur2->name, (const xmlChar *)"value")))
1167                                 {
1168                                   TOUT ro=YacsConvertor<XMLImpl,xmlDocPtr,xmlNodePtr,IMPLOUT,TOUT>(t->contentType(),doc,cur2);
1169                                   v.push_back(ro);
1170                                 }
1171                               cur2 = cur2->next;
1172                             } // end while value
1173                           break;
1174                         }
1175                       cur1 = cur1->next;
1176                     } // end while data
1177                   break;
1178                 }
1179               cur = cur->next;
1180             } // end while array
1181         }
1182     };
1183     template <ImplType IMPLOUT, class TOUT>
1184     struct convertToYacsStruct<XMLImpl,xmlDocPtr,xmlNodePtr,IMPLOUT,TOUT>
1185     {
1186       static inline void convert(const TypeCode *t,xmlDocPtr doc,xmlNodePtr cur,std::map<std::string,TOUT>& m)
1187         {
1188           YACS::ENGINE::TypeCodeStruct* tst=(YACS::ENGINE::TypeCodeStruct*)t;
1189           int nMember=tst->memberCount();
1190           DEBTRACE("nMember="<<nMember);
1191           std::map<std::string,TypeCode*> mtc;
1192           for(int i=0;i<nMember;i++)
1193             {
1194               mtc[tst->memberName(i)]=tst->memberType(i);
1195             }
1196
1197           cur = cur->xmlChildrenNode;
1198           while (cur != NULL)
1199             {
1200               if ((!xmlStrcmp(cur->name, (const xmlChar *)"struct")))
1201                 {
1202                   DEBTRACE( "parse struct " );
1203                   xmlNodePtr cur1=cur->xmlChildrenNode;
1204                   while (cur1 != NULL)
1205                     {
1206                       if ((!xmlStrcmp(cur1->name, (const xmlChar *)"member")))
1207                         {
1208                           DEBTRACE( "parse member " );
1209                           xmlNodePtr cur2=cur1->xmlChildrenNode;
1210                           while (cur2 != NULL)
1211                             {
1212                               //member name
1213                               if ((!xmlStrcmp(cur2->name, (const xmlChar *)"name")))
1214                                 {
1215                                   xmlChar * s = NULL;
1216                                   s = xmlNodeListGetString(doc, cur2->xmlChildrenNode, 1);
1217                                   std::string name= (char *)s;
1218                                   cur2 = cur2->next;
1219                                   while (cur2 != NULL)
1220                                     {
1221                                       if ((!xmlStrcmp(cur2->name, (const xmlChar *)"value")))
1222                                         {
1223                                           TOUT ro=YacsConvertor<XMLImpl,xmlDocPtr,xmlNodePtr,IMPLOUT,TOUT>(mtc[name],doc,cur2);
1224                                           m[name]=ro;
1225                                           break;
1226                                         }
1227                                       cur2 = cur2->next;
1228                                     }
1229                                   xmlFree(s);
1230                                   break;
1231                                 }
1232                               cur2 = cur2->next;
1233                             } // end while member/value
1234                         }
1235                       cur1 = cur1->next;
1236                     } // end while member
1237                   break;
1238                 }
1239               cur = cur->next;
1240             } // end while struct
1241         }
1242     };
1243     /* End of ToYacs Convertor for XMLImpl */
1244
1245     //! FromYacs Convertor for XMLImpl
1246     /*!
1247      * Convert YACS<std::string> intermediate types to std::string types (XMLImpl)
1248      */
1249     template <>
1250     struct convertFromYacsDouble<XMLImpl,std::string>
1251     {
1252       static inline std::string convert(const TypeCode *t,double o)
1253         {
1254           stringstream msg ;
1255           msg << "<value><double>" << o << "</double></value>\n";
1256           return msg.str();
1257         }
1258     };
1259     template <>
1260     struct convertFromYacsInt<XMLImpl,std::string>
1261     {
1262       static inline std::string convert(const TypeCode *t,long o)
1263         {
1264           stringstream msg ;
1265           msg << "<value><int>" << o << "</int></value>\n";
1266           return msg.str();
1267         }
1268     };
1269     template <>
1270     struct convertFromYacsString<XMLImpl,std::string>
1271     {
1272       static inline std::string convert(const TypeCode *t,std::string& o)
1273         {
1274           std::string msg="<value><string>";
1275           return msg+o+"</string></value>\n";
1276         }
1277     };
1278     template <>
1279     struct convertFromYacsBool<XMLImpl,std::string>
1280     {
1281       static inline std::string convert(const TypeCode *t,bool o)
1282         {
1283           stringstream msg ;
1284           msg << "<value><boolean>" << o << "</boolean></value>\n";
1285           return msg.str();
1286         }
1287     };
1288     template <>
1289     struct convertFromYacsObjref<XMLImpl,std::string>
1290     {
1291       static inline std::string convert(const TypeCode *t,std::string& o)
1292         {
1293           return "<value><objref>" + o + "</objref></value>\n";
1294         }
1295     };
1296
1297     template <>
1298     struct convertFromYacsSequence<XMLImpl,std::string>
1299     {
1300       static inline std::string convert(const TypeCode *t,std::vector<std::string>& v)
1301         {
1302           std::vector<std::string>::const_iterator iter;
1303           stringstream xmlob;
1304           xmlob << "<value><array><data>\n";
1305           for(iter=v.begin();iter!=v.end();iter++)
1306             {
1307               xmlob << *iter;
1308             }
1309           xmlob << "</data></array></value>\n";
1310           DEBTRACE("Sequence= " << xmlob);
1311           return xmlob.str();
1312         }
1313     };
1314     template <>
1315     struct convertFromYacsStruct<XMLImpl,std::string>
1316     {
1317       static inline std::string convert(const TypeCode *t,std::map<std::string,std::string>& m)
1318         {
1319           std::string result="<value><struct>\n";
1320           std::map<std::string, std::string>::const_iterator pt;
1321           for(pt=m.begin();pt!=m.end();pt++)
1322             {
1323               std::string name=(*pt).first;
1324               std::string item=(*pt).second;
1325               result=result+"<member>\n";
1326               result=result+"<name>"+name+"</name>\n";
1327               result=result+item;
1328               result=result+"</member>\n";
1329             }
1330           result=result+"</struct></value>\n";
1331           return result;
1332         }
1333     };
1334
1335     /* End of FromYacs Convertor for XMLImpl */
1336
1337     //! ToYacs Convertor for NEUTRALImpl
1338     /*!
1339      * This convertor converts Neutral objects to intermediate YACS<TOUT> types
1340      * Template : Partial specialization for Neutral implementation with types YACS::ENGINE::Any*
1341      */
1342     template <ImplType IMPLOUT, class TOUT>
1343     struct convertToYacsDouble<NEUTRALImpl,YACS::ENGINE::Any*,void*,IMPLOUT,TOUT>
1344     {
1345       static inline double convert(const TypeCode *t,YACS::ENGINE::Any* o,void*)
1346         {
1347           if(o->getType()->kind()==Double)
1348             return o->getDoubleValue();
1349           else if(o->getType()->kind()==Int)
1350             return o->getIntValue();
1351
1352           stringstream msg;
1353           msg << "Problem in conversion: a double or int is expected " ;
1354           msg << " (" << __FILE__ << ":" << __LINE__ << ")";
1355           throw YACS::ENGINE::ConversionException(msg.str());
1356         }
1357     };
1358     template <ImplType IMPLOUT, class TOUT>
1359     struct convertToYacsInt<NEUTRALImpl,YACS::ENGINE::Any*,void*,IMPLOUT,TOUT>
1360     {
1361       static inline long convert(const TypeCode *t,YACS::ENGINE::Any* o,void*)
1362         {
1363           if(o->getType()->kind()==Int)
1364             return o->getIntValue();
1365           stringstream msg;
1366           msg << "Problem in conversion: a int is expected " ;
1367           msg << " (" << __FILE__ << ":" << __LINE__ << ")";
1368           throw YACS::ENGINE::ConversionException(msg.str());
1369         }
1370     };
1371     template <ImplType IMPLOUT, class TOUT>
1372     struct convertToYacsString<NEUTRALImpl,YACS::ENGINE::Any*,void*,IMPLOUT,TOUT>
1373     {
1374       static inline std::string convert(const TypeCode *t,YACS::ENGINE::Any* o,void*)
1375         {
1376           if(o->getType()->kind()==String)
1377             return o->getStringValue();
1378           stringstream msg;
1379           msg << "Problem in conversion: a string is expected " ;
1380           msg << " (" << __FILE__ << ":" << __LINE__ << ")";
1381           throw YACS::ENGINE::ConversionException(msg.str());
1382         }
1383     };
1384     template <ImplType IMPLOUT, class TOUT>
1385     struct convertToYacsBool<NEUTRALImpl,YACS::ENGINE::Any*,void*,IMPLOUT,TOUT>
1386     {
1387       static inline bool convert(const TypeCode *t,YACS::ENGINE::Any* o,void*)
1388         {
1389           if(o->getType()->kind()==Bool)
1390             return o->getBoolValue();
1391           else if(o->getType()->kind()==Int)
1392             return o->getIntValue() != 0;
1393           stringstream msg;
1394           msg << "Problem in conversion: a bool or int is expected " ;
1395           msg << " (" << __FILE__ << ":" << __LINE__ << ")";
1396           throw YACS::ENGINE::ConversionException(msg.str());
1397         }
1398     };
1399     template <ImplType IMPLOUT, class TOUT>
1400     struct convertToYacsObjref<NEUTRALImpl,YACS::ENGINE::Any*,void*,IMPLOUT,TOUT>
1401     {
1402       static inline std::string convert(const TypeCode *t,YACS::ENGINE::Any* o,void*)
1403         {
1404           if(o->getType()->kind()==String)
1405             return o->getStringValue();
1406           stringstream msg;
1407           msg << "Problem in conversion: a objref(string) is expected " ;
1408           msg << " (" << __FILE__ << ":" << __LINE__ << ")";
1409           throw YACS::ENGINE::ConversionException(msg.str());
1410         }
1411     };
1412     template <ImplType IMPLOUT, class TOUT>
1413     struct convertToYacsSequence<NEUTRALImpl,YACS::ENGINE::Any*,void*,IMPLOUT,TOUT>
1414     {
1415       static inline void convert(const TypeCode *t,YACS::ENGINE::Any* o,void*,std::vector<TOUT>& v)
1416         {
1417           SequenceAny* sdata= (SequenceAny*)o;
1418           int length=sdata->size();
1419           v.resize(length);
1420           for(int i=0;i<length;i++)
1421             {
1422               TOUT ro=YacsConvertor<NEUTRALImpl,YACS::ENGINE::Any*,void*,IMPLOUT,TOUT>(t->contentType(),(*sdata)[i],0);
1423               v[i]=ro;
1424             }
1425         }
1426     };
1427     /* End of ToYacs Convertor for NEUTRALImpl */
1428
1429     //! FromYacs Convertor for NEUTRALImpl
1430     /*!
1431      * Convert YACS<YACS::ENGINE::Any*> intermediate types to YACS::ENGINE::Any* types (NEUTRALImpl)
1432      */
1433     template <>
1434     struct convertFromYacsDouble<NEUTRALImpl,YACS::ENGINE::Any*>
1435     {
1436       static inline YACS::ENGINE::Any* convert(const TypeCode *t,double o)
1437         {
1438           YACS::ENGINE::Any *ob=YACS::ENGINE::AtomAny::New(o);
1439           return ob;
1440         }
1441     };
1442     template <>
1443     struct convertFromYacsInt<NEUTRALImpl,YACS::ENGINE::Any*>
1444     {
1445       static inline YACS::ENGINE::Any* convert(const TypeCode *t,long o)
1446         {
1447           return YACS::ENGINE::AtomAny::New((int)o);
1448         }
1449     };
1450     template <>
1451     struct convertFromYacsString<NEUTRALImpl,YACS::ENGINE::Any*>
1452     {
1453       static inline YACS::ENGINE::Any* convert(const TypeCode *t,std::string& o)
1454         {
1455           return YACS::ENGINE::AtomAny::New(o);
1456         }
1457     };
1458     template <>
1459     struct convertFromYacsBool<NEUTRALImpl,YACS::ENGINE::Any*>
1460     {
1461       static inline YACS::ENGINE::Any* convert(const TypeCode *t,bool o)
1462         {
1463           return YACS::ENGINE::AtomAny::New(o);
1464         }
1465     };
1466     template <>
1467     struct convertFromYacsObjref<NEUTRALImpl,YACS::ENGINE::Any*>
1468     {
1469       static inline YACS::ENGINE::Any* convert(const TypeCode *t,std::string& o)
1470         {
1471           return YACS::ENGINE::AtomAny::New(o);
1472         }
1473     };
1474
1475     template <>
1476     struct convertFromYacsSequence<NEUTRALImpl,YACS::ENGINE::Any*>
1477     {
1478       static inline YACS::ENGINE::Any* convert(const TypeCode *t,std::vector<YACS::ENGINE::Any*>& v)
1479         {
1480           std::vector<YACS::ENGINE::Any*>::const_iterator iter;
1481           //Objref are managed as string within YACS::ENGINE::Any objs
1482           SequenceAny* any;
1483           any=SequenceAny::New(t->contentType());
1484           for(iter=v.begin();iter!=v.end();iter++)
1485             {
1486               any->pushBack(*iter);
1487               (*iter)->decrRef();
1488             }
1489           DEBTRACE( "refcnt: " << any->getRefCnt() );
1490           return any;
1491         }
1492     };
1493     /* End of FromYacs Convertor for NEUTRALImpl */
1494
1495     //! ToYacs Convertor for CORBAImpl
1496     /*!
1497      * This convertor converts Corba objects to intermediate YACS<TOUT> types
1498      * Template : Partial specialization for CORBA implementation with types CORBA::Any*
1499      */
1500     template <ImplType IMPLOUT, class TOUT>
1501     struct convertToYacsDouble<CORBAImpl,CORBA::Any*,void*,IMPLOUT,TOUT>
1502     {
1503       static inline double convert(const TypeCode *t,CORBA::Any* o,void*)
1504         {
1505           CORBA::TypeCode_var tc = o->type();
1506           if (tc->equivalent(CORBA::_tc_double))
1507             {
1508               CORBA::Double d;
1509               *o >>= d;
1510               return d;
1511             }
1512           if (tc->equivalent(CORBA::_tc_long))
1513             {
1514               CORBA::Long d;
1515               *o >>= d;
1516               return d;
1517             }
1518           stringstream msg;
1519           msg << "Problem in CORBA to TOUT conversion: kind= " << t->kind() ;
1520           msg << " : " << __FILE__ << ":" << __LINE__;
1521           throw YACS::ENGINE::ConversionException(msg.str());
1522         }
1523     };
1524     template <ImplType IMPLOUT, class TOUT>
1525     struct convertToYacsInt<CORBAImpl,CORBA::Any*,void*,IMPLOUT,TOUT>
1526     {
1527       static inline long convert(const TypeCode *t,CORBA::Any* o,void*)
1528         {
1529           CORBA::Long d;
1530           if(*o >>= d)
1531             return d;
1532           stringstream msg;
1533           msg << "Problem in CORBA to TOUT conversion: kind= " << t->kind() ;
1534           msg << " : " << __FILE__ << ":" << __LINE__;
1535           throw YACS::ENGINE::ConversionException(msg.str());
1536         }
1537     };
1538     template <ImplType IMPLOUT, class TOUT>
1539     struct convertToYacsString<CORBAImpl,CORBA::Any*,void*,IMPLOUT,TOUT>
1540     {
1541       static inline std::string convert(const TypeCode *t,CORBA::Any* o,void*)
1542         {
1543           const char *s;
1544           if(*o >>=s)
1545             return s;
1546           stringstream msg;
1547           msg << "Problem in CORBA to TOUT conversion: kind= " << t->kind() ;
1548           msg << " : " << __FILE__ << ":" << __LINE__;
1549           throw YACS::ENGINE::ConversionException(msg.str());
1550         }
1551     };
1552     template <ImplType IMPLOUT, class TOUT>
1553     struct convertToYacsBool<CORBAImpl,CORBA::Any*,void*,IMPLOUT,TOUT>
1554     {
1555       static inline bool convert(const TypeCode *t,CORBA::Any* o,void*)
1556         {
1557           CORBA::Boolean b;
1558           if(*o >>= CORBA::Any::to_boolean(b))
1559             return b;
1560           stringstream msg;
1561           msg << "Problem in Corba to TOUT conversion: kind= " << t->kind() ;
1562           msg << " : " << __FILE__ << ":" << __LINE__;
1563           throw YACS::ENGINE::ConversionException(msg.str());
1564         }
1565     };
1566     template <ImplType IMPLOUT, class TOUT>
1567     struct convertToYacsObjref<CORBAImpl,CORBA::Any*,void*,IMPLOUT,TOUT>
1568     {
1569       static inline std::string convert(const TypeCode *t,CORBA::Any* o,void*)
1570         {
1571           char file[]="/tmp/XXXXXX";
1572           if(t->isA(Runtime::_tc_file))
1573             {
1574               Engines::Salome_file_ptr sf;
1575               *o >>= sf;
1576               Salome_file_i* f=new Salome_file_i();
1577               mkstemp(file);
1578               f->setDistributedFile(file);
1579               f->connect(sf);
1580               f->recvFiles();
1581               delete f;
1582               return file;
1583             }
1584           else
1585             {
1586               CORBA::Object_var ObjRef ;
1587               *o >>= CORBA::Any::to_object(ObjRef) ;
1588               CORBA::String_var objref = getSALOMERuntime()->getOrb()->object_to_string(ObjRef);
1589               return (char *)objref;
1590             }
1591         }
1592     };
1593     template <ImplType IMPLOUT, class TOUT>
1594     struct convertToYacsSequence<CORBAImpl,CORBA::Any*,void*,IMPLOUT,TOUT>
1595     {
1596       static inline void convert(const TypeCode *t,CORBA::Any* o,void*,std::vector<TOUT>& v)
1597         {
1598           CORBA::TypeCode_var tc=o->type();
1599           if (tc->kind() != CORBA::tk_sequence)
1600             {
1601               stringstream msg;
1602               msg << "Not a sequence corba type " << tc->kind();
1603               msg << " : " << __FILE__ << ":" << __LINE__;
1604               throw YACS::ENGINE::ConversionException(msg.str());
1605             }
1606           DynamicAny::DynAny_ptr dynany=getSALOMERuntime()->getDynFactory()->create_dyn_any(*o);
1607           DynamicAny::DynSequence_ptr ds=DynamicAny::DynSequence::_narrow(dynany);
1608           CORBA::release(dynany);
1609           DynamicAny::AnySeq_var as=ds->get_elements();
1610           int len=as->length();
1611           v.resize(len);
1612           for(int i=0;i<len;i++)
1613             {
1614 #ifdef REFCNT
1615               DEBTRACE("refcount CORBA as[i]: " << ((omni::TypeCode_base*)as[i].pd_tc.in())->pd_ref_count);
1616 #endif
1617               TOUT ro=YacsConvertor<CORBAImpl,CORBA::Any*,void*,IMPLOUT,TOUT>(t->contentType(),&as[i],0);
1618               v[i]=ro;
1619             }
1620           ds->destroy();
1621           CORBA::release(ds);
1622           for(int i=0;i<len;i++)
1623             {
1624 #ifdef REFCNT
1625               DEBTRACE("refcount CORBA as[i]: " << ((omni::TypeCode_base*)as[i].pd_tc.in())->pd_ref_count);
1626 #endif
1627             }
1628         }
1629     };
1630     template <ImplType IMPLOUT, class TOUT>
1631     struct convertToYacsStruct<CORBAImpl,CORBA::Any*,void*,IMPLOUT,TOUT>
1632     {
1633       static inline void convert(const TypeCode *t,CORBA::Any* o,void*,std::map<std::string,TOUT>& m)
1634         {
1635           CORBA::TypeCode_var tc=o->type();
1636           DEBTRACE(tc->kind());
1637           if (tc->kind() != CORBA::tk_struct)
1638             {
1639               stringstream msg;
1640               msg << "Not a struct corba type " << tc->kind();
1641               msg << " : " << __FILE__ << ":" << __LINE__;
1642               throw YACS::ENGINE::ConversionException(msg.str());
1643             }
1644           YACS::ENGINE::TypeCodeStruct* tst=(YACS::ENGINE::TypeCodeStruct*)t;
1645           DynamicAny::DynAny_ptr dynany=getSALOMERuntime()->getDynFactory()->create_dyn_any(*o);
1646           DynamicAny::DynStruct_ptr ds=DynamicAny::DynStruct::_narrow(dynany);
1647           CORBA::release(dynany);
1648           DynamicAny::NameValuePairSeq_var as=ds->get_members();
1649           int len=as->length();
1650           for(int i=0;i<len;i++)
1651             {
1652               std::string name=as[i].id.in();
1653               DEBTRACE(name);
1654               CORBA::Any value=as[i].value;
1655 #ifdef REFCNT
1656               DEBTRACE("refcount CORBA value: " << ((omni::TypeCode_base*)value.pd_tc.in())->pd_ref_count);
1657 #endif
1658               TOUT ro=YacsConvertor<CORBAImpl,CORBA::Any*,void*,IMPLOUT,TOUT>(tst->memberType(i),&value,0);
1659               m[name]=ro;
1660             }
1661           ds->destroy();
1662           CORBA::release(ds);
1663         }
1664     };
1665     /* End of ToYacs Convertor for CORBAImpl */
1666
1667     //! FromYacs Convertor for CORBAImpl
1668     /*!
1669      * Convert YACS<CORBA::Any*> intermediate types to CORBA::Any* types (CORBAImpl)
1670      */
1671     template <>
1672     struct convertFromYacsDouble<CORBAImpl,CORBA::Any*>
1673     {
1674       static inline CORBA::Any* convert(const TypeCode *t,double o)
1675         {
1676           CORBA::Any *any = new CORBA::Any();
1677           *any <<= o;
1678           return any;
1679         }
1680     };
1681     template <>
1682     struct convertFromYacsInt<CORBAImpl,CORBA::Any*>
1683     {
1684       static inline CORBA::Any* convert(const TypeCode *t,long o)
1685         {
1686           CORBA::Any *any = new CORBA::Any();
1687           *any <<= o;
1688           return any;
1689         }
1690     };
1691     template <>
1692     struct convertFromYacsString<CORBAImpl,CORBA::Any*>
1693     {
1694       static inline CORBA::Any* convert(const TypeCode *t,std::string& o)
1695         {
1696           CORBA::Any *any = new CORBA::Any();
1697           *any <<= o.c_str();
1698           return any;
1699         }
1700     };
1701     template <>
1702     struct convertFromYacsBool<CORBAImpl,CORBA::Any*>
1703     {
1704       static inline CORBA::Any* convert(const TypeCode *t,bool o)
1705         {
1706           CORBA::Any *any = new CORBA::Any();
1707           *any <<= CORBA::Any::from_boolean(o);
1708           return any;
1709         }
1710     };
1711     template <>
1712     struct convertFromYacsObjref<CORBAImpl,CORBA::Any*>
1713     {
1714       static inline CORBA::Any* convert(const TypeCode *t,std::string& o)
1715         {
1716           CORBA::Object_var obref;
1717           if(t->isA(Runtime::_tc_file))
1718             {
1719               //It's an objref file. Convert it specially
1720               Salome_file_i* aSalome_file = new Salome_file_i();
1721               try
1722                 {
1723                   aSalome_file->setLocalFile(o.c_str());
1724                   obref = aSalome_file->_this();
1725                   aSalome_file->_remove_ref();
1726                 }
1727               catch (const SALOME::SALOME_Exception& e)
1728                 {
1729                   stringstream msg;
1730                   msg << e.details.text;
1731                   msg << " : " << __FILE__ << ":" << __LINE__;
1732                   throw YACS::ENGINE::ConversionException(msg.str());
1733                 }
1734             }
1735           else
1736             {
1737               try
1738                 {
1739                   obref=getSALOMERuntime()->getOrb()->string_to_object(o.c_str());
1740                 }
1741               catch(CORBA::Exception& ex)
1742                 {
1743                   throw ConversionException("Can't get reference to object");
1744                 }
1745               if( CORBA::is_nil(obref) )
1746                 {
1747                   throw ConversionException("Can't get reference to object");
1748                 }
1749             }
1750 #ifdef REFCNT
1751           DEBTRACE("ObjRef refCount: " << obref->_PR_getobj()->pd_refCount);
1752 #endif
1753           CORBA::Any *any = new CORBA::Any();
1754           *any <<= obref;
1755 #ifdef REFCNT
1756           DEBTRACE("ObjRef refCount: " << obref->_PR_getobj()->pd_refCount);
1757 #endif
1758           return any;
1759         }
1760     };
1761
1762     template <>
1763     struct convertFromYacsSequence<CORBAImpl,CORBA::Any*>
1764     {
1765       static inline CORBA::Any* convert(const TypeCode *t,std::vector<CORBA::Any*>& v)
1766         {
1767           CORBA::ORB_ptr orb=getSALOMERuntime()->getOrb();
1768           std::vector<CORBA::Any*>::const_iterator iter;
1769
1770           // Build an Any from vector v
1771           int isObjref=0;
1772           if(t->contentType()->kind() == Objref)
1773             isObjref=1;
1774
1775           CORBA::TypeCode_var tc=getCorbaTC(t);
1776
1777           DynamicAny::DynAny_var dynany=getSALOMERuntime()->getDynFactory()->create_dyn_any_from_type_code(tc);
1778           DynamicAny::DynSequence_var ds = DynamicAny::DynSequence::_narrow(dynany);
1779           ds->set_length(v.size());
1780
1781           for(iter=v.begin();iter!=v.end();iter++)
1782             {
1783               DynamicAny::DynAny_var temp=ds->current_component();
1784               CORBA::Any* a=*iter;
1785               if(isObjref)
1786                 {
1787                   CORBA::Object_var zzobj ;
1788                   *a >>= CORBA::Any::to_object(zzobj) ;
1789                   temp->insert_reference(zzobj);
1790                 }
1791               else
1792                 temp->from_any(*a);
1793
1794               //delete intermediate any
1795               delete a;
1796               ds->next();
1797             }
1798
1799           CORBA::Any *any=ds->to_any();
1800           ds->destroy();
1801           return any;
1802         }
1803     };
1804     template <>
1805     struct convertFromYacsStruct<CORBAImpl,CORBA::Any*>
1806     {
1807       static inline CORBA::Any* convert(const TypeCode *t,std::map<std::string,CORBA::Any*>& m)
1808         {
1809           CORBA::ORB_ptr orb=getSALOMERuntime()->getOrb();
1810
1811           YACS::ENGINE::TypeCodeStruct* tst=(YACS::ENGINE::TypeCodeStruct*)t;
1812           int nMember=tst->memberCount();
1813           DEBTRACE("nMember="<<nMember);
1814
1815           CORBA::StructMemberSeq mseq;
1816           mseq.length(nMember);
1817           for(int i=0;i<nMember;i++)
1818             {
1819               const char * name=tst->memberName(i);
1820               if(m.count(name) !=0)
1821                 {
1822                   mseq[i].type=m[name]->type();
1823                 }
1824             }
1825           CORBA::TypeCode_var tc= orb->create_struct_tc("","",mseq);
1826           DynamicAny::DynAny_var dynany=getSALOMERuntime()->getDynFactory()->create_dyn_any_from_type_code(tc);
1827           DynamicAny::DynStruct_var ds = DynamicAny::DynStruct::_narrow(dynany);
1828
1829           for(int i=0;i<nMember;i++)
1830             {
1831               DynamicAny::DynAny_var temp=ds->current_component();
1832               const char * name=tst->memberName(i);
1833               DEBTRACE("Member name="<<name);
1834               //do not test member presence : test has been done in ToYacs convertor
1835               CORBA::Any* a=m[name];
1836               temp->from_any(*a);
1837               //delete intermediate any
1838               delete a;
1839               ds->next();
1840             }
1841           CORBA::Any *any=ds->to_any();
1842           ds->destroy();
1843
1844           return any;
1845         }
1846     };
1847     /* End of FromYacs Convertor for CORBAImpl */
1848
1849     /* Some shortcuts for CORBA to CORBA conversion */
1850     template <>
1851     inline CORBA::Any* convertDouble<CORBAImpl,CORBA::Any*,void*,CORBAImpl,CORBA::Any*>(const TypeCode *t,CORBA::Any* o,void* aux)
1852     {
1853       CORBA::TypeCode_var tc = o->type();
1854       if (tc->equivalent(CORBA::_tc_double))
1855         {
1856           return o;
1857         }
1858       if (tc->equivalent(CORBA::_tc_long))
1859         {
1860           CORBA::Long d;
1861           *o >>= d;
1862           CORBA::Any *any = new CORBA::Any();
1863           *any <<= (CORBA::Double)d;
1864           return any;
1865         }
1866       stringstream msg;
1867       msg << "Not a double or long corba type " << tc->kind();
1868       msg << " : " << __FILE__ << ":" << __LINE__;
1869       throw YACS::ENGINE::ConversionException(msg.str());
1870     }
1871     template <>
1872     inline CORBA::Any* convertInt<CORBAImpl,CORBA::Any*,void*,CORBAImpl,CORBA::Any*>(const TypeCode *t,CORBA::Any* o,void* aux)
1873     {
1874       return o;
1875     }
1876     template <>
1877     inline CORBA::Any* convertString<CORBAImpl,CORBA::Any*,void*,CORBAImpl,CORBA::Any*>(const TypeCode *t,CORBA::Any* o,void* aux)
1878     {
1879       return o;
1880     }
1881     template <>
1882     inline CORBA::Any* convertBool<CORBAImpl,CORBA::Any*,void*,CORBAImpl,CORBA::Any*>(const TypeCode *t,CORBA::Any* o,void* aux)
1883     {
1884       return o;
1885     }
1886     template <>
1887     inline CORBA::Any* convertObjref<CORBAImpl,CORBA::Any*,void*,CORBAImpl,CORBA::Any*>(const TypeCode *t,CORBA::Any* o,void* aux)
1888     {
1889       return o;
1890     }
1891     template <>
1892     inline CORBA::Any* convertStruct<CORBAImpl,CORBA::Any*,void*,CORBAImpl,CORBA::Any*>(const TypeCode *t,CORBA::Any* o,void* aux)
1893     {
1894       return o;
1895     }
1896     /* End of shortcuts for CORBA to CORBA conversion */
1897
1898     //! ToYacs Convertor for CPPImpl
1899     /*!
1900      * This convertor converts Python object to YACS<TOUT> types
1901      * Partial specialization for Python implementation with type PyObject* (PYTHONImpl)
1902      */
1903     template <ImplType IMPLOUT, class TOUT>
1904     struct convertToYacsDouble<CPPImpl,void*,const TypeCode*,IMPLOUT,TOUT>
1905     {
1906       static inline double convert(const TypeCode *t,void* o,const TypeCode* intype)
1907         {
1908           if(intype->kind()==YACS::ENGINE::Double)
1909             {
1910               return *(double*)o;
1911             }
1912           else if(intype->kind()==YACS::ENGINE::Int)
1913             {
1914               return *(long*)o;
1915             }
1916           stringstream msg;
1917           msg << "Problem in Cpp to TOUT conversion: kind= " << t->kind() ;
1918           msg << " : " << __FILE__ << ":" << __LINE__;
1919           throw YACS::ENGINE::ConversionException(msg.str());
1920         }
1921     };
1922     template <ImplType IMPLOUT, class TOUT>
1923     struct convertToYacsInt<CPPImpl,void*,const TypeCode*,IMPLOUT,TOUT>
1924     {
1925       static inline long convert(const TypeCode *t,void* o,const TypeCode* intype)
1926         {
1927           if(intype->kind()==YACS::ENGINE::Int)
1928             {
1929               return *(long*)o;
1930             }
1931           stringstream msg;
1932           msg << "Problem in Cpp to TOUT conversion: kind= " << t->kind() ;
1933           msg << " : " << __FILE__ << ":" << __LINE__;
1934           throw YACS::ENGINE::ConversionException(msg.str());
1935         }
1936     };
1937     /* End of ToYacs Convertor for CPPImpl */
1938
1939     //Python conversions
1940     std::string convertPyObjectXml(const TypeCode *t,PyObject *data)
1941       {
1942         return YacsConvertor<PYTHONImpl,PyObject*,void*,XMLImpl,std::string>(t,data,0);
1943       }
1944     YACS::ENGINE::Any* convertPyObjectNeutral(const TypeCode *t,PyObject *data)
1945       {
1946         return YacsConvertor<PYTHONImpl,PyObject*,void*,NEUTRALImpl,YACS::ENGINE::Any*>(t,data,0);
1947       }
1948     CORBA::Any* convertPyObjectCorba(const TypeCode *t,PyObject *data)
1949       {
1950         return YacsConvertor<PYTHONImpl,PyObject*,void*,CORBAImpl,CORBA::Any*>(t,data,0);
1951       }
1952
1953     //XML conversions
1954     PyObject* convertXmlPyObject(const TypeCode *t,xmlDocPtr doc,xmlNodePtr cur)
1955       {
1956         return YacsConvertor<XMLImpl,xmlDocPtr,xmlNodePtr,PYTHONImpl,PyObject*>(t,doc,cur);
1957       }
1958     YACS::ENGINE::Any* convertXmlNeutral(const TypeCode *t,xmlDocPtr doc,xmlNodePtr cur)
1959       {
1960         return YacsConvertor<XMLImpl,xmlDocPtr,xmlNodePtr,NEUTRALImpl,YACS::ENGINE::Any*>(t,doc,cur);
1961       }
1962     CORBA::Any* convertXmlCorba(const TypeCode *t,xmlDocPtr doc,xmlNodePtr cur)
1963       {
1964         return YacsConvertor<XMLImpl,xmlDocPtr,xmlNodePtr,CORBAImpl,CORBA::Any*>(t,doc,cur);
1965       }
1966     //NEUTRAL conversions
1967     PyObject* convertNeutralPyObject(const TypeCode *t,YACS::ENGINE::Any* data)
1968       {
1969         return YacsConvertor<NEUTRALImpl,YACS::ENGINE::Any*,void*,PYTHONImpl,PyObject*>(t,data,0);
1970       }
1971     std::string convertNeutralXml(const TypeCode *t,YACS::ENGINE::Any* data)
1972       {
1973         return YacsConvertor<NEUTRALImpl,YACS::ENGINE::Any*,void*,XMLImpl,std::string>(t,data,0);
1974       }
1975     CORBA::Any* convertNeutralCorba(const TypeCode *t,YACS::ENGINE::Any* data)
1976       {
1977         return YacsConvertor<NEUTRALImpl,YACS::ENGINE::Any*,void*,CORBAImpl,CORBA::Any*>(t,data,0);
1978       }
1979     YACS::ENGINE::Any *convertNeutralNeutral(const TypeCode *t, YACS::ENGINE::Any* data)
1980       {
1981         data->incrRef();
1982         return data;
1983       }
1984
1985     //CORBA conversions
1986     PyObject* convertCorbaPyObject(const TypeCode *t,CORBA::Any* data)
1987       {
1988         return YacsConvertor<CORBAImpl,CORBA::Any*,void*,PYTHONImpl,PyObject*>(t,data,0);
1989       }
1990     std::string convertCorbaXml(const TypeCode *t,CORBA::Any* data)
1991       {
1992         return YacsConvertor<CORBAImpl,CORBA::Any*,void*,XMLImpl,std::string>(t,data,0);
1993       }
1994     YACS::ENGINE::Any* convertCorbaNeutral(const TypeCode *t,CORBA::Any* data)
1995       {
1996         return YacsConvertor<CORBAImpl,CORBA::Any*,void*,NEUTRALImpl,YACS::ENGINE::Any*>(t,data,0);
1997       }
1998     CORBA::Any *convertCorbaCorba(const TypeCode *t,CORBA::Any *data)
1999       {
2000         return YacsConvertor<CORBAImpl,CORBA::Any*,void*,CORBAImpl,CORBA::Any*>(t,data,0);
2001       }
2002   }
2003 }