OW_HDBNode.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2001-2004 Vintela, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
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 } // end namespace OW_NAMESPACE
00229 
00230 #endif

Generated on Thu Feb 9 08:47:59 2006 for openwbem by  doxygen 1.4.6