1 #ifndef __CONTENTOFDATAFLOW_HXX__
2 #define __CONTENTOFDATAFLOW_HXX__
5 #include "TypeCheckerDataFlow.hxx"
6 #include "ConversionException.hxx"
17 class ContentOfDataFlow
22 static void duplicate(Type content);
23 static void release(Type& content);
24 static Type createNewContent(const std::string& content, DynType typeOfContent) throw(Exception);
25 static Type convertContent(Type content, DynType fromType, DynType toType) throw(ConversionException);
26 static bool isStaticallyCompatibleWith(DynType fromType, DynType toType) throw(Exception);
28 static Type createNewContent(T value);
29 template<YACS::DynType typ>
30 static Type createNewContent(const std::string& content) throw(Exception);
32 static void readContent(Type content, T& value) throw(Exception);
33 static Type neuter() { return 0; }
34 static std::string getRepresentation(Type content);
36 static Type allocate(int lgth);
38 static const char STRFORNULLREPR[];
42 ContentOfDataFlow::Type ContentOfDataFlow::createNewContent(T value)
44 std::ostringstream stream;
46 int length=stream.str().length();
47 ContentOfDataFlow::Type ret=allocate(length);
49 memcpy(retC+1,stream.str().c_str(),length+1);
54 void ContentOfDataFlow::readContent(ContentOfDataFlow::Type content, T& value) throw(Exception)
56 if(content==ContentOfDataFlow::neuter())
57 throw Exception("no content to read");
58 char *contentC=(char *)content;
59 contentC+=sizeof(int);
60 const DynType typ=TypeDescriptorTraitsInv<T>::_typeEnum;
61 std::istringstream stream(contentC);
63 if(stream.fail() || !stream.eof())
65 std::string what="Content not recognized as "; what+=TypeDescriptorTraits<TypeDescriptorTraitsInv<T>::_typeEnum>::_name;
66 throw Exception(what);
70 template<YACS::DynType typ>
71 ContentOfDataFlow::Type ContentOfDataFlow::createNewContent(const std::string& content) throw(Exception)
73 std::istringstream stream(content);
74 typename TypeDescriptorTraits<typ>::ConcreteType value;
76 if(!stream.fail() && stream.eof())
77 return createNewContent(value);
80 std::string what(content);
81 what+=" is not recognized as "; what+=TypeDescriptorTraits<typ>::_name;
82 throw Exception(what);