LCOV - code coverage report
Current view: top level - connectivity/source/inc/dbase - dindexnode.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 60 0.0 %
Date: 2014-04-11 Functions: 0 38 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : #ifndef _CONNECTIVITY_DBASE_INDEXNODE_HXX_
      20             : #define _CONNECTIVITY_DBASE_INDEXNODE_HXX_
      21             : 
      22             : #include "file/fcode.hxx"
      23             : #include "file/FTable.hxx"
      24             : #include "connectivity/FValue.hxx"
      25             : #include <rtl/ref.hxx>
      26             : #include <tools/ref.hxx>
      27             : #include <tools/stream.hxx>
      28             : #include <vector>
      29             : 
      30             : #define NODE_NOTFOUND 0xFFFF
      31             : #define DINDEX_PAGE_SIZE 512
      32             : 
      33             : namespace connectivity
      34             : {
      35             :     namespace dbase
      36             :     {
      37             : 
      38             :         class ONDXNode;
      39             :         class ODbaseIndex;
      40             : 
      41             :         // Index Key
      42             : 
      43             :         typedef file::OOperand ONDXKey_BASE;
      44           0 :         class ONDXKey : public ONDXKey_BASE
      45             :         {
      46             :             friend class ONDXNode;
      47             :             sal_uInt32      nRecord;                /* Record pointer */
      48             :             ORowSetValue    xValue;                 /* Key values     */
      49             : 
      50             :         public:
      51             :             ONDXKey(sal_uInt32 nRec=0);
      52             :             ONDXKey(const ORowSetValue& rVal, sal_Int32 eType, sal_uInt32 nRec);
      53             :             ONDXKey(const OUString& aStr, sal_uInt32 nRec = 0);
      54             :             ONDXKey(double aVal, sal_uInt32 nRec = 0);
      55             : 
      56             :             inline ONDXKey(const ONDXKey& rKey);
      57             : 
      58             :             inline ONDXKey& operator= (const ONDXKey& rKey);
      59             :             virtual void setValue(const ORowSetValue& _rVal) SAL_OVERRIDE;
      60             : 
      61             :             virtual const ORowSetValue& getValue() const SAL_OVERRIDE;
      62             : 
      63           0 :             sal_uInt32 GetRecord() const        { return nRecord;   }
      64           0 :             void setRecord(sal_uInt32 _nRec)    { nRecord = _nRec;  }
      65           0 :             void   ResetRecord()            { nRecord = 0;      }
      66             : 
      67             :             sal_Bool operator == (const ONDXKey& rKey) const;
      68             :             sal_Bool operator != (const ONDXKey& rKey) const;
      69             :             sal_Bool operator <  (const ONDXKey& rKey) const;
      70             :             sal_Bool operator <= (const ONDXKey& rKey) const;
      71             :             sal_Bool operator >  (const ONDXKey& rKey) const;
      72             :             sal_Bool operator >= (const ONDXKey& rKey) const;
      73             : 
      74             :             sal_Bool Load (SvFileStream& rStream, sal_Bool bText);
      75             :             sal_Bool Write(SvFileStream& rStream, sal_Bool bText);
      76             : 
      77             :             static sal_Bool IsText(sal_Int32 eType);
      78             : 
      79             :         private:
      80             :             int Compare(const ONDXKey& rKey) const;
      81             :         };
      82             : 
      83             : 
      84             : 
      85             : 
      86             : 
      87             :         // Index Page Pointer
      88             : 
      89             :         class ONDXPage;
      90             :         typedef tools::SvRef<ONDXPage> ONDXPageRef; // Base class - because we need to store additional information
      91             : 
      92             : 
      93           0 :         class ONDXPagePtr : public ONDXPageRef
      94             :         {
      95             :             friend  SvStream& WriteONDXPagePtr(SvStream &rStream, const ONDXPagePtr&);
      96             :             friend  SvStream& operator >> (SvStream &rStream, ONDXPagePtr&);
      97             : 
      98             :             sal_uInt32  nPagePos;       // Position in the index file
      99             : 
     100             :         public:
     101           0 :             ONDXPagePtr(sal_uInt32 nPos = 0):nPagePos(nPos){}
     102             :             ONDXPagePtr(const ONDXPagePtr& rRef);
     103             :             ONDXPagePtr(ONDXPage* pRefPage);
     104             : 
     105             :             ONDXPagePtr& operator=(const ONDXPagePtr& rRef);
     106             :             ONDXPagePtr& operator=(ONDXPage* pPageRef);
     107             : 
     108           0 :             sal_uInt32 GetPagePos() const {return nPagePos;}
     109           0 :             sal_Bool HasPage() const {return nPagePos != 0;}
     110             :             //  sal_Bool Is() const { return isValid(); }
     111             :         };
     112             : 
     113             :         // Index Page
     114             : 
     115             :         class ONDXPage : public SvRefBase
     116             :         {
     117             :             friend class ODbaseIndex;
     118             : 
     119             :             friend  SvStream& WriteONDXPage(SvStream &rStream, const ONDXPage&);
     120             :             friend  SvStream& operator >> (SvStream &rStream, ONDXPage&);
     121             : 
     122             :             sal_uInt32      nPagePos;       // Position in the index file
     123             :             sal_Bool        bModified : 1;
     124             :             sal_uInt16      nCount;
     125             : 
     126             :             ONDXPagePtr aParent,            // Parent page
     127             :                         aChild;             // Pointer to the right child page
     128             :             ODbaseIndex& rIndex;
     129             :             ONDXNode*  ppNodes;             // Array of nodes
     130             : 
     131             :         public:
     132             :             // Node operations
     133           0 :             sal_uInt16  Count() const {return nCount;}
     134             : 
     135             :             sal_Bool    Insert(ONDXNode& rNode, sal_uInt32 nRowsLeft = 0);
     136             :             sal_Bool    Insert(sal_uInt16 nIndex, ONDXNode& rNode);
     137             :             sal_Bool    Append(ONDXNode& rNode);
     138             :             sal_Bool    Delete(sal_uInt16);
     139             :             void    Remove(sal_uInt16);
     140             :             void    Release(sal_Bool bSave = sal_True);
     141             :             void    ReleaseFull(sal_Bool bSave = sal_True);
     142             : 
     143             :             // Split and merge
     144             :             ONDXNode Split(ONDXPage& rPage);
     145             :             void Merge(sal_uInt16 nParentNodePos, ONDXPagePtr xPage);
     146             : 
     147             :             // Access operators
     148             :             ONDXNode& operator[] (sal_uInt16 nPos);
     149             :             const ONDXNode& operator[] (sal_uInt16 nPos) const;
     150             : 
     151             :             sal_Bool IsRoot() const;
     152             :             sal_Bool IsLeaf() const;
     153             :             sal_Bool IsModified() const;
     154             :             sal_Bool HasParent();
     155             :             sal_Bool HasChild() const;
     156             : 
     157             :             sal_Bool IsFull() const;
     158             : 
     159           0 :             sal_uInt32 GetPagePos() const {return nPagePos;}
     160             :             ONDXPagePtr& GetChild(ODbaseIndex* pIndex = 0);
     161             : 
     162             :             // Parent does not need to be reloaded
     163             :             ONDXPagePtr GetParent();
     164           0 :             ODbaseIndex& GetIndex() {return rIndex;}
     165           0 :             const ODbaseIndex& GetIndex() const {return rIndex;}
     166             : 
     167             :             // Setting the child, via reference to retain the PagePos
     168             :             void SetChild(ONDXPagePtr aCh);
     169             :             void SetParent(ONDXPagePtr aPa);
     170             : 
     171             :             sal_uInt16 Search(const ONDXKey& rSearch);
     172             :             sal_uInt16 Search(const ONDXPage* pPage);
     173             :             void   SearchAndReplace(const ONDXKey& rSearch, ONDXKey& rReplace);
     174             : 
     175             :         protected:
     176             :             ONDXPage(ODbaseIndex& rIndex, sal_uInt32 nPos, ONDXPage* = NULL);
     177             :             virtual ~ONDXPage();
     178             : 
     179             :             virtual void QueryDelete() SAL_OVERRIDE;
     180             : 
     181           0 :             void SetModified(sal_Bool bMod) {bModified = bMod;}
     182           0 :             void SetPagePos(sal_uInt32 nPage) {nPagePos = nPage;}
     183             : 
     184             :             sal_Bool Find(const ONDXKey&);  // Descend recursively
     185             :             sal_uInt16 FindPos(const ONDXKey& rKey) const;
     186             : 
     187             : #if OSL_DEBUG_LEVEL > 1
     188             :             void PrintPage();
     189             : #endif
     190             :         };
     191             : 
     192             :         SvStream& WriteONDXPagePtr(SvStream &rStream, const ONDXPagePtr&);
     193             :         SvStream& operator >> (SvStream &rStream, ONDXPagePtr&);
     194             : 
     195           0 :         inline sal_Bool ONDXPage::IsRoot() const {return !aParent.Is();}
     196           0 :         inline sal_Bool ONDXPage::IsLeaf() const {return !aChild.HasPage();}
     197           0 :         inline sal_Bool ONDXPage::IsModified() const {return bModified;}
     198           0 :         inline sal_Bool ONDXPage::HasParent() {return aParent.Is();}
     199             :         inline sal_Bool ONDXPage::HasChild() const {return aChild.HasPage();}
     200           0 :         inline ONDXPagePtr ONDXPage::GetParent() {return aParent;}
     201             : 
     202           0 :         inline void ONDXPage::SetParent(ONDXPagePtr aPa = ONDXPagePtr())
     203             :         {
     204           0 :             aParent = aPa;
     205           0 :         }
     206             : 
     207           0 :         inline void ONDXPage::SetChild(ONDXPagePtr aCh = ONDXPagePtr())
     208             :         {
     209           0 :             aChild = aCh;
     210           0 :             if (aChild.Is())
     211           0 :                 aChild->SetParent(this);
     212           0 :         }
     213             :         SvStream& operator >> (SvStream &rStream, ONDXPage& rPage);
     214             :         SvStream& WriteONDXPage(SvStream &rStream, const ONDXPage& rPage);
     215             : 
     216             : 
     217             :         typedef ::std::vector<ONDXPage*>    ONDXPageList;
     218             : 
     219             : 
     220             :         // Index Node
     221             : 
     222           0 :         class ONDXNode
     223             :         {
     224             :             friend class ONDXPage;
     225             :             ONDXPagePtr aChild;             /* Next page reference */
     226             :             ONDXKey   aKey;
     227             : 
     228             :         public:
     229           0 :             ONDXNode(){}
     230           0 :             ONDXNode(const ONDXKey& rKey,
     231             :                        ONDXPagePtr aPagePtr = ONDXPagePtr())
     232           0 :                        :aChild(aPagePtr),aKey(rKey) {}
     233             : 
     234             :             // Does the node point to a page?
     235           0 :             sal_Bool            HasChild() const {return aChild.HasPage();}
     236             :             // If an index is provided, we may be able to retrieve the page
     237             :             ONDXPagePtr&    GetChild(ODbaseIndex* pIndex = NULL, ONDXPage* = NULL);
     238             : 
     239           0 :             const ONDXKey& GetKey() const   { return aKey;}
     240           0 :             ONDXKey&       GetKey()         { return aKey;}
     241             : 
     242             :             // Setting the child, via reference to retain the PagePos
     243             :             void            SetChild(ONDXPagePtr aCh = ONDXPagePtr(), ONDXPage* = NULL);
     244             :             void            SetKey(ONDXKey& rKey) {aKey = rKey;}
     245             : 
     246             :             void Write(SvStream &rStream, const ONDXPage& rPage) const;
     247             :             void Read(SvStream &rStream, ODbaseIndex&);
     248             :         };
     249             : 
     250             :         // inline implementation
     251             : 
     252             : //      inline ONDXKey::ONDXKey(const ORowSetValue& rVal, sal_Int32 eType, sal_uInt32 nRec)
     253             : //          : ONDXKey_BASE(eType)
     254             : //          , nRecord(nRec),xValue(rVal)
     255             : //      {
     256             : //      }
     257             : 
     258             : 
     259             : //      inline ONDXKey::ONDXKey(const OUString& aStr, sal_uInt32 nRec)
     260             : //                  : ONDXKey_BASE(::com::sun::star::sdbc::DataType::VARCHAR)
     261             : //                   ,nRecord(nRec)
     262             : //      {
     263             : //          if (aStr.len())
     264             : //              xValue = aStr;
     265             : //      }
     266             : 
     267             : //      inline ONDXKey::ONDXKey(double aVal, sal_uInt32 nRec)
     268             : //                   : ONDXKey_BASE(::com::sun::star::sdbc::DataType::DOUBLE)
     269             : //                   ,nRecord(nRec)
     270             : //                   ,xValue(aVal)
     271             : //      {
     272             : //      }
     273             : 
     274             : //      inline ONDXKey::ONDXKey(sal_uInt32 nRec)
     275             : //                   :nRecord(nRec)
     276             : //      {
     277             : //      }
     278             : 
     279           0 :         inline ONDXKey::ONDXKey(const ONDXKey& rKey)
     280           0 :                      : ONDXKey_BASE(rKey.getDBType())
     281             :                      ,nRecord(rKey.nRecord)
     282           0 :                      ,xValue(rKey.xValue)
     283             :         {
     284           0 :         }
     285             : 
     286           0 :         inline ONDXKey& ONDXKey::operator=(const ONDXKey& rKey)
     287             :         {
     288           0 :             if(&rKey == this)
     289           0 :                 return *this;
     290             : 
     291           0 :             xValue = rKey.xValue;
     292           0 :             nRecord = rKey.nRecord;
     293           0 :             m_eDBType = rKey.getDBType();
     294           0 :             return *this;
     295             :         }
     296             : 
     297           0 :         inline sal_Bool ONDXKey::operator == (const ONDXKey& rKey) const
     298             :         {
     299           0 :             if(&rKey == this)
     300           0 :                 return sal_True;
     301           0 :             return Compare(rKey) == 0;
     302             :         }
     303           0 :         inline sal_Bool ONDXKey::operator != (const ONDXKey& rKey) const
     304             :         {
     305           0 :             return !operator== (rKey);
     306             :         }
     307             :         inline sal_Bool ONDXKey::operator <  (const ONDXKey& rKey) const
     308             :         {
     309             :             return Compare(rKey) < 0;
     310             :         }
     311           0 :         inline sal_Bool ONDXKey::operator >  (const ONDXKey& rKey) const
     312             :         {
     313           0 :             return Compare(rKey) > 0;
     314             :         }
     315           0 :         inline sal_Bool ONDXKey::operator <= (const ONDXKey& rKey) const
     316             :         {
     317           0 :             return !operator > (rKey);
     318             :         }
     319             :         inline sal_Bool ONDXKey::operator >= (const ONDXKey& rKey) const
     320             :         {
     321             :             return !operator< (rKey);
     322             :         }
     323             : 
     324           0 :         inline void ONDXNode::SetChild(ONDXPagePtr aCh, ONDXPage* pParent)
     325             :         {
     326           0 :             aChild = aCh;
     327           0 :             if (aChild.Is())
     328           0 :                 aChild->SetParent(pParent);
     329           0 :         }
     330             : 
     331             :     }
     332             : 
     333             : }
     334             : 
     335             : 
     336             : 
     337             : 
     338             : #endif // _CONNECTIVITY_DBASE_INDEXNODE_HXX_
     339             : 
     340             : 
     341             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10