LCOV - code coverage report
Current view: top level - connectivity/source/inc/dbase - dindexnode.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 62 0.0 %
Date: 2012-08-25 Functions: 0 49 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 46 0.0 %

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

Generated by: LCOV version 1.10