InternalKeyDurableTable.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 #ifndef _INTERNAL_KEY_DURABLE_TABLE_H_
00018 #define _INTERNAL_KEY_DURABLE_TABLE_H_
00019 
00020 #include "../debug/Logger.h"
00021 #include "../debug/DebugUtils.h"
00022 #include "DurableStore.h"
00023 #include "StorageConfig.h"
00024 
00025 namespace oasys {
00026 
00050 template <typename _ShimType, typename _KeyType, typename _DataType>
00051 class InternalKeyDurableTable : public Logger {
00052 public:
00053     InternalKeyDurableTable(const char* classname,
00054                             const char* logpath,
00055                             const char* datatype,
00056                             const char* table_name);
00057 
00058     virtual ~InternalKeyDurableTable();
00059     
00063     int do_init(const StorageConfig& cfg,
00064                 DurableStore*        store);
00065 
00069     void close();
00070     
00071     bool add(_DataType* data);
00072     
00073     _DataType* get(_KeyType id);
00074     
00075     bool update(_DataType* data);
00076 
00077     bool del(_KeyType id);
00078 
00082     class iterator {
00083     public:
00084         typedef class InternalKeyDurableTable<_ShimType,
00085                                               _KeyType,
00086                                               _DataType> table_t;
00087 
00088         virtual ~iterator();
00089 
00096         int next();
00097 
00101         void begin() { next(); }
00102 
00106         bool more() { return !done_; }
00107 
00111         _KeyType cur_val() { return cur_val_.value(); }
00112 
00113     private:
00114         friend class InternalKeyDurableTable<_ShimType,
00115                                              _KeyType,
00116                                              _DataType>;
00117 
00118         iterator(table_t* table, DurableIterator* iter);
00119 
00120         table_t*  table_;       
00121         DurableIterator* iter_; 
00122         _ShimType cur_val_;     
00123         bool      done_;        
00124     };
00125     
00130     iterator* new_iterator()
00131     {
00132         return new iterator(this, table_->itr());
00133     }
00134 
00135 protected:
00136     SingleTypeDurableTable<_DataType>* table_;
00137     const char* datatype_;
00138     const char* table_name_;
00139 };
00140 
00141 #include "InternalKeyDurableTable.tcc"
00142 
00143 } // namespace oasys
00144 
00145 #endif /* _INTERNAL_KEY_DURABLE_TABLE_H_ */

Generated on Sat Sep 8 08:43:28 2007 for DTN Reference Implementation by  doxygen 1.5.3