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 #ifndef __ZTS_RAM__
00026 #define __ZTS_RAM__
00027 #include "zconfig.h"
00028
00029 #include "ZTS.h"
00030
00031 #include <map>
00032 #include <set>
00033
00034 class ZTupleIndex;
00035 class ZTupleIndexFactory;
00036
00037
00038 #pragma mark -
00039 #pragma mark * ZTS_RAM
00040
00041 class ZTS_RAM : public ZTS
00042 {
00043 public:
00044 ZTS_RAM();
00045 ZTS_RAM(const std::vector<ZRef<ZTupleIndexFactory> >& iIndexFactories);
00046 ZTS_RAM(const std::vector<ZRef<ZTupleIndexFactory> >& iIndexFactories, uint64 iNextUnusedID, const std::map<uint64, ZTuple>& iTuples);
00047 ZTS_RAM(const std::vector<ZRef<ZTupleIndexFactory> >& iIndexFactories, uint64 iNextUnusedID, std::map<uint64, ZTuple>& ioTuples, bool iKnowWhatImDoing);
00048 virtual ~ZTS_RAM();
00049
00050
00051 virtual void AllocateIDs(size_t iCount, uint64& oBaseID, size_t& oCount);
00052 virtual void SetTuples(size_t iCount, const uint64* iIDs, const ZTuple* iTuples);
00053 virtual void GetTuples(size_t iCount, const uint64* iIDs, ZTuple* oTuples);
00054 virtual void Search(const ZTBSpec& iSpec, const std::set<uint64>& iSkipIDs, std::set<uint64>& ioIDs);
00055 virtual ZMutexBase& GetReadLock();
00056 virtual ZMutexBase& GetWriteLock();
00057
00058
00059 void AddIndex(ZRef<ZTupleIndexFactory> iIndexFactory);
00060 void AddIndices(const std::vector<ZRef<ZTupleIndexFactory> >& iIndexFactories);
00061
00062 bool GetDataIfChanged(uint64& oNextUnusedID, std::map<uint64, ZTuple>& oTuples);
00063 bool GetDataIfChanged(uint64& oNextUnusedID, vector<pair<uint64, ZTuple> >& oTuples);
00064 void GetData(uint64& oNextUnusedID, std::map<uint64, ZTuple>& oTuples);
00065
00066 private:
00067 ZRWLock fRWLock;
00068 ZMutex fMutex_ID;
00069 uint64 fNextUnusedID;
00070 std::map<uint64, ZTuple> fTuples;
00071 std::vector<ZTupleIndex*> fIndices;
00072 bool fChanged;
00073 };
00074
00075 #endif // __ZTS_RAM__