00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef BITDATA_H
00020 #define BITDATA_H
00021
00022 #include <string>
00023
00024 #include <sigc++/sigc++.h>
00025
00026 #include <bit/enums.h>
00027 #include <bit/pointer.h>
00028
00029 namespace bit {
00030
00031 typedef enum DataMode {
00032 COPY,
00033 MANAGED,
00034 UNMANAGED,
00035 } DataMode;
00036
00043 class Data
00044 {
00045 public:
00046
00048 Data( size_t s = 0 ) throw (std::bad_alloc);
00049
00051 Data( const void* d, size_t s, DataMode mode=COPY ) throw (std::bad_alloc);
00052
00054 Data( const Data& other );
00055
00057 ~Data();
00058
00060 uint8_t* data();
00061
00063 const uint8_t* data() const;
00064
00070 bool set_data( const void* newdata, size_t newsize, DataMode mode=COPY ) throw (std::bad_alloc);
00071
00073 size_t size() const;
00074
00084 bool resize( size_t s ) throw (std::bad_alloc);
00085
00091 Data clone() const;
00092
00093 operator bool();
00094
00095 operator bool() const;
00096
00098 operator uint8_t*();
00099
00101 operator const uint8_t*() const;
00102
00104 std::string hex_string( std::string separator = std::string() ) const;
00105
00107 void clear();
00108
00109 bool operator<( const Data& other ) const;
00110 bool operator<=( const Data& other ) const;
00111 bool operator==( const Data& other ) const;
00112 bool operator!=( const Data& other ) const;
00113 bool operator>=( const Data& other ) const;
00114 bool operator>( const Data& other ) const;
00115
00129 int compare( const Data& other ) const;
00130
00131 protected:
00132
00133 class Storage {
00134 public:
00135
00136 Storage(): data(NULL), size(0), manage_data(false) { }
00137
00138 ~Storage() {
00139 if ( data && manage_data ) {
00140 ::free( data );
00141 data = NULL;
00142 }
00143 }
00144
00145 typedef BitPointer<Storage> pointer;
00146
00148 uint8_t* data;
00149
00151 size_t size;
00152
00154 bool manage_data;
00155
00156 };
00157
00158 Storage::pointer m_storage;
00159
00160 };
00161
00162
00163 }
00164
00165 #endif