00001 /*************************************************************************** 00002 * Copyright (C) 2001 by Rick L. Vinyard, Jr. * 00003 * rvinyard@cs.nmsu.edu * 00004 * * 00005 * This file is part of the bit library. * 00006 * * 00007 * The bit 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 bit library is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * 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 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 00135 virtual const FieldType& type() const = 0; 00136 00138 virtual void set_type( const FieldType& ) = 0; 00139 00141 virtual Encoding encoding() const = 0; 00142 00144 virtual void set_encoding( Encoding en ) = 0; 00145 00146 virtual const std::string& xml() = 0; 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 ( exception::invalid_iterator ); 00188 00189 iterator operator++ ( int ) throw ( exception::invalid_iterator ); 00190 00191 iterator& operator--() throw ( exception::invalid_iterator ); 00192 00193 iterator operator-- ( int ) throw ( exception::invalid_iterator ); 00194 00195 FieldBase& operator*() throw ( exception::invalid_iterator ); 00196 00197 FieldBase* operator->() throw ( exception::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 ( exception::invalid_container_op, std::out_of_range ); 00211 00212 virtual FieldBase& operator[] ( size_t i ) throw ( exception::invalid_container_op, std::out_of_range ); 00213 00215 virtual size_t subfields(); 00216 00218 virtual FieldBase::pointer subfield ( const std::string& s ); 00219 00221 virtual FieldBase::pointer subfield ( size_t i ); 00222 00223 FieldBase* parent() { return m_parent; } 00224 00225 virtual Container container_type() = 0; 00226 00227 protected: 00228 friend class RecordStorage; 00229 friend class RecordVector; 00230 00231 FieldBase* m_parent; 00232 // FieldType m_type; 00233 std::string m_xml; 00234 00235 virtual FieldBase::pointer previous_field ( FieldBase::pointer current_field ) throw ( exception::invalid_container_op ); 00236 00237 virtual FieldBase::pointer next_field ( FieldBase::pointer current_field ) throw ( exception::invalid_container_op ); 00238 00239 }; 00240 00241 } 00242 00243 #endif