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
00039 #ifndef __MEMORY_STORE_H__
00040 #define __MEMORY_STORE_H__
00041
00042 #include "config.h"
00043 #include <map>
00044
00045 #include "../debug/Logger.h"
00046 #include "../thread/SpinLock.h"
00047 #include "../util/ScratchBuffer.h"
00048 #include "../util/StringUtils.h"
00049
00050 #include "DurableStore.h"
00051
00052 namespace oasys {
00053
00054
00055 class MemoryStore;
00056 class MemoryTable;
00057 class MemoryIterator;
00058 class StorageConfig;
00059
00064 class MemoryTable : public DurableTableImpl, public Logger {
00065 friend class MemoryStore;
00066 friend class MemoryIterator;
00067
00068 public:
00069 ~MemoryTable();
00070
00072 int get(const SerializableObject& key,
00073 SerializableObject* data);
00074
00075 int get(const SerializableObject& key,
00076 SerializableObject** data,
00077 TypeCollection::Allocator_t allocator);
00078
00079 int put(const SerializableObject& key,
00080 TypeCollection::TypeCode_t typecode,
00081 const SerializableObject* data,
00082 int flags);
00083
00084 int del(const SerializableObject& key);
00085
00086 size_t size() const;
00087
00088 DurableIterator* itr();
00090
00091 private:
00092 SpinLock lock_;
00093
00094 struct Item {
00095 ScratchBuffer<u_char*> key_;
00096 ScratchBuffer<u_char*> data_;
00097 TypeCollection::TypeCode_t typecode_;
00098 };
00099
00100 typedef StringMap<Item*> ItemMap;
00101 ItemMap* items_;
00102
00103 oasys::ScratchBuffer<u_char*> scratch_;
00104
00106 MemoryTable(const char* logpath, ItemMap* items,
00107 const std::string& name, bool multitype);
00108 };
00109
00116 class MemoryStore : public DurableStoreImpl {
00117 friend class MemoryTable;
00118
00119 public:
00120 MemoryStore(const char* logpath);
00121
00122
00123 MemoryStore& operator=(const MemoryStore&);
00124 MemoryStore(const MemoryStore&);
00125
00126 ~MemoryStore();
00127
00130 int init(const StorageConfig& cfg);
00131
00132 int get_table(DurableTableImpl** table,
00133 const std::string& name,
00134 int flags,
00135 PrototypeVector& prototypes);
00136
00137 int del_table(const std::string& name);
00138 int get_table_names(StringVector* names);
00140
00141 private:
00142 bool init_;
00143
00144 typedef StringMap<MemoryTable::ItemMap> TableMap;
00145 TableMap tables_;
00146 };
00147
00151 class MemoryIterator : public DurableIterator, public Logger {
00152 friend class MemoryTable;
00153
00154 private:
00159 MemoryIterator(const char* logpath, MemoryTable* t);
00160
00161 public:
00162 virtual ~MemoryIterator();
00163
00165 int next();
00166 int get_key(SerializableObject* key);
00168
00169 protected:
00170 MemoryTable* table_;
00171 bool first_;
00172 MemoryTable::ItemMap::iterator iter_;
00173 };
00174
00175 };
00176
00177 #endif //__MEMORY_STORE_H__