1 #ifndef __TYPECHECKERDATAFLOW_HXX__
2 #define __TYPECHECKERDATAFLOW_HXX__
5 #include "ConversionException.hxx"
16 * @ note : container in all this file is a concept that stores any data of any data into container::Type type.
17 * container concept must at least implement
18 * - createNewContent method
19 * - readContent method
20 * and container must define Type class that stores data independently of type.
21 * ContentOfDataFlow is one class fulfilling this concept !
24 template< template< DynType type> class TREATMENTPERTYPE >
25 class DynToStaticTypeDispatcher1
28 template<class T, class U>
29 static void perform(YACS::DynType myTypeDyn, T input, U& output) throw(Exception)
34 TREATMENTPERTYPE<Double>::perform(input, output);
37 TREATMENTPERTYPE<Int>::perform(input, output);
40 TREATMENTPERTYPE<String>::perform(input, output);
43 TREATMENTPERTYPE<Bool>::perform(input, output);
46 throw Exception("Unknow type enum");
51 template< template< DynType fromType, DynType toType> class TREATMENTPERTYPE >
52 class DynToStaticTypeDispatcher2
54 template<DynType toType> class TREATMENTPERTYPEDOUBLE : public TREATMENTPERTYPE<Double,toType> { };
55 template<DynType toType> class TREATMENTPERTYPEINT : public TREATMENTPERTYPE<Int,toType> { };
56 template<DynType toType> class TREATMENTPERTYPEBOOL : public TREATMENTPERTYPE<Bool,toType> { };
57 template<DynType toType> class TREATMENTPERTYPESTRING : public TREATMENTPERTYPE<String,toType> { };
59 template<class T, class U>
60 static void perform(YACS::DynType myTypeDynFrom, YACS::DynType myTypeDynTo, T input, U& output) throw(Exception)
66 DynToStaticTypeDispatcher1<TREATMENTPERTYPEDOUBLE>::perform(myTypeDynTo, input, output);
71 TREATMENTPERTYPE<Double,Double>::perform(input, output);
74 TREATMENTPERTYPE<Double,Int>::perform(input, output);
77 TREATMENTPERTYPE<Double,String>::perform(input, output);
80 TREATMENTPERTYPE<Double,Bool>::perform(input, output);
83 throw Exception("Unknow type enum");
89 DynToStaticTypeDispatcher1<TREATMENTPERTYPEINT>::perform(myTypeDynTo, input, output);
94 TREATMENTPERTYPE<Int,Double>::perform(input, output);
97 TREATMENTPERTYPE<Int,Int>::perform(input, output);
100 TREATMENTPERTYPE<Int,String>::perform(input, output);
103 TREATMENTPERTYPE<Int,Bool>::perform(input, output);
106 throw Exception("Unknow type enum");
112 DynToStaticTypeDispatcher1<TREATMENTPERTYPESTRING>::perform(myTypeDynTo, input, output);
117 TREATMENTPERTYPE<String,Double>::perform(input, output);
120 TREATMENTPERTYPE<String,Int>::perform(input, output);
123 TREATMENTPERTYPE<String,String>::perform(input, output);
126 TREATMENTPERTYPE<String,Bool>::perform(input, output);
129 throw Exception("Unknow type enum");
135 DynToStaticTypeDispatcher1<TREATMENTPERTYPESTRING>::perform(myTypeDynTo, input, output);
140 TREATMENTPERTYPE<Bool,Double>::perform(input, output);
143 TREATMENTPERTYPE<Bool,Int>::perform(input, output);
146 TREATMENTPERTYPE<Bool,String>::perform(input, output);
149 TREATMENTPERTYPE<Bool,Bool>::perform(input, output);
152 throw Exception("Unknow type enum");
157 throw Exception("Unknow type enum");
162 template<YACS::DynType baseTyp>
163 class TypeDescriptorTraits
168 class TypeDescriptorTraitsInv
173 class TypeDescriptorTraits<YACS::Double>
176 typedef double ConcreteType;
177 static const char _name[];
181 class TypeDescriptorTraitsInv<double>
184 static const YACS::DynType _typeEnum=Double;
188 class TypeDescriptorTraits<YACS::Int>
191 typedef int ConcreteType;
192 static const char _name[];
196 class TypeDescriptorTraitsInv<int>
199 static const YACS::DynType _typeEnum=Int;
203 class TypeDescriptorTraits<YACS::Bool>
206 typedef bool ConcreteType;
207 static const char _name[];
211 class TypeDescriptorTraitsInv<bool>
214 static const YACS::DynType _typeEnum=Bool;
218 class TypeDescriptorTraits<YACS::String>
221 typedef std::string ConcreteType;
222 static const char _name[];
226 class TypeDescriptorTraitsInv<std::string>
229 static const YACS::DynType _typeEnum=String;
234 * This class has the responsability of the validity of the content of data regarding only statically its types from and to.
237 template<DynType fromType, DynType toType >
238 class StaticTypeConverter
241 enum { _staticallyCompatible=0 };
242 static typename TypeDescriptorTraits<toType>::ConcreteType traduce(typename TypeDescriptorTraits<fromType>::ConcreteType input) throw(ConversionException)
244 throw ConversionException(TypeDescriptorTraits<fromType>::_name, TypeDescriptorTraits<toType>::_name);
248 //Specialisation of the previously declared StaticTypeConverter class when 'fromType' and 'toType' are equal.
249 template<DynType aType>
250 class StaticTypeConverter<aType, aType>
253 enum { _staticallyCompatible=1 };
254 static typename TypeDescriptorTraits<aType>::ConcreteType traduce(typename TypeDescriptorTraits<aType>::ConcreteType input) throw(ConversionException)
261 class StaticTypeConverter<YACS::Double, YACS::Int>
264 enum { _staticallyCompatible=1 };
265 static TypeDescriptorTraits<YACS::Int>::ConcreteType traduce(TypeDescriptorTraits<YACS::Double>::ConcreteType input) throw(ConversionException)
267 return (TypeDescriptorTraits<YACS::Int>::ConcreteType) input;
272 class StaticTypeConverter<YACS::Int, YACS::Double>
275 enum { _staticallyCompatible=1 };
276 static TypeDescriptorTraits<YACS::Double>::ConcreteType traduce(TypeDescriptorTraits<YACS::Int>::ConcreteType input) throw(ConversionException)
278 return (TypeDescriptorTraits<YACS::Double>::ConcreteType) input;
283 class StaticTypeConverter<YACS::Int, YACS::Bool>
286 enum { _staticallyCompatible=1 };
287 static TypeDescriptorTraits<YACS::Bool>::ConcreteType traduce(TypeDescriptorTraits<YACS::Int>::ConcreteType input) throw(ConversionException)
297 class StaticTypeConverter<YACS::Bool, YACS::Int>
300 enum { _staticallyCompatible=1 };
301 static TypeDescriptorTraits<YACS::Int>::ConcreteType traduce(TypeDescriptorTraits<YACS::Bool>::ConcreteType input) throw(ConversionException)
312 * This class has the responsability of the validity of the content of data regarding statically and dynamically its types from and to.
315 template<class container, DynType fromType, DynType toType >
316 class StaticAndDynamicTypeConverter
319 static typename container::Type convert(typename container::Type source) throw(ConversionException)
321 if(!StaticTypeConverter<fromType, toType>::_staticallyCompatible)
322 throw ConversionException(TypeDescriptorTraits<fromType>::_name, TypeDescriptorTraits<toType>::_name);
323 typename TypeDescriptorTraits<fromType>::ConcreteType sourceValue;
324 container::readContent(source,sourceValue);
325 typename TypeDescriptorTraits<toType>::ConcreteType targetValue=StaticTypeConverter<fromType, toType>::traduce(sourceValue);
326 return container::createNewContent(targetValue);