inlib
1.2.0
|
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved. 00002 // See the file inlib.license for terms. 00003 00004 #ifndef inlib_wroot_base_leaf 00005 #define inlib_wroot_base_leaf 00006 00007 #ifdef INLIB_MEM 00008 #include "../mem" 00009 #endif 00010 00011 #include "named" 00012 00013 namespace inlib { 00014 namespace wroot { 00015 class branch; 00016 }} 00017 00018 namespace inlib { 00019 namespace wroot { 00020 00021 class base_leaf : public virtual ibo { 00022 static unsigned int kNullTag() {return 0;} 00023 #ifdef INLIB_MEM 00024 public: 00025 static const std::string& s_class() { 00026 static const std::string s_v("inlib::wroot::base_leaf"); 00027 return s_v; 00028 } 00029 #endif 00030 public: //ibo 00031 virtual bool stream(buffer& a_buffer) const { 00032 unsigned int c; 00033 if(!a_buffer.write_version(2,c)) return false; 00034 if(!Named_stream(a_buffer,m_name,m_title)) return false; 00035 if(!a_buffer.write(m_length)) return false; 00036 if(!a_buffer.write(m_length_type)) return false; 00037 uint32 fOffset = 0; 00038 if(!a_buffer.write(fOffset)) return false; 00039 bool fIsRange = false; 00040 if(!a_buffer.write(fIsRange)) return false; 00041 bool fIsUnsigned = false; 00042 if(!a_buffer.write(fIsUnsigned)) return false; 00043 00044 //if(!a_buffer.write_object(m_leaf_count)) return false; 00045 if(!a_buffer.write(kNullTag())) return false; 00046 00047 if(!a_buffer.set_byte_count(c)) return false; 00048 return true; 00049 } 00050 public: 00051 virtual bool fill_basket(buffer&) const = 0; 00052 public: 00053 base_leaf(std::ostream& a_out, 00054 wroot::branch& a_branch, 00055 const std::string& a_name, 00056 const std::string& a_title) 00057 :m_out(a_out) 00058 ,m_branch(a_branch) 00059 ,m_name(a_name) 00060 ,m_title(a_title) 00061 00062 ,m_length(0) 00063 ,m_length_type(0) 00064 { 00065 #ifdef INLIB_MEM 00066 mem::increment(s_class().c_str()); 00067 #endif 00068 } 00069 virtual ~base_leaf(){ 00070 #ifdef INLIB_MEM 00071 mem::decrement(s_class().c_str()); 00072 #endif 00073 } 00074 protected: 00075 base_leaf(const base_leaf& a_from) 00076 : ibo(a_from) 00077 ,m_out(a_from.m_out) 00078 ,m_branch(a_from.m_branch) 00079 {} 00080 base_leaf& operator=(const base_leaf&){return *this;} 00081 public: 00082 wroot::branch& branch() {return m_branch;} 00083 const std::string& name() const {return m_name;} 00084 //const std::string& title() const {return m_title;} 00085 protected: 00086 std::ostream& m_out; 00087 wroot::branch& m_branch; 00088 protected: //Named 00089 std::string m_name; 00090 std::string m_title; 00091 uint32 m_length; // Number of fixed length elements 00092 uint32 m_length_type; // Number of bytes for this data type 00093 }; 00094 00095 }} 00096 00097 #endif