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