src_other/tuplebase/ZUtil_TS.h

00001 /*  @(#) $Id: ZUtil_TS.h,v 1.4 2006/11/17 19:00:15 agreen Exp $ */
00002 
00003 /* ------------------------------------------------------------
00004 Copyright (c) 2006 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 __ZUtil_TS__
00026 #define __ZUtil_TS__
00027 #include "zconfig.h"
00028 
00029 #include "ZTypes.h"
00030 
00031 #include <map>
00032 #include <stdexcept>
00033 
00034 class ZTuple;
00035 class ZStreamR;
00036 class ZStreamRPos;
00037 class ZStreamWPos;
00038 class ZStrimU;
00039 class ZStrimW;
00040 
00041 namespace ZUtil_TS {
00042 
00043 class Ex_Base : public runtime_error
00044         {
00045 protected:
00046         Ex_Base(const char* what);
00047         Ex_Base(const std::string& what);
00048         };
00049 
00050 class Ex_MagicTextMissing : public Ex_Base
00051         {
00052 public:
00053         Ex_MagicTextMissing();
00054         };
00055 
00056 class Ex_IDInvalid : public Ex_Base
00057         {
00058 public:
00059         Ex_IDInvalid();
00060         };
00061 
00062 class Ex_IDOutOfSequence : public Ex_Base
00063         {
00064 public:
00065         Ex_IDOutOfSequence();
00066         };
00067 
00068 class Ex_IDOutOfBounds : public Ex_Base
00069         {
00070 public:
00071         Ex_IDOutOfBounds();
00072         };
00073 
00074 class Ex_IDDuplicate : public Ex_Base
00075         {
00076 public:
00077         Ex_IDDuplicate();
00078         };
00079 
00080 class Ex_OversizedStream : public Ex_Base
00081         {
00082 public:
00083         Ex_OversizedStream();
00084         };
00085 
00086 class Ex_MalformedText : public Ex_Base
00087         {
00088 public:
00089         Ex_MalformedText(const char* what);
00090         Ex_MalformedText(const std::string& what);
00091         };
00092 
00093 // =================================================================================================
00094 #pragma mark -
00095 #pragma mark * ZUtil_TS::Source
00096 
00097 class Source
00098         {
00099 public:
00100         virtual bool Get(uint64& oID, ZTuple& oTuple) = 0;
00101         };
00102 
00103 // =================================================================================================
00104 #pragma mark -
00105 #pragma mark * ZUtil_TS::Sink
00106 
00107 class Sink
00108         {
00109 public:
00110         virtual bool Set(uint64 iID, const ZTuple& iTuple) = 0;
00111         virtual void Clear() = 0;
00112         };
00113 
00114 // =================================================================================================
00115 #pragma mark -
00116 #pragma mark * ZUtil_TS::Source_Map
00117 
00118 class Source_Map : public Source
00119         {
00120 public:
00121         Source_Map(const std::map<uint64, ZTuple>& iMap);
00122 
00123 // From Source
00124         virtual bool Get(uint64& oID, ZTuple& oTuple);
00125 
00126 private:
00127         std::map<uint64, ZTuple>::const_iterator fIter;
00128         std::map<uint64, ZTuple>::const_iterator fEnd;
00129         };
00130 
00131 // =================================================================================================
00132 #pragma mark -
00133 #pragma mark * ZUtil_TS::Sink_Map
00134 
00135 class Sink_Map : public Sink
00136         {
00137 public:
00138         Sink_Map(std::map<uint64, ZTuple>& oMap);
00139 
00140 // From Sink
00141         virtual bool Set(uint64 iID, const ZTuple& iTuple);
00142         virtual void Clear();
00143 
00144 private:
00145         std::map<uint64, ZTuple>& fMap;
00146         };
00147 
00148 // =================================================================================================
00149 #pragma mark -
00150 #pragma mark * ZUtil_TS
00151 
00152 void sToStream(uint64 iNextUnusedID, Source& iSource, const ZStreamWPos& iStreamWPos);
00153 void sFromStream(Sink& iSink, uint64& oNextUnusedID, const ZStreamR& iStreamR);
00154 
00155 void sToStrim(uint64 iNextUnusedID, Source& iSource, const ZStrimW& iStrimW);
00156 void sFromStrim(Sink& iSink, uint64& oNextUnusedID, const ZStrimU& iStrimU);
00157 
00158 void sRead(const ZStreamRPos& iStreamRPos, uint64& oNextUnusedID, Sink& iSink);
00159 
00160 } // namespace ZUtil_TS
00161 
00162 #endif // __ZUtil_TS__

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