bit/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 <string>
00023 
00024 #include <bit/enums.h>
00025 #include <bit/pointer.h>
00026 #include <bit/except.h>
00027 #include <bit/fieldtype.h>
00028 
00029 namespace bit
00030   {
00031 
00032     class RecordBase;
00033     class RecordStorage;
00034 
00043   class FieldBase
00044     {
00045     public:
00046 
00048       typedef BitPointer<FieldBase> pointer;
00049 
00053       FieldBase();
00054 
00056       virtual ~FieldBase();
00057 
00059       virtual size_t length() const = 0;
00060 
00074       virtual size_t length(size_t units) const;
00075 
00077       virtual size_t length_units() const = 0;
00078 
00080       virtual int offset() const = 0;
00081 
00095       virtual int offset(size_t units) const;
00096 
00098       virtual size_t offset_units() const = 0;
00099 
00114       virtual int start(size_t units=BITS) const;
00115 
00123       virtual std::string name() const = 0;
00124 
00125       virtual std::string name(int depth) const;
00126 
00127       virtual size_t depth() const;
00128 
00132       virtual std::string description() const = 0;
00133 
00137       const FieldType& type();
00138 
00142       void set_type(const FieldType&);
00143 
00144       virtual const std::string& xml() = 0;
00145 
00154       virtual bool operator<(const FieldBase& other) const;
00155 
00164       virtual bool operator>(const FieldBase& other) const;
00165 
00166       virtual FieldBase::pointer clone() = 0;
00167 
00172     class iterator: public std::iterator<std::bidirectional_iterator_tag, FieldBase>
00173         {
00174         public:
00175           iterator(FieldBase* container=NULL, FieldBase::pointer object=FieldBase::pointer());
00176 
00177           ~iterator();
00178 
00179           iterator& operator=(const iterator& other);
00180 
00181           bool operator==(const iterator& other) const;
00182 
00183           bool operator!=(const iterator& other) const;
00184 
00185           iterator& operator++() throw (exception::invalid_iterator);
00186 
00187           iterator operator++(int) throw (exception::invalid_iterator);
00188 
00189           iterator& operator--() throw (exception::invalid_iterator);
00190 
00191           iterator operator--(int) throw (exception::invalid_iterator);
00192 
00193           FieldBase& operator*() throw (exception::invalid_iterator);
00194 
00195           FieldBase* operator->() throw (exception::invalid_iterator);
00196 
00197           FieldBase::pointer pointer();
00198 
00199         private:
00200           FieldBase* m_container;
00201           FieldBase::pointer m_object;
00202         };
00203 
00204       virtual iterator begin();
00205 
00206       virtual iterator end();
00207 
00208       virtual FieldBase& operator[](std::string s) throw (exception::invalid_container_op, std::out_of_range);
00209 
00210       virtual FieldBase& operator[](size_t i) throw (exception::invalid_container_op, std::out_of_range);
00211 
00212       virtual size_t fields();
00213 
00214       virtual FieldBase::pointer field(std::string s);
00215 
00216       virtual FieldBase::pointer field(size_t i);
00217 
00218       FieldBase* parent() { return m_parent; }
00219 
00220       virtual Container container_type() = 0;
00221 
00222     protected:
00223       friend class RecordStorage;
00224       friend class RecordVector;
00225 
00226       FieldBase* m_parent;
00227       FieldType m_type;
00228       std::string m_xml;
00229 
00230       virtual FieldBase::pointer previous_field(FieldBase::pointer current_field) throw (exception::invalid_container_op);
00231 
00232       virtual FieldBase::pointer next_field(FieldBase::pointer current_field) throw (exception::invalid_container_op);
00233 
00234     };
00235 
00236 }
00237 
00238 #endif

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