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 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/except.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 size_t subfields(); 00066 00067 virtual FieldBase::pointer subfield(const std::string& s); 00068 00069 virtual FieldBase::pointer subfield(size_t i); 00070 00071 virtual void add_field(FieldBase::pointer field); 00072 00073 virtual void remove_field(FieldBase::pointer field); 00074 00075 virtual void remove_field(const std::string& name); 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 (exception::invalid_container_op); 00087 00088 virtual FieldBase::pointer next_field(FieldBase::pointer current_field) throw (exception::invalid_container_op); 00089 00090 protected: 00091 00092 FieldBase* m_record; 00093 00094 }; 00095 00096 } 00097 00098 #endif