// Copyright (C) 2010, Guy Barrand. All rights reserved. // See the file tools.license for terms. #ifndef tools_wroot_element #define tools_wroot_element #include "buffer" #include "named" #include "../snpf" namespace tools { namespace wroot { namespace streamer_info { enum Type { // sizeof : BASE = 0, // x ARRAY = 20, // ? POINTER = 40, // 4 POINTER_INT = 43, // 4 POINTER_FLOAT = 45, // 4 POINTER_DOUBLE = 48, // 4 COUNTER = 6, // 4 CHAR = 1, // 1 SHORT = 2, // 2 INT = 3, // 4 FLOAT = 5, // 4 DOUBLE = 8, // 8 UNSIGNED_CHAR = 11, // 1 UNSIGNED_SHORT = 12, // 2 UNSIGNED_INT = 13, // 4 BOOL = 18, // 1 ? OBJECT = 61, // ? OBJECT_ANY = 62, // ? OBJECT_ARROW = 63, // ? OBJECT_POINTER = 64, // ? TSTRING = 65, // 8 TOBJECT = 66, // 12 TNAMED = 67 // 28 }; } class streamer_element : public virtual ibo { static const std::string& s_class() { static const std::string s_v("tools::wroot::streamer_element"); return s_v; } public: //ibo virtual const std::string& store_cls() const { static const std::string s_v("TStreamerElement"); return s_v; } virtual bool stream(buffer& aBuffer) const { unsigned int c; if(!aBuffer.write_version(2,c)) return false; if(!Named_stream(aBuffer,fName,fTitle)) return false; if(!aBuffer.write(fType)) return false; if(!aBuffer.write(fSize)) return false; if(!aBuffer.write(fArrayLength)) return false; if(!aBuffer.write(fArrayDim)) return false; if(!aBuffer.write_fast_array(fMaxIndex,5)) return false; if(!aBuffer.write(fTypeName)) return false; if(!aBuffer.set_byte_count(c)) return false; return true; } public: virtual streamer_element* copy() const = 0; public: virtual void out(std::ostream& aOut) const { char s[128]; snpf(s,sizeof(s)," %-14s%-15s offset=%3d type=%2d %-20s", fTypeName.c_str(),fullName().c_str(),fOffset,fType,fTitle.c_str()); aOut << s << std::endl; } public: streamer_element(const std::string& aName,const std::string& aTitle, int aOffset,int aType,const std::string& aTypeName) :fName(aName),fTitle(aTitle),fType(aType) ,fSize(0),fArrayLength(0),fArrayDim(0),fOffset(aOffset) ,fTypeName(aTypeName){ #ifdef TOOLS_MEM mem::increment(s_class().c_str()); #endif for(int i=0;i<5;i++) fMaxIndex[i] = 0; } virtual ~streamer_element(){ #ifdef TOOLS_MEM mem::decrement(s_class().c_str()); #endif } protected: streamer_element(const streamer_element& a_from) :ibo(a_from) ,fName(a_from.fName),fTitle(a_from.fTitle) ,fType(a_from.fType),fSize(a_from.fSize) ,fArrayLength(a_from.fArrayLength) ,fArrayDim(a_from.fArrayDim),fOffset(a_from.fOffset) ,fTypeName(a_from.fTypeName){ #ifdef TOOLS_MEM mem::increment(s_class().c_str()); #endif for(int i=0;i<5;i++) fMaxIndex[i] = a_from.fMaxIndex[i]; } streamer_element& operator=(const streamer_element& a_from){ fName = a_from.fName; fTitle = a_from.fTitle; fType = a_from.fType; fSize = a_from.fSize; fArrayLength = a_from.fArrayLength; fArrayDim = a_from.fArrayDim; fOffset = a_from.fOffset; fTypeName = a_from.fTypeName; for(int i=0;i<5;i++) fMaxIndex[i] = a_from.fMaxIndex[i]; return *this; } public: virtual void setArrayDimension(int aDimension){ fArrayDim = aDimension; if(aDimension) fType += streamer_info::ARRAY; //fNewType = fType; } virtual void setMaxIndex(int aDimension,int aMaximum){ //set maximum index for array with dimension dim if (aDimension < 0 || aDimension > 4) return; fMaxIndex[aDimension] = aMaximum; if (fArrayLength == 0) fArrayLength = aMaximum; else fArrayLength *= aMaximum; } virtual std::string fullName() const { std::string s = fName; for (int i=0;i") fType = streamer_info::OBJECT_ARROW; } virtual ~streamer_object_pointer(){} public: streamer_object_pointer(const streamer_object_pointer& a_from) :ibo(a_from),streamer_element(a_from){} streamer_object_pointer& operator=(const streamer_object_pointer& a_from){ streamer_element::operator=(a_from); return *this; } }; class streamer_object_any : public streamer_element { public: //ibo virtual const std::string& store_cls() const { static const std::string s_v("TStreamerObjectAny"); return s_v; } virtual bool stream(buffer& aBuffer) const { unsigned int c; if(!aBuffer.write_version(2,c)) return false; if(!streamer_element::stream(aBuffer)) return false; if(!aBuffer.set_byte_count(c)) return false; return true; } public: //streamer_element virtual streamer_element* copy() const { return new streamer_object_any(*this); } public: streamer_object_any(const std::string& aName,const std::string& aTitle, int aOffset,const std::string& aTypeName) :streamer_element(aName,aTitle,aOffset,streamer_info::OBJECT_ANY,aTypeName) {} virtual ~streamer_object_any(){} public: streamer_object_any(const streamer_object_any& a_from) :ibo(a_from),streamer_element(a_from){} streamer_object_any& operator=(const streamer_object_any& a_from){ streamer_element::operator=(a_from); return *this; } }; class streamer_STL : public streamer_element { public: //ibo virtual const std::string& store_cls() const { static const std::string s_v("TStreamerSTL"); return s_v; } virtual bool stream(buffer& aBuffer) const { unsigned int c; if(!aBuffer.write_version(2,c)) return false; if(!streamer_element::stream(aBuffer)) return false; if(!aBuffer.write(fSTLtype)) return false; if(!aBuffer.write(fCtype)) return false; if(!aBuffer.set_byte_count(c)) return false; return true; } public: //streamer_element virtual streamer_element* copy() const { return new streamer_STL(*this); } protected: enum ESTLtype { kSTL = 300, kSTLstring =365, kSTLvector = 1, kSTLlist = 2, kSTLdeque = 3, kSTLmap = 4, kSTLset = 5, kSTLmultimap=6, kSTLmultiset=7}; // Instead of EDataType, we use the Streamer_Info::Type. //enum EDataType { // kChar_t = 1, kUChar_t = 11, kShort_t = 2, kUShort_t = 12, // kInt_t = 3, kUInt_t = 13, kLong_t = 4, kULong_t = 14, // kFloat_t = 5, kDouble_t = 8, kchar = 10, kOther_t = -1 //}; public: streamer_STL(const std::string& aName,const std::string& aTitle, int aOffset, streamer_info::Type aType, //Must match TDataType/EDataType const std::string& aTypeName) :streamer_element(aName,aTitle,aOffset,kSTL,aTypeName){ fSTLtype = kSTLvector; fCtype = aType; } virtual ~streamer_STL(){} public: streamer_STL(const streamer_STL& a_from) :ibo(a_from),streamer_element(a_from) ,fSTLtype(a_from.fSTLtype) ,fCtype(a_from.fCtype) {} streamer_STL& operator=(const streamer_STL& a_from){ streamer_element::operator=(a_from); fSTLtype = a_from.fSTLtype; fCtype = a_from.fCtype; return *this; } protected: int fSTLtype; //type of STL vector int fCtype; //STL contained type }; }} #endif