Salome HOME
PR: what YACS means
[modules/yacs.git] / src / basicData / TypeCheckerDataStream.cxx
1 #include "TypeCheckerDataStream.hxx"
2
3 namespace YACS
4 {
5   namespace ENGINE
6   {
7     template< template< StreamType type> class TREATMENTPERTYPE >
8     class DynToStaticStreamTypeDispatcher1
9     {
10     public:
11       template<class  T, class U>
12       static void perform(YACS::StreamType myTypeDyn, T input, U& output) throw(Exception)
13       {
14         switch(myTypeDyn)
15           {
16           case SDouble:
17             TREATMENTPERTYPE<SDouble>::perform(input, output);
18             break;
19           default:
20             throw Exception("Unknow stream type enum");
21           }
22       }
23     };
24
25     template< template< StreamType fromType, StreamType toType> class TREATMENTPERTYPE >
26     class DynToStaticStreamTypeDispatcher2
27     {
28       template<StreamType toType> class TREATMENTPERTYPESDOUBLE : public TREATMENTPERTYPE<SDouble,toType> { };
29     public:
30       template<class  T, class U>
31       static void perform(YACS::StreamType myTypeDynFrom, YACS::StreamType myTypeDynTo, T input, U& output) throw(Exception)
32       {
33         switch(myTypeDynFrom)
34           {
35           case SDouble:
36             DynToStaticStreamTypeDispatcher1<TREATMENTPERTYPESDOUBLE>::perform(myTypeDynTo, input, output);
37             break;
38           default:
39             throw Exception("Unknow stream type enum");
40           }
41       }
42     };
43
44     template<YACS::StreamType baseTyp>
45     class StreamTypeDescriptorTraits
46     {
47     };
48
49     template<>
50     class StreamTypeDescriptorTraits<YACS::SDouble>
51     {
52     public:
53       static const char _name[];
54     };
55
56     /**
57      *
58      * This class has the responsability of the validity of the content of stream data regarding only statically its types from and to.
59      *
60      */
61     template< StreamType fromType, StreamType toType >
62     class StaticStreamTypeConverter
63     {
64     public:
65       enum { _staticallyCompatible=0 };
66     };
67
68     template<StreamType type>
69     class StaticStreamTypeConverter<type,type>
70     {
71     public:
72       enum { _staticallyCompatible=1 };
73     };
74   }
75 }
76
77 using namespace YACS::ENGINE;
78
79 const char StreamTypeDescriptorTraits<YACS::SDouble>::_name[]="SDouble";
80
81 const char TypeCheckerDataStream::UNRECOGNIZEDTYPENAME[]="Unrecognized type";
82
83 //Part of TypeCheckerDataStream::areStaticallyCompatible implementation
84 template< YACS::StreamType fromType, YACS::StreamType toType >
85 class TreatmentToCheckStaticallyTypes
86 {
87 public:
88   static void perform(int input, bool& ret)
89   {
90     ret=StaticStreamTypeConverter<fromType,toType>::_staticallyCompatible;
91   }
92 };
93
94 bool TypeCheckerDataStream::areStaticallyCompatible(YACS::StreamType type1, YACS::StreamType type2) throw(Exception)
95 {
96   bool ret;
97   int fake;
98   //DynToStaticStreamTypeDispatcher2<TreatmentToCheckStaticallyTypes>::perform(type1, type2, fake, ret);
99   return ret;
100 }
101
102 // Part of TypeCheckerDataStream::edGetTypeInPrintableForm implementation
103
104 template< YACS::StreamType type >
105 class TreatmentForNameOfStreamType
106 {
107 public:
108   static void perform(int input, std::string& ret)
109   {
110     ret=StreamTypeDescriptorTraits<type>::_name;
111   }
112 };
113
114 std::string TypeCheckerDataStream::edGetTypeInPrintableForm(YACS::StreamType type)
115 {
116   try
117     {
118       int fake1;
119       std::string ret;
120       DynToStaticStreamTypeDispatcher1< TreatmentForNameOfStreamType >::perform(type, fake1, ret);
121       return ret;
122     }
123   catch(Exception& e)
124     {
125       return UNRECOGNIZEDTYPENAME;
126     }
127 }