00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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 }
00144
00145 #endif