bit/buffer.h

00001 /***************************************************************************
00002  *   Copyright (C) 2001 by Rick L. Vinyard, Jr.                            *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation version 2.1.                *
00008  *                                                                         *
00009  *   This program is distributed in the hope that it will be useful,       *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012  *   GNU General Public License for more details.                          *
00013  *                                                                         *
00014  *   You should have received a copy of the GNU Lesser General Public      *
00015  *   License along with this library; if not, write to the                 *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA              *
00018  ***************************************************************************/
00019 #ifndef BITBUFFER_H
00020 #define BITBUFFER_H
00021 
00022 #include <bit/enums.h>
00023 #include <bit/data.h>
00024 
00030 namespace bit
00031   {
00032 
00046   class Buffer: public Data
00047     {
00048     protected:
00049 
00054       Buffer(size_t initial_size=0, size_t sizemax=0);
00055 
00059       Buffer(void* data, size_t size, size_t sizemax=0, DataMode mode=COPY);
00060 
00061     public:
00062 
00063       typedef BitPointer<Buffer> pointer;
00064 
00065       static pointer create(size_t initial_size=0, size_t sizemax=0);
00066 
00067       static pointer create(void* data, size_t size, size_t sizemax=0, DataMode mode=COPY);
00068 
00069       virtual ~Buffer();
00070 
00097       bool unpack(void* mem, size_t mem_octets, Location mem_loc, size_t buf_offset_bits, size_t extract_bits);
00098 
00099       Data unpack( size_t buf_offset_bits, size_t extract_bits, Location mem_loc=END );
00100 
00101       template <typename T>
00102       bool unpack(T& val, Location mem_loc, size_t buf_offset_bits, size_t extract_bits)
00103       {
00104         return unpack(&val, sizeof(T), mem_loc, buf_offset_bits, extract_bits);
00105       }
00106 
00140       bool pack(const void* mem, size_t mem_octets, Location mem_loc, size_t buf_offset, size_t buf_tgtsize, size_t n);
00141 
00142       bool pack( Data d, size_t buf_offset, size_t buf_tgtsize, size_t n, Location mem_loc=END );
00143 
00144       template <typename T>
00145       bool pack(const T& val, Location mem_loc, size_t offset, size_t destsize, size_t n)
00146       {
00147         bool b;
00148         b = pack(&val, sizeof(T), mem_loc, offset, destsize, n);
00149         return b;
00150       }
00151 
00152       bool clear_bits(size_t offset, size_t bits)
00153       {
00154         return clear_bits(offset, bits, false);
00155       }
00156 
00158       size_t size_max();
00159 
00165       void set_size_max(size_t sizemax);
00166 
00167       virtual void set_data( const void* newdata, size_t newsize, DataMode mode=COPY ) throw (std::bad_alloc);
00168 
00169       virtual bool resize( size_t s ) throw (std::bad_alloc);
00170 
00172       sigc::signal<void> signal_changed()
00173       {
00174         return m_signal_changed;
00175       }
00176 
00177     protected:
00178       size_t m_size_max;
00179 
00183       bool clear_bits(size_t offset, size_t bits, bool suppress);
00184 
00185       virtual void on_data_changed();
00186 
00187     private:
00188       sigc::signal<void> m_signal_changed;
00189 
00190       bool m_signal_changed_need_reemit;
00191       bool m_signal_changed_emitting;
00192 
00193 
00194     };
00195 
00196 }
00197 
00198 #endif

Generated on Tue Mar 13 20:00:01 2007 by  doxygen 1.5.1