Warning, /include/Geant4/tools/wroot/base_leaf is written in an unsupported language. File is not indexed.
0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003
0004 #ifndef tools_wroot_base_leaf
0005 #define tools_wroot_base_leaf
0006
0007 #ifdef TOOLS_MEM
0008 #include "../mem"
0009 #endif
0010
0011 #include "named"
0012
0013 #include "cids"
0014 #include "../scast"
0015
0016 namespace tools {
0017 namespace wroot {
0018
0019 class base_leaf : public virtual ibo {
0020 static unsigned int kNullTag() {return 0;}
0021 #ifdef TOOLS_MEM
0022 public:
0023 static const std::string& s_class() {
0024 static const std::string s_v("tools::wroot::base_leaf");
0025 return s_v;
0026 }
0027 #endif
0028 public:
0029 static cid id_class() {return base_leaf_cid();}
0030 virtual void* cast(cid a_class) const {
0031 if(void* p = cmp_cast<base_leaf>(this,a_class)) {return p;}
0032 else return 0;
0033 }
0034 virtual cid id_cls() const {return id_class();}
0035 public: //ibo
0036 virtual bool stream(buffer& a_buffer) const {
0037 //::printf("debug : base_leaf::stream %s\n",m_name.c_str());
0038 //::printf("debug : m_length %d\n",m_length);
0039 //::printf("debug : m_is_range %d\n",m_is_range);
0040 //::printf("debug : m_leaf_count %lu\n",m_leaf_count);
0041 unsigned int c;
0042 if(!a_buffer.write_version(2,c)) return false;
0043 if(!Named_stream(a_buffer,m_name,m_title)) return false;
0044 if(!a_buffer.write(m_length)) return false;
0045 if(!a_buffer.write(m_length_type)) return false;
0046 uint32 fOffset = 0;
0047 if(!a_buffer.write(fOffset)) return false;
0048 if(!a_buffer.write(m_is_range)) return false;
0049 bool fIsUnsigned = false;
0050 if(!a_buffer.write(fIsUnsigned)) return false;
0051
0052 if(m_leaf_count) {
0053 if(!a_buffer.write_object(*m_leaf_count)) return false;
0054 } else {
0055 if(!a_buffer.write(kNullTag())) return false;
0056 }
0057
0058 if(!a_buffer.set_byte_count(c)) return false;
0059 return true;
0060 }
0061 public:
0062 virtual bool fill_buffer(buffer&) const = 0;
0063 public:
0064 base_leaf(std::ostream& a_out,const std::string& a_name,const std::string& a_title)
0065 :m_out(a_out)
0066 ,m_name(a_name)
0067 ,m_title(a_title)
0068
0069 ,m_length(0)
0070 ,m_length_type(0)
0071 ,m_leaf_count(0)
0072 ,m_is_range(false)
0073 {
0074 #ifdef TOOLS_MEM
0075 mem::increment(s_class().c_str());
0076 #endif
0077 }
0078 virtual ~base_leaf(){
0079 #ifdef TOOLS_MEM
0080 mem::decrement(s_class().c_str());
0081 #endif
0082 }
0083 protected:
0084 base_leaf(const base_leaf& a_from)
0085 :ibo(a_from)
0086 ,m_out(a_from.m_out)
0087 ,m_length(0)
0088 ,m_length_type(0)
0089 ,m_leaf_count(0)
0090 ,m_is_range(false)
0091 {}
0092 base_leaf& operator=(const base_leaf&){return *this;}
0093 public:
0094 const std::string& name() const {return m_name;}
0095 //const std::string& title() const {return m_title;}
0096 void set_title(const std::string& a_value) {m_title = a_value;}
0097 uint32 length() const {return m_length;}
0098 void set_length(uint32 a_value) {m_length = a_value;}
0099 void set_is_range(bool a_value) {m_is_range = a_value;}
0100 protected:
0101 std::ostream& m_out;
0102 protected: //Named
0103 std::string m_name;
0104 std::string m_title;
0105 uint32 m_length; // Number of fixed length elements
0106 uint32 m_length_type; // Number of bytes for this data type
0107 ibo* m_leaf_count;
0108 bool m_is_range;
0109 };
0110
0111 }}
0112
0113 #endif