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 __ZNode__
00026 #define __ZNode__ 1
00027 #include "zconfig.h"
00028
00029 #include "ZCompat_NonCopyable.h"
00030 #include "ZRefCount.h"
00031 #include "ZStreamer.h"
00032 #include "ZTrail.h"
00033 #include "ZTuple.h"
00034
00035 #include <set>
00036 #include <string>
00037
00038 class ZNode;
00039 class ZNodeRep;
00040 class ZNodeIterRep;
00041
00042
00043 #pragma mark -
00044 #pragma mark * ZNode
00045
00046 class ZNode
00047 {
00048 ZOOLIB_DEFINE_OPERATOR_BOOL_TYPES(ZNode,
00049 operator_bool_generator_type, operator_bool_type);
00050
00051 public:
00052 enum Error
00053 {
00054 errorNone,
00055 errorGeneric,
00056 errorDoesntExist,
00057 errorAlreadyExists,
00058 errorInvalidNode,
00059 errorIllegalName,
00060 errorNoPermission,
00061 errorWrongTypeForOperation,
00062 errorReadPastEOF,
00063 errorInsufficientSpace
00064 };
00065
00066 ZNode();
00067 ZNode(const ZNode& iOther);
00068 ZNode(const ZRef<ZNodeRep>& iRep);
00069 ZNode(const ZRef<ZNodeRep>& iNodeRep, const std::string& iComp);
00070 ZNode(ZNodeRep* iNodeRep);
00071
00072 template <class I>
00073 ZNode(const ZRef<ZNodeRep>& iNodeRep, const I& iBegin, const I& iEnd)
00074 : fNodeRep(iNodeRep),
00075 fComps(iBegin, iEnd)
00076 {}
00077
00078 template <class I>
00079 ZNode(const ZRef<ZNodeRep>& iNodeRep, const I& iBegin, const I& iEnd,
00080 const std::string& iAdditional)
00081 : fNodeRep(iNodeRep),
00082 fComps(iBegin, iEnd)
00083 { fComps.push_back(iAdditional); }
00084
00085 ~ZNode();
00086
00087 ZNode& operator=(const ZNode& iOther);
00088 ZNode& operator=(const ZRef<ZNodeRep>& iRep);
00089
00090 bool operator==(const ZNode& iOther) const;
00091 bool operator<(const ZNode& iOther) const;
00092
00093 operator operator_bool_type() const;
00094
00095 bool GetProp(const std::string& iPropName, ZTupleValue& oTV, Error* oError = 0) const;
00096
00097 bool CanHaveChildren(Error* oError = 0) const;
00098
00099 std::string Name(Error* oError = 0) const;
00100 ZNode Ancestor(size_t iCount, Error* oError = 0) const;
00101 ZNode Parent(Error* oError = 0) const;
00102 ZNode Child(const std::string& iName, Error* oError = 0) const;
00103 ZNode Sibling(const std::string& iName, Error* oError = 0) const;
00104 ZNode Trail(const ZTrail& iTrail, Error* oError = 0) const;
00105 ZNode Descendant(const std::string* iComps, size_t iCount, Error* oError = 0) const;
00106
00107 ZTrail TrailTo(const ZNode& iDest, Error* oError = 0) const;
00108 ZTrail TrailFrom(const ZNode& iSource, Error* oError = 0) const;
00109 ZTrail TrailFromRoot(Error* oError = 0) const;
00110
00111 bool Exists(Error* oError = 0) const;
00112
00113 ZNode CreateDir(Error* oError = 0) const;
00114
00115 ZNode MoveTo(const ZNode& iDest, Error* oError = 0) const;
00116
00117
00118 bool Delete(Error* oError = 0) const;
00119
00120 ZRef<ZStreamerR> OpenR(bool iPreventWriters = false, Error* oError = 0) const;
00121 ZRef<ZStreamerRPos> OpenRPos(bool iPreventWriters = false, Error* oError = 0) const;
00122 ZRef<ZStreamerW> OpenW(bool iPreventWriters = true, Error* oError = 0) const;
00123 ZRef<ZStreamerWPos> OpenWPos(bool iPreventWriters = true, Error* oError = 0) const;
00124 ZRef<ZStreamerRWPos> OpenRWPos(bool iPreventWriters = true, Error* oError = 0) const;
00125
00126 ZRef<ZStreamerWPos> CreateWPos(bool iOpenExisting,
00127 bool iPreventWriters = true, Error* oError = 0) const;
00128
00129 ZRef<ZStreamerRWPos> CreateRWPos(bool iOpenExisting,
00130 bool iPreventWriters = true, Error* oError = 0) const;
00131
00132 ZRef<ZNodeRep> GetNodeRep() const;
00133
00134 protected:
00135 ZRef<ZNodeRep> pPhysicalNodeRep() const;
00136
00137 ZRef<ZNodeRep> fNodeRep;
00138 std::vector<std::string> fComps;
00139 };
00140
00141
00142 #pragma mark -
00143 #pragma mark * ZNodeIter
00144
00145 class ZNodeIter
00146 {
00147 ZOOLIB_DEFINE_OPERATOR_BOOL_TYPES(ZNodeIter,
00148 operator_bool_generator_type, operator_bool_type);
00149 public:
00150 ZNodeIter();
00151 ZNodeIter(const ZNodeIter& iOther);
00152 ZNodeIter(const ZNode& iAsset);
00153 ~ZNodeIter();
00154 ZNodeIter& operator=(const ZNodeIter& iOther);
00155
00156 operator operator_bool_type() const;
00157 ZNodeIter& Advance();
00158 ZNode Current() const;
00159 std::string CurrentName() const;
00160
00161 private:
00162 ZRef<ZNodeIterRep> fRep;
00163 };
00164
00165
00166 #pragma mark -
00167 #pragma mark * ZNodeTreeIter
00168
00170
00171 class ZNodeTreeIter
00172 {
00173 ZOOLIB_DEFINE_OPERATOR_BOOL_TYPES(ZNodeTreeIter,
00174 operator_bool_generator_type, operator_bool_type);
00175 public:
00176 ZNodeTreeIter();
00177 ZNodeTreeIter(const ZNodeTreeIter& iOther);
00178 ZNodeTreeIter(const ZNode& iRoot);
00179 ~ZNodeTreeIter();
00180 ZNodeTreeIter& operator=(const ZNodeTreeIter& iOther);
00181
00182 operator operator_bool_type() const;
00183 ZNodeTreeIter& Advance();
00184 ZNode Current() const;
00185 std::string CurrentName() const;
00186
00187 private:
00188 ZNode fCurrent;
00189 std::vector<ZNodeIter> fStack;
00190 };
00191
00192
00193 #pragma mark -
00194 #pragma mark * ZNodeRep
00195
00196 class ZNodeRep : public ZRefCountedWithFinalization
00197 {
00198 protected:
00199 ZNodeRep();
00200
00201 public:
00202 typedef ZNode::Error Error;
00203
00204 virtual ~ZNodeRep();
00205
00206 virtual ZRef<ZNodeIterRep> CreateIterRep();
00207
00208 virtual bool GetProp(const std::string& iPropName, ZTupleValue& oTV, Error* oError);
00209 virtual bool CanHaveChildren(Error* oError);
00210
00211 virtual std::string GetName(Error* oError) = 0;
00212 virtual ZTrail TrailTo(ZRef<ZNodeRep> iDest, Error* oError) = 0;
00213
00214 virtual ZRef<ZNodeRep> GetAncestor(size_t iCount, Error* oError) = 0;
00215 virtual ZRef<ZNodeRep> GetDescendant(const std::string* iComps,
00216 size_t iCount, Error* oError) = 0;
00217
00218 virtual bool Exists(Error* oError) = 0;
00219
00220 virtual ZRef<ZNodeRep> CreateDir(Error* oError);
00221
00222 virtual ZRef<ZNodeRep> MoveTo(ZRef<ZNodeRep> iDest, Error* oError);
00223
00224
00225 virtual bool Delete(Error* oError);
00226
00227 virtual ZRef<ZStreamerR> OpenR(bool iPreventWriters, Error* oError);
00228 virtual ZRef<ZStreamerRPos> OpenRPos(bool iPreventWriters, Error* oError);
00229 virtual ZRef<ZStreamerW> OpenW(bool iPreventWriters, Error* oError);
00230 virtual ZRef<ZStreamerWPos> OpenWPos(bool iPreventWriters, Error* oError);
00231 virtual ZRef<ZStreamerRWPos> OpenRWPos(bool iPreventWriters, Error* oError);
00232
00233 virtual ZRef<ZStreamerWPos> CreateWPos(bool iOpenExisting,
00234 bool iPreventWriters, Error* oError);
00235
00236 virtual ZRef<ZStreamerRWPos> CreateRWPos(bool iOpenExisting,
00237 bool iPreventWriters, Error* oError);
00238 };
00239
00240
00241 #pragma mark -
00242 #pragma mark * ZNodeIterRep
00243
00244 class ZNodeIterRep : public ZRefCountedWithFinalization
00245 {
00246 protected:
00247 ZNodeIterRep();
00248
00249 public:
00250 virtual ~ZNodeIterRep();
00251
00252 virtual bool HasValue() = 0;
00253 virtual void Advance() = 0;
00254 virtual ZRef<ZNodeRep> Current() = 0;
00255 virtual std::string CurrentName() = 0;
00256
00257 virtual ZRef<ZNodeIterRep> Clone() = 0;
00258 };
00259
00260
00261 #pragma mark -
00262 #pragma mark * ZNodeIterRep_Std
00263
00264 class ZNodeIterRep_Std : public ZNodeIterRep
00265 {
00266 public:
00267 class RealRep;
00268
00269 ZNodeIterRep_Std(ZRef<RealRep> iRealRep, size_t iIndex);
00270 virtual ~ZNodeIterRep_Std();
00271
00272
00273 virtual bool HasValue();
00274 virtual void Advance();
00275 virtual ZRef<ZNodeRep> Current();
00276 virtual std::string CurrentName();
00277
00278 virtual ZRef<ZNodeIterRep> Clone();
00279
00280 private:
00281 ZRef<RealRep> fRealRep;
00282 size_t fIndex;
00283 };
00284
00285
00286 #pragma mark -
00287 #pragma mark * ZNodeIterRep_Std::RealRep
00288
00289 class ZNodeIterRep_Std::RealRep : public ZRefCountedWithFinalization
00290 {
00291 protected:
00292 RealRep() {};
00293
00294 public:
00295 virtual bool HasValue(size_t iIndex) = 0;
00296 virtual ZRef<ZNodeRep> GetNodeRep(size_t iIndex) = 0;
00297 virtual std::string GetName(size_t iIndex) = 0;
00298 };
00299
00300 #endif // __ZNode__