recordbuffer.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 BITRECORDBUFFER_H
00020 #define BITRECORDBUFFER_H
00021 
00022 #include <string>
00023 #include <queue>
00024 #include <set>
00025 
00026 #include <bit/buffer.h>
00027 #include <bit/record.h>
00028 #include <bit/fieldbuffer.h>
00029 #include <bit/data.h>
00030 #include <bit/error.h>
00031 
00032 namespace bit
00033   {
00034 
00041   class RecordBuffer : public Buffer
00042     {
00043     public:
00044       friend class FieldBuffer;
00045 
00046       RecordBuffer(size_t initial_size=0,
00047                    Growth growth=DYNAMIC,
00048                    size_t sizemax=0
00049                   );
00050 
00051       RecordBuffer(RecordBase::pointer record,
00052                    size_t initial_size=0,
00053                    Growth growth=DYNAMIC,
00054                    size_t sizemax=0
00055                   );
00056 
00057       RecordBuffer(void* external_data,
00058                    size_t data_octets,
00059                    DataMode datamode=COPY,
00060                    Growth growth=DYNAMIC,
00061                    size_t sizemax=0
00062                   );
00063 
00064       RecordBuffer(RecordBase::pointer record,
00065                    void* external_data,
00066                    size_t data_octets,
00067                    DataMode datamode=COPY,
00068                    Growth growth=DYNAMIC,
00069                    size_t sizemax=0
00070                   );
00071 
00072       virtual ~RecordBuffer();
00073 
00074       FieldBuffer operator[](size_t) throw (error::no_record);
00075       FieldBuffer operator[](std::string) throw (error::no_record);
00076       FieldBuffer operator[](FieldBase::iterator);
00077       FieldBuffer operator[](FieldBase::pointer);
00078 
00079       virtual void set_data(void* data, size_t size, DataMode datamode=COPY);
00080 
00081       void set_record(RecordBase::pointer record) throw ();
00082       void clear_record() throw ();
00083       RecordBase::pointer record();
00084 
00085       RecordBuffer& operator=(const RecordBuffer& other);
00086 
00087       sigc::signal<void, FieldBuffer> signal_field_changed();
00088 
00089       sigc::signal<void> signal_record_changed();
00090 
00091     protected:
00096       RecordBase::pointer m_record;
00097 
00106       void on_field_changed(FieldBase::pointer field);
00107 
00108       void on_record_changed();
00109 
00110     private:
00111 
00112       sigc::signal<void> m_signal_record_changed;
00113 
00125       sigc::signal<void, FieldBuffer> m_signal_field_changed;
00126 
00127       // Stores the fields that have changed and still need to have an emit signal
00128       //called. The fields are stored in the order they are changed.
00129       std::queue< FieldBase::pointer > m_signal_field_changed_queue;
00130 
00131       //Stores the set of fields that have changed and still need an emit signal.
00132       //The set is used to provide quick lookup O(lg n) rather than the O(n) necessary
00133       //in the queue.
00134       std::set< FieldBase::pointer >  m_signal_field_changed_set;
00135 
00136       bool  m_signal_field_changed_emitting;
00137     };
00138 
00139 }
00140 
00141 #endif

Generated on Thu Jul 6 14:38:08 2006 by  doxygen 1.4.6