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 BITRECORDSTORAGE_H 00020 #define BITRECORDSTORAGE_H 00021 00022 #include <set> 00023 #include <map> 00024 00025 #include <bit/fieldbase.h> 00026 #include <bit/recordbase.h> 00027 #include <bit/error.h> 00028 00029 namespace bit { 00030 00038 class RecordStorage{ 00039 public: 00040 RecordStorage(FieldBase& record); 00041 00042 virtual ~RecordStorage(); 00043 00044 struct fieldbase_pointer_compare { 00045 bool operator() (FieldBase::pointer p1, FieldBase::pointer p2) const { 00046 int p1_offset, p2_offset; 00047 p1_offset = p1->offset(BITS); 00048 p2_offset = p2->offset(BITS); 00049 if (p1_offset < p2_offset) 00050 return true; 00051 else if (p1_offset == p2_offset) 00052 return ( p1->length(BITS) < p2->length(BITS) ); 00053 else 00054 return false; 00055 } 00056 }; 00057 00058 virtual FieldBase::iterator begin(); 00059 00060 virtual FieldBase::iterator end(); 00061 00063 RecordStorage& operator=(const RecordStorage& other); 00064 00065 virtual FieldBase::pointer field(std::string s); 00066 00067 virtual FieldBase::pointer field(size_t i); 00068 00069 virtual void add_field(FieldBase::pointer field); 00070 00071 virtual void remove_field(FieldBase::pointer field); 00072 00073 virtual void remove_field(const std::string& name); 00074 00075 virtual size_t fields(); 00076 00078 typedef std::set<FieldBase::pointer, fieldbase_pointer_compare> Fields; 00079 00081 typedef std::map<std::string, Fields::iterator> FieldNameMap; 00082 00083 Fields field_set; 00084 FieldNameMap field_name_map; 00085 00086 virtual FieldBase::pointer previous_field(FieldBase::pointer current_field) throw (error::invalid_container_op); 00087 00088 virtual FieldBase::pointer next_field(FieldBase::pointer current_field) throw (error::invalid_container_op); 00089 00090 protected: 00091 00092 FieldBase* m_record; 00093 }; 00094 00095 } 00096 00097 #endif