conexus logo

data.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2001 by Rick L. Vinyard, Jr.                            *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This file is part of the conexus library.                             *
00006  *                                                                         *
00007  *   The conexus library is free software; you can redistribute it and/or  *
00008  *   modify it under the terms of the GNU General Public License           *
00009  *   version 3 as published by the Free Software Foundation.               *
00010  *                                                                         *
00011  *   The conexus library is distributed in the hope that it will be        *
00012  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty   *
00013  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
00014  *   General Public License for more details.                              *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU General Public License     *
00017  *   along with this software. If not see <http://www.gnu.org/licenses/>.  *
00018  ***************************************************************************/
00019 #ifndef CONEXUSDATA_H
00020 #define CONEXUSDATA_H
00021 
00022 #include <cstdlib>
00023 #include <stdexcept>
00024 #include <string>
00025 
00026 #include <sigc++/sigc++.h>
00027 
00028 #include <conexus/pointer.h>
00029 #include <conexus/timeval.h>
00030 
00031 #include <glibmm/thread.h>
00032 
00033 namespace Conexus
00034 {
00035 
00036   typedef enum DataMode {
00037     COPY,
00038     MANAGED,
00039     UNMANAGED,
00040   } DataMode;
00041 
00048   class Data
00049   {
00050     public:
00051 
00053       Data( size_t s = 0, unsigned priority = 0 ) throw (std::bad_alloc);
00054 
00056       Data( const void* d, size_t s, unsigned priority = 0, DataMode mode=COPY ) throw (std::bad_alloc);
00057 
00059       Data( const Data& other );
00060 
00062       ~Data();
00063 
00065       uint8_t* data();
00066 
00068       const uint8_t* data() const;
00069 
00075       bool set_data( const void* newdata, size_t newsize, DataMode mode=COPY ) throw (std::bad_alloc);
00076 
00078       size_t size() const;
00079 
00089       bool resize( size_t s ) throw (std::bad_alloc);
00090 
00096       Data clone() const;
00097 
00098       operator bool();
00099 
00100       operator bool() const;
00101 
00103       operator uint8_t*();
00104 
00106       operator const uint8_t*() const;
00107 
00108       operator char*();
00109 
00110       operator const char*() const;
00111 
00112       operator void*();
00113 
00114       operator const void*() const;
00115 
00116       uint8_t& operator[](const ssize_t offset);
00117 
00118       const uint8_t& operator[](const ssize_t offset) const;
00119 
00121       std::string hex_string( std::string separator = std::string() ) const;
00122 
00124       void clear();
00125 
00127       const TimeVal& time() const;
00128 
00130       void set_time( const TimeVal& );
00131 
00133       void set_current_time();
00134 
00136       unsigned priority() const;
00137 
00139       void set_priority( unsigned p );
00140 
00141       bool operator<( const Data& other ) const;
00142       bool operator<=( const Data& other ) const;
00143       bool operator==( const Data& other ) const;
00144       bool operator!=( const Data& other ) const;
00145       bool operator>=( const Data& other ) const;
00146       bool operator>( const Data& other ) const;
00147 
00161       int compare( const Data& other ) const;
00162 
00167       bool append( const Data& other );
00168 
00169       Data operator+( const Data& other ) const;
00170 
00171       Data& operator+=( const Data& other );
00172 
00173     protected:
00174 
00175       class Storage {
00176         public:
00177 
00178           Storage(): data(NULL), size(0), manage_data(false), priority(0) { }
00179 
00180           ~Storage() {
00181             if ( data && manage_data ) {
00182                 ::free( data );
00183                 data = NULL;
00184             }
00185           }
00186 
00187           typedef ConexusPointer<Storage> pointer;
00188 
00190           uint8_t* data;
00191 
00193           size_t size;
00194 
00196           bool manage_data;
00197 
00199           unsigned int priority;
00200 
00202           TimeVal time;
00203 
00204       };
00205 
00206       Storage::pointer m_storage;
00207 
00208   };
00209 
00210 
00211 }
00212 
00213 #endif

Generated on Wed Jul 8 15:50:07 2009 for conexus by doxygen 1.5.8