src_other/tuplebase/ZTS_RAM.h

00001 /*  @(#) $Id: ZTS_RAM.h,v 1.14 2006/10/13 20:10:13 agreen Exp $ */
00002 
00003 /* ------------------------------------------------------------
00004 Copyright (c) 2003 Andrew Green and Learning in Motion, Inc.
00005 http://www.zoolib.org
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a copy
00008 of this software and associated documentation files (the "Software"), to deal
00009 in the Software without restriction, including without limitation the rights
00010 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011 copies of the Software, and to permit persons to whom the Software is
00012 furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00020 COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 // From ZTS
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 // Our protocol
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__

Generated on Thu Jul 26 11:21:59 2007 for ZooLib by  doxygen 1.4.7