SourceForge.jp

dkutilEasySeries.h

説明を見る。
00001 
00002 
00003 #ifndef _dkutil_EasySeries__
00004 #define _dkutil_EasySeries__
00005 
00006 
00007 #include "dkutilDefined.h"
00008 #include "dKingyoMacro.h"
00009 #include "dkutilGetParam.h"
00010 #include "dkutilBuffer.h"
00011 #include "filesystem/dkutilFileSystem.h"
00012 
00013 namespace dkutil{
00014 
00015 class IEasySeries{
00016 public:
00017     typedef std::size_t size_type;
00018     IEasySeries(){}
00019     virtual ~IEasySeries(){};
00020     //virtual void Release() = 0;
00021     virtual bool isValid() = 0;
00022     //virtual void Reserve(size_type) = 0;
00023     //何かを貰う
00024     //virtual void *Get(int id=NULL) = 0;
00025     //virtual void Set(int id=NULL,void *ptr=NULL) = 0;
00026     //定義していない場合はedk_Not_Defined_Functionを返す
00027     //virtual int Task(int mes=NULL,void *adr=NULL) = 0;
00033     virtual bool Serialize(const char *filename)const = 0;
00039     virtual bool DeSerialize(const char *filename) = 0;
00040 
00041 };
00042 
00043 #define IEasySeriesTypedefDefine \
00044     typedef IEasySeries::size_type size_type
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 namespace private_{
00055 
00060 class serialize_offset_pusher : public offset_pusher<char>{
00061 public:
00062     typedef offset_pusher<char> BASE_TYPE;
00063     typedef offset_pusher<char>::size_type size_type;
00064     serialize_offset_pusher(const char *buf,size_type size) : 
00065         BASE_TYPE(buf,size){
00066         reset(buf,size);    
00067     }
00068 
00069     static size_type get_top_size(){return 1;}
00070     char *get()const{// return &(BASE_TYPE::get())[get_top_size()];}
00071         return BASE_TYPE::get();
00072     }
00073     char *now()const{   return get() + BASE_TYPE::size();}
00074     void reset(const char *buf,size_type size){
00075         BASE_TYPE::reset(buf,size);
00076         bool f=isLittleEndian();
00077         push_back((const char *)&f,get_top_size());
00078     }
00079     bool EndianCheck(){
00080         return ((char)isLittleEndian() == (char)(BASE_TYPE::get()[0]));
00081     }
00082 };
00083 
00084 /*
00085 class file_stream{
00086     enum{
00087         binary,
00088         text
00089 */
00090 
00091 }//end of private_ namespace
00092 
00093 
00094 class serializer : public private_::serialize_offset_pusher{
00095 private:
00096     scoped_buffer mbuf;
00097 public:
00098     typedef private_::serialize_offset_pusher BASE_TYPE;
00099     typedef BASE_TYPE::size_type size_type;
00100     serializer(size_type size=0) : BASE_TYPE(NULL,size){
00101         reset(size);    
00102     }
00103     virtual ~serializer(){}
00104     void clear(){
00105         mbuf.clear();
00106     }
00107     void reset(size_type size){
00108         //size + エンディアン格納 + NULL文字(がある場合)
00109         size_type asize = size + BASE_TYPE::get_top_size() + 1;
00110         if(size == 0) return;
00111         mbuf.reset(asize);
00112         BASE_TYPE::reset(mbuf.get(),asize);
00113     }
00115     void push_back(const char *data,size_type size){
00116         if(mbuf.isValid()==false){
00117             //くらいあがれ〜〜!!!!
00118             throw std::logic_error("メモリが確保されてません。resetを呼び出してください。");
00119         }
00120         BASE_TYPE::push_back(data,size);
00121     }
00123     const char *reference_back(size_type size){
00124         const char *ptr=BASE_TYPE::now();
00125         BASE_TYPE::OffsetPlus(size);
00126         return ptr;
00127     }
00129     int serialize(const char *filename)const{
00130         return SaveWin32APIFile(filename,mbuf.data(),mbuf.capacity());
00131     }
00133     int deserialize(const char *filename){
00134         clear();
00135         size_type size = filesystem::GetFileSizeMini(filename);
00136         reset(size);
00137         DWORD loaded_size;
00138         if(DKUTIL_FAILED(LoadWin32APIFile_Proto(filename,mbuf.data(),size,&loaded_size))){
00139             return edk_FAILED;
00140         }
00141         //NULL文字ぶち込む NULL文字も考慮してmbufは確保している!(はず・・・
00142         //mbuf.get()[loaded_size] = '\0';
00143         
00144         if(false==BASE_TYPE::EndianCheck()){
00145             return edk_FAILED;//変なもん読み込むなぁ!!
00146         }
00147         return edk_SUCCEEDED;
00148     }
00149 
00150 };
00151 /*
00152 template<class T>
00153 class IEasySerializ{
00154 private:
00155     std::size_t mfsize;
00156 protected:
00157     void SetSize(std::size_t size){ mfsize = size;}
00158 public:
00159     IEasySerialize(std::size_t size) : mfsize(size){}
00160     std::size_t GetSize(){return mfsize;}
00161     virtual T GetData() = 0;
00162 };      
00163 */
00164 
00165 }//end of dkutil namespace
00166 
00167 
00168 
00169 #endif//end of include once

dkutil 1.02リリース前 d金魚専用マニュアルバージョンに対してSun Dec 28 21:23:07 2003に生成されました。 doxygen 1.3.5