fieldbase.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 BITFIELDBASE_H
00020 #define BITFIELDBASE_H
00021 
00022 #include <bit/error.h>
00023 #include <bit/fieldtype.h>
00024 
00025 #include <boost/shared_ptr.hpp>
00026 #include <string>
00027 
00028 namespace bit
00029   {
00030 
00031     class RecordBase;
00032     class RecordStorage;
00033 
00037   typedef enum UNITS { BITS=1, OCTETS=8} UNITS;
00038 
00047   class FieldBase
00048     {
00049     public:
00050 
00052       typedef boost::shared_ptr<FieldBase> pointer;
00053 
00057       FieldBase();
00058 
00060       virtual ~FieldBase();
00061 
00063       virtual size_t length() const = 0;
00064 
00078       virtual size_t length(size_t units) const;
00079 
00081       virtual size_t length_units() const = 0;
00082 
00084       virtual int offset() const = 0;
00085 
00099       virtual int offset(size_t units) const;
00100 
00102       virtual size_t offset_units() const = 0;
00103 
00118       virtual int start(size_t units=BITS) const;
00119 
00127       virtual std::string name() const = 0;
00128 
00129       virtual std::string name(int depth) const;
00130 
00131       virtual size_t depth() const;
00132 
00136       virtual std::string description() const = 0;
00137 
00141       const FieldType& type();
00142 
00146       void set_type(const FieldType&);
00147       
00156       virtual bool operator<(const FieldBase& other) const;
00157 
00166       virtual bool operator>(const FieldBase& other) const;
00167 
00168       virtual FieldBase::pointer clone() = 0;
00169       
00174     class iterator: public std::iterator<std::bidirectional_iterator_tag, FieldBase>
00175         {
00176         public:
00177           iterator(FieldBase* container=NULL, FieldBase::pointer object=FieldBase::pointer());
00178 
00179           ~iterator();
00180 
00181           iterator& operator=(const iterator& other);
00182 
00183           bool operator==(const iterator& other) const;
00184 
00185           bool operator!=(const iterator& other) const;
00186 
00187           iterator& operator++() throw (error::invalid_iterator);
00188 
00189           iterator operator++(int) throw (error::invalid_iterator);
00190 
00191           iterator& operator--() throw (error::invalid_iterator);
00192 
00193           iterator operator--(int) throw (error::invalid_iterator);
00194 
00195           FieldBase& operator*() throw (error::invalid_iterator);
00196 
00197           FieldBase* operator->() throw (error::invalid_iterator);
00198 
00199           FieldBase::pointer pointer();
00200 
00201         private:
00202           FieldBase* m_container;
00203           FieldBase::pointer m_object;
00204         };
00205 
00206       virtual iterator begin();
00207 
00208       virtual iterator end();
00209 
00210       virtual FieldBase& operator[](std::string s) throw (error::invalid_container_op, std::out_of_range);
00211 
00212       virtual FieldBase& operator[](size_t i) throw (error::invalid_container_op, std::out_of_range);
00213 
00214       virtual size_t fields();
00215 
00216       virtual FieldBase::pointer field(std::string s);
00217 
00218       virtual FieldBase::pointer field(size_t i);
00219 
00220       FieldBase* parent() { return m_parent; }
00221       
00222     protected:
00223       friend class RecordStorage;
00224       friend class RecordVector;
00225 
00226       FieldBase* m_parent;
00227       FieldType m_type;
00228 
00229       virtual FieldBase::pointer previous_field(FieldBase::pointer current_field) throw (error::invalid_container_op);
00230 
00231       virtual FieldBase::pointer next_field(FieldBase::pointer current_field) throw (error::invalid_container_op);
00232 
00233     };
00234 
00235 }
00236 
00237 #endif

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