00001 /* 00002 * Copyright (C) Sergey P. Derevyago, 2008-2009. 00003 * 00004 * Permission to copy, use, modify, sell and distribute this software is granted 00005 * provided this copyright notice appears in all copies. 00006 * This software is provided "as is" without express or implied warranty, and 00007 * with no claim as to its suitability for any purpose. 00008 * 00009 */ 00010 00017 #ifndef __DERS__DATA_IO_HPP__ 00018 #define __DERS__DATA_IO_HPP__ 00019 00020 #include <ders/config.hpp> 00021 #include <ders/cycl_buf.hpp> 00022 #include <ders/text.hpp> 00023 00024 namespace ders { // ::ders 00025 00026 class object_io; 00027 00031 class data_in : virtual public destroyable { 00032 public: 00033 virtual bool read_bool(bool& val)=0; 00034 00035 virtual bool read_char(char& val)=0; 00036 virtual bool read_schar(signed char& val)=0; 00037 virtual bool read_uchar(unsigned char& val)=0; 00038 virtual bool read_wchar(wchar_t& val)=0; 00039 00040 virtual bool read_short(short& val)=0; 00041 virtual bool read_ushort(unsigned short& val)=0; 00042 00043 virtual bool read_int(int& val)=0; 00044 virtual bool read_uint(unsigned int& val)=0; 00045 00046 virtual bool read_long(long& val)=0; 00047 virtual bool read_ulong(unsigned long& val)=0; 00048 00049 virtual bool read_float(float& val)=0; 00050 virtual bool read_double(double& val)=0; 00051 virtual bool read_ldouble(long double& val)=0; 00052 00053 virtual bool read_ptr(void*& val)=0; 00054 template<class T> bool read_ptr(T*& val); 00055 00056 virtual bool read_text(sh_text& val)=0; 00057 }; 00058 00062 class data_out : virtual public destroyable { 00063 public: 00064 virtual void write_bool(bool val)=0; 00065 00066 virtual void write_char(char val)=0; 00067 virtual void write_schar(signed char val)=0; 00068 virtual void write_uchar(unsigned char val)=0; 00069 virtual void write_wchar(wchar_t val)=0; 00070 00071 virtual void write_short(short val)=0; 00072 virtual void write_ushort(unsigned short val)=0; 00073 00074 virtual void write_int(int val)=0; 00075 virtual void write_uint(unsigned int val)=0; 00076 00077 virtual void write_long(long val)=0; 00078 virtual void write_ulong(unsigned long val)=0; 00079 00080 virtual void write_float(float val)=0; 00081 virtual void write_double(double val)=0; 00082 virtual void write_ldouble(long double val)=0; 00083 00084 virtual void write_ptr(void* val)=0; 00085 00086 virtual void write_text(const ch_rng& val)=0; 00087 }; 00088 00093 class data_io : public data_in, public data_out { 00094 }; 00095 00096 typedef sh_ptr<data_io> sh_data_io; 00097 00103 sh_data_io new_data_io(sh_cycl_buf cb); 00104 00105 template<class T> 00106 inline bool data_in::read_ptr(T*& val) 00107 { 00108 void* ptr; 00109 bool ret=read_ptr(ptr); 00110 val=static_cast<T*>(ptr); 00111 00112 return ret; 00113 } 00114 00115 } // namespace ::ders 00116 00117 #endif // __DERS__DATA_IO_HPP__ 00118