src_other/tuplebase/ZTB.h

00001 /*  @(#) $Id: ZTB.h,v 1.15 2006/07/23 21:48:31 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 __ZTB__
00026 #define __ZTB__ 1
00027 #include "zconfig.h"
00028 
00029 #include "ZCompat_NonCopyable.h"
00030 #include "ZTBRep.h"
00031 #include "ZTBSpec.h"
00032 #include "ZTxn.h"
00033 
00034 #include <set>
00035 
00036 // =================================================================================================
00037 #pragma mark -
00038 #pragma mark * ZTB
00039 
00041 
00042 class ZTB
00043         {
00044     ZOOLIB_DEFINE_OPERATOR_BOOL_TYPES(ZTB, operator_bool_generator_type, operator_bool_type);
00045 public:
00046         ZTB() {}
00047         ZTB(ZRef<ZTBRep> iTBRep);
00048         ZTB(const ZTB& iOther);
00049         ZTB& operator=(const ZTB& iOther);
00050         ~ZTB();
00051 
00053         operator operator_bool_type() const
00054                 { return operator_bool_generator_type::translate(fTBRep && true); }
00055 
00057         uint64 AllocateID();
00058 
00060         uint64 Add(const ZTxn& iTxn, const ZTuple& iTuple);
00061 
00063         void Set(const ZTxn& iTxn, uint64 iID, const ZTuple& iTuple);
00064 
00066         void Erase(const ZTxn& iTxn, uint64 iID);
00067 
00069         ZTuple Get(const ZTxn& iTxn, uint64 iID);
00070 
00072         size_t Count(const ZTxn& iTxn, const ZTBQuery& iQuery);
00073 
00075         ZRef<ZTBRep> GetTBRep() const;
00076 
00077 protected:
00078         ZRef<ZTBRep> fTBRep;
00079         };
00080 
00081 // =================================================================================================
00082 #pragma mark -
00083 #pragma mark * ZTBTxn
00084 
00086 
00087 class ZTBTxn
00088         {
00089 private:
00090         ZTBTxn(); // Not implemented
00091         ZTBTxn& operator=(const ZTBTxn&); // Not implemented
00092 
00093 public:
00094         ZTBTxn(const ZTBTxn& iOther);
00095         ZTBTxn(const ZTxn& iTxn, ZTB iTB);
00096         ~ZTBTxn();
00097 
00099         uint64 AllocateID() const;
00100 
00102         uint64 Add(const ZTuple& iTuple) const;
00103 
00105         void Set(uint64 iID, const ZTuple& iTuple) const;
00106 
00108         void Erase(uint64 iID) const;
00109 
00111         ZTuple Get(uint64 iID) const;
00112 
00114         size_t Count(const ZTBQuery& iQuery) const;
00115 
00116         ZTBRepTransaction* GetTBRepTransaction() const;
00117 
00118 protected:
00119         mutable ZTBRepTransaction* fTBRepTransaction;
00120         };
00121 
00122 // =================================================================================================
00123 #pragma mark -
00124 #pragma mark * ZTBIter
00125 
00126 class ZTBIterRep;
00127 
00129 
00130 class ZTBIter
00131         {
00132     ZOOLIB_DEFINE_OPERATOR_BOOL_TYPES(ZTBIter, operator_bool_generator_type, operator_bool_type);
00133 public: //@{
00137         ZTBIter();
00138 
00140         ZTBIter(const ZTBIter& iOther);
00141 
00144         ZTBIter(const ZTxn& iTxn, ZTB iTB, const ZTBQuery& iQuery);
00145 
00148         ZTBIter(const ZTBTxn& iTBTxn, const ZTBQuery& iQuery);
00150         ~ZTBIter();
00151 
00153         ZTBIter& operator=(const ZTBIter& iOther);
00154 
00156         operator operator_bool_type() const;
00157 
00159         void Advance();
00160 
00162         size_t Advance(size_t iCount);
00163 
00165         size_t AdvanceAll();
00166 
00168         ZTuple Get() const;
00169 
00171         uint64 GetID() const;
00172 
00174         void Get(uint64* oID, ZTuple* oTuple) const;
00175 
00177         void Set(const ZTuple& iTuple);
00178 
00180         void Erase();
00181 
00183         size_t EraseAll();
00184 
00185 private:
00186         ZRef<ZTBIterRep> fRep;
00187         size_t fIndex;
00188         };
00189 
00190 #endif // __ZTB__

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