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_leaf 00005 #define inlib_wroot_leaf 00006 00007 #include "base_leaf" 00008 00009 namespace inlib { 00010 namespace wroot { 00011 00012 inline const std::string& leaf_store_class(char) { 00013 static const std::string s_v("TLeafB"); 00014 return s_v; 00015 } 00016 inline const std::string& leaf_store_class(short) { 00017 static const std::string s_v("TLeafS"); 00018 return s_v; 00019 } 00020 inline const std::string& leaf_store_class(int) { 00021 static const std::string s_v("TLeafI"); 00022 return s_v; 00023 } 00024 inline const std::string& leaf_store_class(float) { 00025 static const std::string s_v("TLeafF"); 00026 return s_v; 00027 } 00028 inline const std::string& leaf_store_class(double) { 00029 static const std::string s_v("TLeafD"); 00030 return s_v; 00031 } 00032 00033 template <class T> 00034 class leaf : public base_leaf { 00035 public: //ibo 00036 virtual const std::string& store_cls() const { 00037 return leaf_store_class(T()); 00038 } 00039 virtual bool stream(buffer& a_buffer) const { 00040 unsigned int c; 00041 if(!a_buffer.write_version(1,c)) return false; 00042 if(!base_leaf::stream(a_buffer)) return false; 00043 if(!a_buffer.write(m_min)) return false; 00044 if(!a_buffer.write(m_max)) return false; 00045 if(!a_buffer.set_byte_count(c)) return false; 00046 return true; 00047 } 00048 public: //base_leaf 00049 virtual bool fill_basket(buffer& a_buffer) const { 00050 return a_buffer.write<T>(m_value); 00051 } 00052 public: 00053 leaf(std::ostream& a_out, 00054 wroot::branch& a_branch, 00055 const std::string& a_name, 00056 const std::string& a_title) 00057 : base_leaf(a_out,a_branch,a_name,a_title) 00058 ,m_min(T()),m_max(T()) 00059 ,m_value(T()) 00060 { 00061 m_length = 1; 00062 m_length_type = sizeof(T); 00063 } 00064 virtual ~leaf(){} 00065 protected: 00066 leaf(const leaf& a_from): base_leaf(a_from){} 00067 leaf& operator=(const leaf&){return *this;} 00068 public: 00069 void fill(const T& a_value) {m_value = a_value;} 00070 protected: 00071 T m_min; //Minimum value if leaf range is specified 00072 T m_max; //Maximum value if leaf range is specified 00073 T m_value; 00074 }; 00075 00076 }} 00077 00078 #endif