inlib
1.2.0
|
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved. 00002 // See the file inlib.license for terms. 00003 00004 #ifndef my_space_my_obj 00005 #define my_space_my_obj 00006 00007 // prototype for a user class. 00008 00009 //inheritance : 00010 #include <inlib/rroot/iro> 00011 00012 #include <inlib/rroot/buffer> 00013 #include <inlib/scast> 00014 00015 namespace my_space { 00016 00017 class my_obj : public virtual inlib::rroot::iro { 00018 public: 00019 static const std::string& s_class() { 00020 static const std::string s_v("my_space::my_obj"); 00021 return s_v; 00022 } 00023 static const std::string& s_store_class() { 00024 //not needed to be the same than the upper. 00025 static const std::string s_v("TMyObj"); 00026 return s_v; 00027 } 00028 public: //iro 00029 virtual void* cast(const std::string& a_class) const { 00030 if(void* p = inlib::cmp_cast<my_obj>(this,a_class)) {return p;} 00031 else return 0; 00032 } 00033 virtual bool stream(inlib::rroot::buffer& a_buffer) { 00034 //the below code skips correctly the data in the file. 00035 inlib::uint32 startpos = a_buffer.length(); 00036 short v; 00037 unsigned int s,c; 00038 if(!a_buffer.read_version(v,s,c)) return false; 00039 a_buffer.set_offset(startpos+c+sizeof(unsigned int)); 00040 if(!a_buffer.check_byte_count(s,c,s_store_class())) return false; 00041 return true; 00042 } 00043 public: 00044 my_obj() { 00045 #ifdef INLIB_MEM 00046 inlib::mem::increment(s_class().c_str()); 00047 #endif 00048 } 00049 virtual ~my_obj(){ 00050 #ifdef INLIB_MEM 00051 inlib::mem::decrement(s_class().c_str()); 00052 #endif 00053 } 00054 public: 00055 my_obj(const my_obj& a_from): inlib::rroot::iro(a_from){ 00056 #ifdef INLIB_MEM 00057 inlib::mem::increment(s_class().c_str()); 00058 #endif 00059 } 00060 my_obj& operator=(const my_obj&){return *this;} 00061 }; 00062 00063 } 00064 00065 #endif