LCOV - code coverage report
Current view: top level - writerfilter/inc/resourcemodel - TableData.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 69 77 89.6 %
Date: 2012-08-25 Functions: 33 70 47.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 36 92 39.1 %

           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                 :            : 
      20                 :            : #ifndef INCLUDED_TABLE_DATA
      21                 :            : #define INCLUDED_TABLE_DATA
      22                 :            : 
      23                 :            : #include <resourcemodel/WW8ResourceModel.hxx>
      24                 :            : 
      25                 :            : #include <vector>
      26                 :            : #include <boost/shared_ptr.hpp>
      27                 :            : 
      28                 :            : namespace writerfilter
      29                 :            : {
      30                 :            : 
      31                 :            : template <typename T, typename PropertiesPointer>
      32                 :            : /**
      33                 :            :    Class containing the data to describe a table cell.
      34                 :            :  */
      35                 :            : class CellData
      36                 :            : {
      37                 :            :     /**
      38                 :            :        Handle to start of cell.
      39                 :            :     */
      40                 :            :     T mStart;
      41                 :            : 
      42                 :            :     /**
      43                 :            :        Handle to end of cell.
      44                 :            :     */
      45                 :            :     T mEnd;
      46                 :            : 
      47                 :            :     /**
      48                 :            :        Pointer to properties of cell.
      49                 :            :     */
      50                 :            :     PropertiesPointer mpProps;
      51                 :            : 
      52                 :            :     bool mbOpen;
      53                 :            : 
      54                 :            : public:
      55                 :            :     typedef boost::shared_ptr<CellData> Pointer_t;
      56                 :            : 
      57                 :        546 :     CellData(T start, PropertiesPointer pProps)
      58      [ #  +  - ]:        546 :     : mStart(start), mEnd(start), mpProps(pProps), mbOpen(true)
                 [ #  # ]
      59                 :            :     {
      60                 :        546 :     }
      61                 :            : 
      62 [ +  - ][ -  + ]:       1092 :     virtual ~CellData() {}
      63                 :            : 
      64                 :            :     /**
      65                 :            :        Set the start handle of the cell.
      66                 :            : 
      67                 :            :        @param start    the start handle of the cell
      68                 :            :     */
      69                 :            :     void setStart(T start) { mStart = start; }
      70                 :            : 
      71                 :            :     /**
      72                 :            :        Set the end handle of a cell.
      73                 :            : 
      74                 :            :        @param end     the end handle of the cell
      75                 :            :     */
      76                 :        514 :     void setEnd(T end) { mEnd = end; mbOpen = false; }
      77                 :            : 
      78                 :            :     /**
      79                 :            :        Set the properties of the cell.
      80                 :            : 
      81                 :            :        @param pProps      the properties of the cell
      82                 :            :     */
      83                 :            :     void setProperties(PropertiesPointer pProps) { mpProps = pProps; }
      84                 :            : 
      85                 :            :     /**
      86                 :            :        Adds properties to the cell.
      87                 :            : 
      88                 :            :        @param pProps      the properties to add
      89                 :            :      */
      90                 :         85 :     void insertProperties(PropertiesPointer pProps)
      91                 :            :     {
      92         [ -  + ]:         85 :         if( mpProps.get() )
      93 [ #  # ][ #  # ]:          0 :             mpProps->insert(pProps);
                 [ #  # ]
      94                 :            :         else
      95                 :         85 :             mpProps = pProps;
      96                 :         85 :     }
      97                 :            : 
      98                 :            :     /**
      99                 :            :        Return start handle of the cell.
     100                 :            :      */
     101                 :        514 :     const T & getStart() { return mStart; }
     102                 :            : 
     103                 :            :     /**
     104                 :            :        Return end handle of the cell.
     105                 :            :     */
     106                 :        514 :     const T & getEnd() { return mEnd; }
     107                 :            : 
     108                 :            :     /**
     109                 :            :        Return properties of the cell.
     110                 :            :      */
     111                 :        514 :     PropertiesPointer getProperties() { return mpProps; }
     112                 :            : 
     113                 :        493 :     bool isOpen() const { return mbOpen; }
     114                 :            : };
     115                 :            : 
     116                 :            : template <typename T, typename PropertiesPointer>
     117                 :            : /**
     118                 :            :    Class to handle data of a table row.
     119                 :            :  */
     120                 :            : class RowData
     121                 :            : {
     122                 :            :     typedef typename CellData<T, PropertiesPointer>::Pointer_t
     123                 :            :         CellDataPointer_t;
     124                 :            :     typedef ::std::vector<CellDataPointer_t> Cells;
     125                 :            : 
     126                 :            :     /**
     127                 :            :        the cell data of the row
     128                 :            :      */
     129                 :            :     Cells mCells;
     130                 :            : 
     131                 :            :     /**
     132                 :            :        the properties of the row
     133                 :            :     */
     134                 :            :     mutable PropertiesPointer mpProperties;
     135                 :            : 
     136                 :            : public:
     137                 :            :     typedef boost::shared_ptr<RowData <T, PropertiesPointer> > Pointer_t;
     138                 :            : 
     139         [ +  - ]:        867 :     RowData() {}
     140                 :            : 
     141                 :            :     RowData(const RowData<T, PropertiesPointer> & rRowData)
     142                 :            :     : mCells(rRowData.mCells), mpProperties(rRowData.mpProperties)
     143                 :            :     {
     144                 :            :     }
     145                 :            : 
     146 [ +  - ][ -  + ]:       1734 :     virtual ~RowData() {}
     147                 :            : 
     148                 :            :     /**
     149                 :            :        Add a cell to the row.
     150                 :            : 
     151                 :            :        @param start     the start handle of the cell
     152                 :            :        @param end       the end handle of the cell
     153                 :            :        @param pProps    the properties of the cell
     154                 :            :      */
     155                 :        546 :     void addCell(const T & start, PropertiesPointer pProps)
     156                 :            :     {
     157                 :            :         CellDataPointer_t pCellData
     158      [ #  +  - ]:        546 :             (new CellData<T, PropertiesPointer>(start, pProps));
              [ #  +  - ]
              [ #  +  - ]
              [ #  +  - ]
              [ #  +  - ]
                 [ #  # ]
     159 [ +  - ][ +  - ]:        546 :         mCells.push_back(pCellData);
     160                 :        546 :     }
     161                 :            : 
     162                 :        514 :     void endCell(const T & end)
     163                 :            :     {
     164         [ +  - ]:        514 :         if (mCells.size() > 0)
     165 [ +  - ][ +  - ]:        514 :             mCells.back()->setEnd(end);
     166                 :        514 :     }
     167                 :            : 
     168                 :        631 :     bool isCellOpen() const
     169                 :            :     {
     170 [ +  + ][ +  + ]:        631 :         return mCells.size() > 0 && mCells.back()->isOpen();
     171                 :            :     }
     172                 :            : 
     173                 :            :     /**
     174                 :            :        Add properties to the row.
     175                 :            : 
     176                 :            :        @param pProperties   the properties to set
     177                 :            :      */
     178                 :        127 :     void insertProperties(PropertiesPointer pProperties)
     179                 :            :     {
     180         [ +  + ]:        127 :         if( pProperties.get() )
     181                 :            :         {
     182         [ +  - ]:        106 :             if( !mpProperties.get() )
     183                 :        106 :                 mpProperties = pProperties;
     184                 :            :             else
     185 [ #  # ][ #  # ]:          0 :                 mpProperties->insert( pProperties );
                 [ #  # ]
     186                 :            :         }
     187                 :        127 :     }
     188                 :            : 
     189                 :            :     /**
     190                 :            :        Add properties to a cell of the row.
     191                 :            : 
     192                 :            :        @param i          index of the cell
     193                 :            :        @param pProps     the properties to add
     194                 :            :      */
     195                 :          0 :     void insertCellProperties(unsigned int i, PropertiesPointer pProps)
     196                 :            :     {
     197         [ #  # ]:          0 :         mCells[i]->insertProperties(pProps);
     198                 :          0 :     }
     199                 :            : 
     200                 :            :     /**
     201                 :            :         Add properties to the last cell of the row.
     202                 :            :      */
     203                 :         85 :     void insertCellProperties(PropertiesPointer pProps)
     204                 :            :     {
     205         [ +  - ]:         85 :         if (! mCells.empty())
     206 [ +  - ][ +  - ]:         85 :             mCells.back()->insertProperties(pProps);
     207                 :         85 :     }
     208                 :            : 
     209                 :            :     /**
     210                 :            :        Return number of cells in the row.
     211                 :            :     */
     212                 :        127 :     unsigned int getCellCount()
     213                 :            :     {
     214                 :        127 :         return mCells.size();
     215                 :            :     }
     216                 :            : 
     217                 :            :     /**
     218                 :            :        Return start handle of a cell in the row.
     219                 :            : 
     220                 :            :        @param i      index of the cell
     221                 :            :      */
     222                 :        514 :     const T & getCellStart(unsigned int i) const
     223                 :            :     {
     224                 :        514 :         return mCells[i]->getStart();
     225                 :            :     }
     226                 :            : 
     227                 :            :     /**
     228                 :            :         Return end handle of a cell in the row.
     229                 :            : 
     230                 :            :         @param i     index of the cell
     231                 :            :     */
     232                 :        514 :     const T & getCellEnd(unsigned int i) const
     233                 :            :     {
     234                 :        514 :         return mCells[i]->getEnd();
     235                 :            :     }
     236                 :            : 
     237                 :            :     /**
     238                 :            :        Return the properties of a cell in the row.
     239                 :            : 
     240                 :            :        @param i      index of the cell
     241                 :            :      */
     242                 :        514 :     PropertiesPointer getCellProperties(unsigned int i) const
     243                 :            :     {
     244                 :        514 :         return mCells[i]->getProperties();
     245                 :            :     }
     246                 :            : 
     247                 :            :     /**
     248                 :            :        Return properties of the row.
     249                 :            :      */
     250                 :        127 :     PropertiesPointer getProperties()
     251                 :            :     {
     252                 :        127 :         return mpProperties;
     253                 :            :     }
     254                 :            : 
     255                 :            :     /**
     256                 :            :        Clear the row data.
     257                 :            :      */
     258                 :            :     void clear()
     259                 :            :     {
     260                 :            :         mCells.clear();
     261                 :            :         mpProperties.reset();
     262                 :            :     }
     263                 :            : };
     264                 :            : 
     265                 :            : template <typename T, typename PropertiesPointer>
     266                 :            : /**
     267                 :            :    Class that holds the data of a table.
     268                 :            :  */
     269                 :            : class TableData
     270                 :            : {
     271                 :            :     typedef typename RowData<T, PropertiesPointer>::Pointer_t RowPointer_t;
     272                 :            :     typedef ::std::vector<RowPointer_t> Rows;
     273                 :            : 
     274                 :            :     /**
     275                 :            :        the table properties
     276                 :            :      */
     277                 :            :     PropertiesPointer mpTableProps;
     278                 :            : 
     279                 :            :     /**
     280                 :            :        the data of the rows of the table
     281                 :            :     */
     282                 :            :     Rows mRows;
     283                 :            : 
     284                 :            :     /**
     285                 :            :         pointer to the data of the current row (while building up the table data).
     286                 :            :     */
     287                 :            :     RowPointer_t mpRow;
     288                 :            : 
     289                 :            :     /**
     290                 :            :        depth of the current table in a hierarchy of tables
     291                 :            :      */
     292                 :            :     unsigned int mnDepth;
     293                 :            : 
     294                 :            :     /**
     295                 :            :        initialize mpRow
     296                 :            :      */
     297 [ +  - ][ +  - ]:        867 :     void newRow() { mpRow = RowPointer_t(new RowData<T, PropertiesPointer>()); }
     298                 :            : 
     299                 :            : public:
     300                 :            :     typedef boost::shared_ptr<TableData <T, PropertiesPointer> > Pointer_t;
     301                 :            : 
     302 [ +  - ][ +  - ]:        740 :     TableData(unsigned int nDepth) : mnDepth(nDepth) { newRow(); }
                 [ +  - ]
     303         [ +  - ]:        740 :     ~TableData() {}
     304                 :            : 
     305                 :            :     /**
     306                 :            :        End the current row.
     307                 :            : 
     308                 :            :        Sets properties of the current row and pushes the row to the
     309                 :            :        back of the rows currently contained in the table.
     310                 :            : 
     311                 :            :        @param pProperties    properties of the row to be ended
     312                 :            :      */
     313                 :        127 :     void endRow(PropertiesPointer pProperties)
     314                 :            :     {
     315         [ +  - ]:        127 :         mpRow->insertProperties(pProperties);
     316                 :        127 :         mRows.push_back(mpRow);
     317                 :        127 :         newRow();
     318                 :        127 :     }
     319                 :            : 
     320                 :            :     /**
     321                 :            :        Add a cell to the current row.
     322                 :            : 
     323                 :            :        @param start   start handle of the cell
     324                 :            :        @param end     end handle of the cell
     325                 :            :        @param pProps  properties of the cell
     326                 :            :      */
     327                 :        546 :     void addCell(const T & start, PropertiesPointer pProps)
     328                 :            :     {
     329         [ +  - ]:        546 :         mpRow->addCell(start, pProps);
     330                 :        546 :     }
     331                 :            : 
     332                 :            :     /**
     333                 :            :         End the current cell of the current row.
     334                 :            : 
     335                 :            :         @parm end    end handle of the cell
     336                 :            :      */
     337                 :        514 :     void endCell(const T & end)
     338                 :            :     {
     339                 :        514 :         mpRow->endCell(end);
     340                 :        514 :     }
     341                 :            : 
     342                 :            :     /**
     343                 :            :         Return if the current cell of the current row is open.
     344                 :            :      */
     345                 :        631 :     bool isCellOpen() const
     346                 :            :     {
     347                 :        631 :         return mpRow->isCellOpen();
     348                 :            :     }
     349                 :            : 
     350                 :            :     /**
     351                 :            :         Insert properties to the current cell of the current row.
     352                 :            : 
     353                 :            :         @param pProps   the properties to add
     354                 :            :      */
     355                 :         85 :     void insertCellProperties(PropertiesPointer pProps)
     356                 :            :     {
     357         [ +  - ]:         85 :         mpRow->insertCellProperties(pProps);
     358                 :         85 :     }
     359                 :            : 
     360                 :            :     /**
     361                 :            :        Add properties to a cell of the current row.
     362                 :            : 
     363                 :            :        @param i       index of the cell
     364                 :            :        @param pProps  properties to add
     365                 :            :      */
     366                 :          0 :     void insertCellProperties(unsigned int i, PropertiesPointer pProps)
     367                 :            :     {
     368         [ #  # ]:          0 :         mpRow->insertCellProperties(i, pProps);
     369                 :          0 :     }
     370                 :            : 
     371                 :            :     void insertTableProperties( PropertiesPointer pProps )
     372                 :            :     {
     373                 :            :         if ( mpTableProps.get( ) )
     374                 :            :             mpTableProps->insert( pProps );
     375                 :            :         else
     376                 :            :             mpTableProps = pProps;
     377                 :            :     }
     378                 :            : 
     379                 :            :     /**
     380                 :            :       Return the table properties.
     381                 :            :      */
     382                 :            :     PropertiesPointer getTableProperties( )
     383                 :            :     {
     384                 :            :         return mpTableProps;
     385                 :            :     }
     386                 :            : 
     387                 :            :     /**
     388                 :            :        Return number of rows in the table.
     389                 :            :      */
     390                 :        671 :     unsigned int getRowCount()
     391                 :            :     {
     392                 :        671 :         return mRows.size();
     393                 :            :     }
     394                 :            : 
     395                 :            :     /**
     396                 :            :        Return depth of table in surrounding table hierarchy.
     397                 :            :     */
     398                 :        671 :     unsigned int getDepth()
     399                 :            :     {
     400                 :        671 :         return mnDepth;
     401                 :            :     }
     402                 :            : 
     403                 :            :     /**
     404                 :            :        Return row data of a certain row.
     405                 :            : 
     406                 :            :        @param i     index of the row
     407                 :            :     */
     408                 :        127 :     const RowPointer_t getRow(unsigned int i) const
     409                 :            :     {
     410                 :        127 :         return mRows[i];
     411                 :            :     }
     412                 :            : };
     413                 :            : 
     414                 :            : }
     415                 :            : 
     416                 :            : #endif // INCLUDED_TABLE_DATA
     417                 :            : 
     418                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10