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
00026
00027
00028
00029
00030
00036 #ifndef OW_HDBNODE_HPP_INCLUDE_GUARD_
00037 #define OW_HDBNODE_HPP_INCLUDE_GUARD_
00038 #include "OW_config.h"
00039 #include "OW_HDBCommon.hpp"
00040 #include "OW_String.hpp"
00041 #include "OW_IntrusiveReference.hpp"
00042 #include "OW_IntrusiveCountableBase.hpp"
00043
00044 namespace OW_NAMESPACE
00045 {
00046
00047 class HDBHandle;
00048 class HDB;
00050 class OW_HDB_API HDBNode
00051 {
00052 private:
00053 struct HDBNodeData : public IntrusiveCountableBase
00054 {
00055 HDBNodeData();
00056 HDBNodeData(const HDBNodeData& x);
00057 ~HDBNodeData();
00058 HDBNodeData& operator= (const HDBNodeData& x);
00059
00060 HDBBlock m_blk;
00061 String m_key;
00062 Int32 m_bfrLen;
00063 unsigned char* m_bfr;
00064 Int32 m_offset;
00065 Int32 m_version;
00066 };
00067 typedef IntrusiveReference<HDBNodeData> HDBNodeDataRef;
00068
00069 public:
00073 HDBNode() : m_pdata(0) {}
00081 HDBNode(const String& key, int dataLen, const unsigned char* data);
00086 HDBNode(const HDBNode& x) : m_pdata(x.m_pdata) { }
00092 HDBNode& operator= (const HDBNode& x)
00093 {
00094 m_pdata = x.m_pdata;
00095 return *this;
00096 }
00100 UInt32 getFlags()
00101 {
00102 return m_pdata->m_blk.flags;
00103 }
00109 bool areAllFlagsOn(UInt32 flags) const
00110 {
00111 return ((m_pdata->m_blk.flags & flags) == flags);
00112 }
00118 bool areSomeFlagsOn(UInt32 flags) const
00119 {
00120 return ((m_pdata->m_blk.flags & flags) != 0);
00121 }
00129 bool turnFlagsOn(HDBHandle& hdl, UInt32 flags);
00137 bool turnFlagsOff(HDBHandle& hdl, UInt32 flags);
00141 String getKey() const { return m_pdata->m_key; }
00145 Int32 getDataLen() const { return m_pdata->m_bfrLen; }
00149 const unsigned char* getData() const { return m_pdata->m_bfr; }
00153 bool hasParent() const { return (m_pdata->m_blk.parent != -1); }
00157 bool hasNextSibling() const { return (m_pdata->m_blk.nextSib != -1); }
00161 bool hasPreviousSibling() const { return (m_pdata->m_blk.prevSib != -1); }
00165 bool hasChildren() const { return (m_pdata->m_blk.firstChild != -1); }
00169 bool isRoot() const { return (hasParent() == false); }
00173 bool isChild() const { return (hasParent() == true); }
00177 bool isSibling() const
00178 {
00179 return ( hasNextSibling() || hasPreviousSibling() );
00180 }
00181
00182 typedef HDBNodeDataRef HDBNode::*safe_bool;
00186 operator safe_bool () const
00187 { return m_pdata ? &HDBNode::m_pdata : 0; }
00188 bool operator!() const
00189 { return !m_pdata; }
00190 private:
00191 HDBNode(const char* key, HDBHandle& hdl);
00192 HDBNode(Int32 offset, HDBHandle& hdl);
00193 void read(Int32 offset, HDBHandle& hdl);
00194 bool reload(HDBHandle& hdl);
00195 enum EWriteHeaderFlag
00196 {
00197 E_WRITE_ALL,
00198 E_WRITE_ONLY_HEADER
00199 };
00200 Int32 write(HDBHandle& hdl, EWriteHeaderFlag onlyHeader = E_WRITE_ALL);
00201 void updateOffsets(HDBHandle& hdl, Int32 offset);
00202 Int32 getParentOffset() const { return m_pdata->m_blk.parent; }
00203 Int32 getFirstChildOffset() const { return m_pdata->m_blk.firstChild; }
00204 Int32 getLastChildOffset() const { return m_pdata->m_blk.lastChild; }
00205 Int32 getNextSiblingOffset() const { return m_pdata->m_blk.nextSib; }
00206 Int32 getPrevSiblingOffset() const { return m_pdata->m_blk.prevSib; }
00207 Int32 getOffset() const { return m_pdata->m_offset; }
00208 bool remove(HDBHandle& hdl);
00209 void removeBlock(HDBHandle& hdl, HDBBlock& fblk, Int32 offset);
00210 void addChild(HDBHandle& hdl, HDBNode& arg);
00211 bool updateData(HDBHandle& hdl, int dataLen, const unsigned char* data);
00212 void setNull() { m_pdata = 0; }
00213
00214 #ifdef OW_WIN32
00215 #pragma warning (push)
00216 #pragma warning (disable: 4251)
00217 #endif
00218
00219 HDBNodeDataRef m_pdata;
00220
00221 #ifdef OW_WIN32
00222 #pragma warning (pop)
00223 #endif
00224
00225 friend class HDBHandle;
00226 };
00227
00228 }
00229
00230 #endif