00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef _INTERNAL_KEY_DURABLE_TABLE_H_
00039 #define _INTERNAL_KEY_DURABLE_TABLE_H_
00040
00041 #include "../debug/Logger.h"
00042 #include "../debug/DebugUtils.h"
00043 #include "DurableStore.h"
00044 #include "StorageConfig.h"
00045
00046 namespace oasys {
00047
00071 template <typename _ShimType, typename _KeyType, typename _DataType>
00072 class InternalKeyDurableTable : public Logger {
00073 public:
00074 InternalKeyDurableTable(const char* classname,
00075 const char* logpath,
00076 const char* datatype,
00077 const char* table_name);
00078
00079 virtual ~InternalKeyDurableTable();
00080
00084 int do_init(const StorageConfig& cfg,
00085 DurableStore* store);
00086
00090 void close();
00091
00092 bool add(_DataType* data);
00093
00094 _DataType* get(_KeyType id);
00095
00096 bool update(_DataType* data);
00097
00098 bool del(_KeyType id);
00099
00103 class iterator {
00104 public:
00105 typedef class InternalKeyDurableTable<_ShimType,
00106 _KeyType,
00107 _DataType> table_t;
00108
00109 virtual ~iterator();
00110
00117 int next();
00118
00122 void begin() { next(); }
00123
00127 bool more() { return !done_; }
00128
00132 _KeyType cur_val() { return cur_val_.value(); }
00133
00134 private:
00135 friend class InternalKeyDurableTable<_ShimType,
00136 _KeyType,
00137 _DataType>;
00138
00139 iterator(table_t* table, DurableIterator* iter);
00140
00141 table_t* table_;
00142 DurableIterator* iter_;
00143 _ShimType cur_val_;
00144 bool done_;
00145 };
00146
00151 iterator* new_iterator()
00152 {
00153 return new iterator(this, table_->itr());
00154 }
00155
00156 protected:
00157 SingleTypeDurableTable<_DataType>* table_;
00158 const char* datatype_;
00159 const char* table_name_;
00160 };
00161
00162 #include "InternalKeyDurableTable.tcc"
00163
00164 }
00165
00166 #endif