00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef CONEXUSDATA_H
00020 #define CONEXUSDATA_H
00021
00022 #include <stdexcept>
00023 #include <string>
00024
00025 #include <sigc++/sigc++.h>
00026
00027 #include <conexus/pointer.h>
00028
00029 #include <glibmm/timeval.h>
00030 #include <glibmm/thread.h>
00031
00032 namespace Conexus
00033 {
00034
00035 typedef enum DataMode {
00036 COPY,
00037 MANAGED,
00038 UNMANAGED,
00039 } DataMode;
00040
00047 class Data
00048 {
00049 public:
00050
00052 Data( size_t s = 0, unsigned priority = 0 ) throw (std::bad_alloc);
00053
00055 Data( const void* d, size_t s, unsigned priority = 0, DataMode mode=COPY ) throw (std::bad_alloc);
00056
00058 Data( const Data& other );
00059
00061 ~Data();
00062
00064 uint8_t* data();
00065
00067 const uint8_t* data() const;
00068
00074 bool set_data( const void* newdata, size_t newsize, DataMode mode=COPY ) throw (std::bad_alloc);
00075
00077 size_t size() const;
00078
00088 bool resize( size_t s ) throw (std::bad_alloc);
00089
00095 Data clone() const;
00096
00097 operator bool();
00098
00099 operator bool() const;
00100
00102 operator uint8_t*();
00103
00105 operator const uint8_t*() const;
00106
00108 std::string hex_string( std::string separator = std::string() ) const;
00109
00111 void clear();
00112
00114 const Glib::TimeVal& time() const;
00115
00117 void set_time( const Glib::TimeVal& );
00118
00120 void set_current_time();
00121
00123 unsigned priority() const;
00124
00126 void set_priority( unsigned p );
00127
00128 bool operator<( const Data& other ) const;
00129 bool operator<=( const Data& other ) const;
00130 bool operator==( const Data& other ) const;
00131 bool operator!=( const Data& other ) const;
00132 bool operator>=( const Data& other ) const;
00133 bool operator>( const Data& other ) const;
00134
00148 int compare( const Data& other ) const;
00149
00150 protected:
00151
00152 class Storage {
00153 public:
00154
00155 Storage(): data(NULL), size(0), manage_data(false), priority(0) { }
00156
00157 ~Storage() {
00158 if ( data && manage_data ) {
00159 ::free( data );
00160 data = NULL;
00161 }
00162 }
00163
00164 typedef ConexusPointer<Storage> pointer;
00165
00167 uint8_t* data;
00168
00170 size_t size;
00171
00173 bool manage_data;
00174
00176 unsigned int priority;
00177
00179 Glib::TimeVal time;
00180
00181 };
00182
00183 Storage::pointer m_storage;
00184
00185 };
00186
00187
00188 }
00189
00190 #endif