LCOV - code coverage report
Current view: top level - sc/source/filter/inc - formulabase.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 10 12 83.3 %
Date: 2012-08-25 Functions: 11 15 73.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 5 10 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef OOX_XLS_FORMULABASE_HXX
      30                 :            : #define OOX_XLS_FORMULABASE_HXX
      31                 :            : 
      32                 :            : #include <com/sun/star/beans/Pair.hpp>
      33                 :            : #include <com/sun/star/sheet/FormulaOpCodeMapEntry.hpp>
      34                 :            : #include <com/sun/star/sheet/FormulaToken.hpp>
      35                 :            : #include <com/sun/star/table/CellAddress.hpp>
      36                 :            : #include <com/sun/star/table/CellRangeAddress.hpp>
      37                 :            : #include <com/sun/star/uno/Sequence.hxx>
      38                 :            : #include "oox/helper/propertyset.hxx"
      39                 :            : #include "oox/helper/refvector.hxx"
      40                 :            : #include "addressconverter.hxx"
      41                 :            : 
      42                 :            : namespace com { namespace sun { namespace star {
      43                 :            :     namespace sheet { class XFormulaOpCodeMapper; }
      44                 :            :     namespace sheet { class XFormulaParser; }
      45                 :            : } } }
      46                 :            : 
      47                 :            : namespace oox { template< typename Type > class Matrix; }
      48                 :            : 
      49                 :            : namespace oox {
      50                 :            : namespace xls {
      51                 :            : 
      52                 :            : // Constants ==================================================================
      53                 :            : 
      54                 :            : const size_t BIFF_TOKARR_MAXLEN                 = 4096;     /// Maximum size of a token array.
      55                 :            : 
      56                 :            : // token class flags ----------------------------------------------------------
      57                 :            : 
      58                 :            : const sal_uInt8 BIFF_TOKCLASS_MASK              = 0x60;
      59                 :            : const sal_uInt8 BIFF_TOKCLASS_NONE              = 0x00;     /// 00-1F: Base tokens.
      60                 :            : const sal_uInt8 BIFF_TOKCLASS_REF               = 0x20;     /// 20-3F: Reference class tokens.
      61                 :            : const sal_uInt8 BIFF_TOKCLASS_VAL               = 0x40;     /// 40-5F: Value class tokens.
      62                 :            : const sal_uInt8 BIFF_TOKCLASS_ARR               = 0x60;     /// 60-7F: Array class tokens.
      63                 :            : 
      64                 :            : const sal_uInt8 BIFF_TOKFLAG_INVALID            = 0x80;     /// This bit must be null for a valid token identifier.
      65                 :            : 
      66                 :            : // base token identifiers -----------------------------------------------------
      67                 :            : 
      68                 :            : const sal_uInt8 BIFF_TOKID_MASK                 = 0x1F;
      69                 :            : 
      70                 :            : const sal_uInt8 BIFF_TOKID_NONE                 = 0x00;     /// Placeholder for invalid token id.
      71                 :            : const sal_uInt8 BIFF_TOKID_EXP                  = 0x01;     /// Array or shared formula reference.
      72                 :            : const sal_uInt8 BIFF_TOKID_TBL                  = 0x02;     /// Multiple operation reference.
      73                 :            : const sal_uInt8 BIFF_TOKID_ADD                  = 0x03;     /// Addition operator.
      74                 :            : const sal_uInt8 BIFF_TOKID_SUB                  = 0x04;     /// Subtraction operator.
      75                 :            : const sal_uInt8 BIFF_TOKID_MUL                  = 0x05;     /// Multiplication operator.
      76                 :            : const sal_uInt8 BIFF_TOKID_DIV                  = 0x06;     /// Division operator.
      77                 :            : const sal_uInt8 BIFF_TOKID_POWER                = 0x07;     /// Power operator.
      78                 :            : const sal_uInt8 BIFF_TOKID_CONCAT               = 0x08;     /// String concatenation operator.
      79                 :            : const sal_uInt8 BIFF_TOKID_LT                   = 0x09;     /// Less than operator.
      80                 :            : const sal_uInt8 BIFF_TOKID_LE                   = 0x0A;     /// Less than or equal operator.
      81                 :            : const sal_uInt8 BIFF_TOKID_EQ                   = 0x0B;     /// Equal operator.
      82                 :            : const sal_uInt8 BIFF_TOKID_GE                   = 0x0C;     /// Greater than or equal operator.
      83                 :            : const sal_uInt8 BIFF_TOKID_GT                   = 0x0D;     /// Greater than operator.
      84                 :            : const sal_uInt8 BIFF_TOKID_NE                   = 0x0E;     /// Not equal operator.
      85                 :            : const sal_uInt8 BIFF_TOKID_ISECT                = 0x0F;     /// Intersection operator.
      86                 :            : const sal_uInt8 BIFF_TOKID_LIST                 = 0x10;     /// List operator.
      87                 :            : const sal_uInt8 BIFF_TOKID_RANGE                = 0x11;     /// Range operator.
      88                 :            : const sal_uInt8 BIFF_TOKID_UPLUS                = 0x12;     /// Unary plus.
      89                 :            : const sal_uInt8 BIFF_TOKID_UMINUS               = 0x13;     /// Unary minus.
      90                 :            : const sal_uInt8 BIFF_TOKID_PERCENT              = 0x14;     /// Percent sign.
      91                 :            : const sal_uInt8 BIFF_TOKID_PAREN                = 0x15;     /// Parentheses.
      92                 :            : const sal_uInt8 BIFF_TOKID_MISSARG              = 0x16;     /// Missing argument.
      93                 :            : const sal_uInt8 BIFF_TOKID_STR                  = 0x17;     /// String constant.
      94                 :            : const sal_uInt8 BIFF_TOKID_NLR                  = 0x18;     /// Natural language reference (NLR).
      95                 :            : const sal_uInt8 BIFF_TOKID_ATTR                 = 0x19;     /// Special attribute.
      96                 :            : const sal_uInt8 BIFF_TOKID_SHEET                = 0x1A;     /// Start of a sheet reference (BIFF2-BIFF4).
      97                 :            : const sal_uInt8 BIFF_TOKID_ENDSHEET             = 0x1B;     /// End of a sheet reference (BIFF2-BIFF4).
      98                 :            : const sal_uInt8 BIFF_TOKID_ERR                  = 0x1C;     /// Error constant.
      99                 :            : const sal_uInt8 BIFF_TOKID_BOOL                 = 0x1D;     /// Boolean constant.
     100                 :            : const sal_uInt8 BIFF_TOKID_INT                  = 0x1E;     /// Integer constant.
     101                 :            : const sal_uInt8 BIFF_TOKID_NUM                  = 0x1F;     /// Floating-point constant.
     102                 :            : 
     103                 :            : // base identifiers of classified tokens --------------------------------------
     104                 :            : 
     105                 :            : const sal_uInt8 BIFF_TOKID_ARRAY                = 0x00;     /// Array constant.
     106                 :            : const sal_uInt8 BIFF_TOKID_FUNC                 = 0x01;     /// Function, fixed number of arguments.
     107                 :            : const sal_uInt8 BIFF_TOKID_FUNCVAR              = 0x02;     /// Function, variable number of arguments.
     108                 :            : const sal_uInt8 BIFF_TOKID_NAME                 = 0x03;     /// Defined name.
     109                 :            : const sal_uInt8 BIFF_TOKID_REF                  = 0x04;     /// 2D cell reference.
     110                 :            : const sal_uInt8 BIFF_TOKID_AREA                 = 0x05;     /// 2D area reference.
     111                 :            : const sal_uInt8 BIFF_TOKID_MEMAREA              = 0x06;     /// Constant reference subexpression.
     112                 :            : const sal_uInt8 BIFF_TOKID_MEMERR               = 0x07;     /// Deleted reference subexpression.
     113                 :            : const sal_uInt8 BIFF_TOKID_MEMNOMEM             = 0x08;     /// Constant reference subexpression without result.
     114                 :            : const sal_uInt8 BIFF_TOKID_MEMFUNC              = 0x09;     /// Variable reference subexpression.
     115                 :            : const sal_uInt8 BIFF_TOKID_REFERR               = 0x0A;     /// Deleted 2D cell reference.
     116                 :            : const sal_uInt8 BIFF_TOKID_AREAERR              = 0x0B;     /// Deleted 2D area reference.
     117                 :            : const sal_uInt8 BIFF_TOKID_REFN                 = 0x0C;     /// Relative 2D cell reference (in names).
     118                 :            : const sal_uInt8 BIFF_TOKID_AREAN                = 0x0D;     /// Relative 2D area reference (in names).
     119                 :            : const sal_uInt8 BIFF_TOKID_MEMAREAN             = 0x0E;     /// Reference subexpression (in names).
     120                 :            : const sal_uInt8 BIFF_TOKID_MEMNOMEMN            = 0x0F;     /// Reference subexpression (in names) without result.
     121                 :            : const sal_uInt8 BIFF_TOKID_FUNCCE               = 0x18;
     122                 :            : const sal_uInt8 BIFF_TOKID_NAMEX                = 0x19;     /// External reference.
     123                 :            : const sal_uInt8 BIFF_TOKID_REF3D                = 0x1A;     /// 3D cell reference.
     124                 :            : const sal_uInt8 BIFF_TOKID_AREA3D               = 0x1B;     /// 3D area reference.
     125                 :            : const sal_uInt8 BIFF_TOKID_REFERR3D             = 0x1C;     /// Deleted 3D cell reference.
     126                 :            : const sal_uInt8 BIFF_TOKID_AREAERR3D            = 0x1D;     /// Deleted 3D area reference
     127                 :            : 
     128                 :            : // specific token constants ---------------------------------------------------
     129                 :            : 
     130                 :            : const sal_uInt8 BIFF_TOK_ARRAY_DOUBLE           = 0;        /// Double value in an array.
     131                 :            : const sal_uInt8 BIFF_TOK_ARRAY_STRING           = 1;        /// String value in an array.
     132                 :            : const sal_uInt8 BIFF_TOK_ARRAY_BOOL             = 2;        /// Boolean value in an array.
     133                 :            : const sal_uInt8 BIFF_TOK_ARRAY_ERROR            = 4;        /// Error code in an array.
     134                 :            : 
     135                 :            : const sal_uInt8 BIFF_TOK_BOOL_FALSE             = 0;        /// FALSE value of a tBool token.
     136                 :            : const sal_uInt8 BIFF_TOK_BOOL_TRUE              = 1;        /// TRUE value of a tBool token.
     137                 :            : 
     138                 :            : const sal_uInt8 BIFF_TOK_ATTR_VOLATILE          = 0x01;     /// Volatile function.
     139                 :            : const sal_uInt8 BIFF_TOK_ATTR_IF                = 0x02;     /// Start of true condition in IF function.
     140                 :            : const sal_uInt8 BIFF_TOK_ATTR_CHOOSE            = 0x04;     /// Jump array of CHOOSE function.
     141                 :            : const sal_uInt8 BIFF_TOK_ATTR_SKIP              = 0x08;     /// Skip tokens.
     142                 :            : const sal_uInt8 BIFF_TOK_ATTR_SUM               = 0x10;     /// SUM function with one parameter.
     143                 :            : const sal_uInt8 BIFF_TOK_ATTR_ASSIGN            = 0x20;     /// BASIC style assignment.
     144                 :            : const sal_uInt8 BIFF_TOK_ATTR_SPACE             = 0x40;     /// Spaces in formula representation.
     145                 :            : const sal_uInt8 BIFF_TOK_ATTR_SPACE_VOLATILE    = 0x41;     /// Leading spaces and volatile formula.
     146                 :            : const sal_uInt8 BIFF_TOK_ATTR_IFERROR           = 0x80;     /// Start of condition in IFERROR function (BIFF12 only).
     147                 :            : 
     148                 :            : const sal_uInt8 BIFF_TOK_ATTR_SPACE_SP          = 0x00;     /// Spaces before next token.
     149                 :            : const sal_uInt8 BIFF_TOK_ATTR_SPACE_BR          = 0x01;     /// Line breaks before next token.
     150                 :            : const sal_uInt8 BIFF_TOK_ATTR_SPACE_SP_OPEN     = 0x02;     /// Spaces before opening parenthesis.
     151                 :            : const sal_uInt8 BIFF_TOK_ATTR_SPACE_BR_OPEN     = 0x03;     /// Line breaks before opening parenthesis.
     152                 :            : const sal_uInt8 BIFF_TOK_ATTR_SPACE_SP_CLOSE    = 0x04;     /// Spaces before closing parenthesis.
     153                 :            : const sal_uInt8 BIFF_TOK_ATTR_SPACE_BR_CLOSE    = 0x05;     /// Line breaks before closing parenthesis.
     154                 :            : const sal_uInt8 BIFF_TOK_ATTR_SPACE_SP_PRE      = 0x06;     /// Spaces before formula (BIFF3).
     155                 :            : 
     156                 :            : const sal_uInt16 BIFF_TOK_FUNCVAR_CMD           = 0x8000;   /// Macro command.
     157                 :            : const sal_uInt16 BIFF_TOK_FUNCVAR_FUNCIDMASK    = 0x7FFF;   /// Mask for function/command index.
     158                 :            : const sal_uInt8 BIFF_TOK_FUNCVAR_CMDPROMPT      = 0x80;     /// User prompt for macro commands.
     159                 :            : const sal_uInt8 BIFF_TOK_FUNCVAR_COUNTMASK      = 0x7F;     /// Mask for parameter count.
     160                 :            : 
     161                 :            : const sal_uInt16 BIFF12_TOK_REF_COLMASK         = 0x3FFF;   /// Mask to extract column from reference (BIFF12).
     162                 :            : const sal_Int32 BIFF12_TOK_REF_ROWMASK          = 0xFFFFF;  /// Mask to extract row from reference (BIFF12).
     163                 :            : const sal_uInt16 BIFF12_TOK_REF_COLREL          = 0x4000;   /// True = column is relative (BIFF12).
     164                 :            : const sal_uInt16 BIFF12_TOK_REF_ROWREL          = 0x8000;   /// True = row is relative (BIFF12).
     165                 :            : 
     166                 :            : const sal_uInt16 BIFF_TOK_REF_COLMASK           = 0x00FF;   /// Mask to extract BIFF8 column from reference.
     167                 :            : const sal_uInt16 BIFF_TOK_REF_ROWMASK           = 0x3FFF;   /// Mask to extract BIFF2-BIFF5 row from reference.
     168                 :            : const sal_uInt16 BIFF_TOK_REF_COLREL            = 0x4000;   /// True = column is relative.
     169                 :            : const sal_uInt16 BIFF_TOK_REF_ROWREL            = 0x8000;   /// True = row is relative.
     170                 :            : 
     171                 :            : const sal_uInt16 BIFF12_TOK_TABLE_COLUMN         = 0x0001;   /// Table reference: Single column.
     172                 :            : const sal_uInt16 BIFF12_TOK_TABLE_COLRANGE       = 0x0002;   /// Table reference: Range of columns.
     173                 :            : const sal_uInt16 BIFF12_TOK_TABLE_ALL            = 0x0004;   /// Table reference: Special [#All] range.
     174                 :            : const sal_uInt16 BIFF12_TOK_TABLE_HEADERS        = 0x0008;   /// Table reference: Special [#Headers] range.
     175                 :            : const sal_uInt16 BIFF12_TOK_TABLE_DATA           = 0x0010;   /// Table reference: Special [#Data] range.
     176                 :            : const sal_uInt16 BIFF12_TOK_TABLE_TOTALS         = 0x0020;   /// Table reference: Special [#Totals] range.
     177                 :            : const sal_uInt16 BIFF12_TOK_TABLE_THISROW        = 0x0040;   /// Table reference: Special [#This Row] range.
     178                 :            : const sal_uInt16 BIFF12_TOK_TABLE_SP_BRACKETS    = 0x0080;   /// Table reference: Spaces in outer brackets.
     179                 :            : const sal_uInt16 BIFF12_TOK_TABLE_SP_SEP         = 0x0100;   /// Table reference: Spaces after separators.
     180                 :            : const sal_uInt16 BIFF12_TOK_TABLE_ROW            = 0x0200;   /// Table reference: Single row.
     181                 :            : const sal_uInt16 BIFF12_TOK_TABLE_CELL           = 0x0400;   /// Table reference: Single cell.
     182                 :            : 
     183                 :            : const sal_uInt8 BIFF_TOK_NLR_ERR                = 0x01;     /// NLR: Invalid/deleted.
     184                 :            : const sal_uInt8 BIFF_TOK_NLR_ROWR               = 0x02;     /// NLR: Row index.
     185                 :            : const sal_uInt8 BIFF_TOK_NLR_COLR               = 0x03;     /// NLR: Column index.
     186                 :            : const sal_uInt8 BIFF_TOK_NLR_ROWV               = 0x06;     /// NLR: Value in row.
     187                 :            : const sal_uInt8 BIFF_TOK_NLR_COLV               = 0x07;     /// NLR: Value in column.
     188                 :            : const sal_uInt8 BIFF_TOK_NLR_RANGE              = 0x0A;     /// NLR: Range.
     189                 :            : const sal_uInt8 BIFF_TOK_NLR_SRANGE             = 0x0B;     /// Stacked NLR: Range.
     190                 :            : const sal_uInt8 BIFF_TOK_NLR_SROWR              = 0x0C;     /// Stacked NLR: Row index.
     191                 :            : const sal_uInt8 BIFF_TOK_NLR_SCOLR              = 0x0D;     /// Stacked NLR: Column index.
     192                 :            : const sal_uInt8 BIFF_TOK_NLR_SROWV              = 0x0E;     /// Stacked NLR: Value in row.
     193                 :            : const sal_uInt8 BIFF_TOK_NLR_SCOLV              = 0x0F;     /// Stacked NLR: Value in column.
     194                 :            : const sal_uInt8 BIFF_TOK_NLR_RANGEERR           = 0x10;     /// NLR: Invalid/deleted range.
     195                 :            : const sal_uInt8 BIFF_TOK_NLR_SXNAME             = 0x1D;     /// NLR: Pivot table name.
     196                 :            : const sal_uInt16 BIFF_TOK_NLR_REL               = 0x8000;   /// True = NLR is relative.
     197                 :            : const sal_uInt16 BIFF_TOK_NLR_MASK              = 0x3FFF;   /// Mask to extract BIFF8 column from NLR.
     198                 :            : 
     199                 :            : const sal_uInt32 BIFF_TOK_NLR_ADDREL            = 0x80000000;   /// NLR relative (in appended data).
     200                 :            : const sal_uInt32 BIFF_TOK_NLR_ADDMASK           = 0x3FFFFFFF;   /// Mask for number of appended ranges.
     201                 :            : 
     202                 :            : // function constants ---------------------------------------------------------
     203                 :            : 
     204                 :            : const sal_uInt8 OOX_MAX_PARAMCOUNT              = 255;      /// Maximum parameter count for OOXML/BIFF12 files.
     205                 :            : const sal_uInt8 BIFF_MAX_PARAMCOUNT             = 30;       /// Maximum parameter count for BIFF2-BIFF8 files.
     206                 :            : 
     207                 :            : const sal_uInt16 BIFF_FUNC_IF                   = 1;        /// Function identifier of the IF function.
     208                 :            : const sal_uInt16 BIFF_FUNC_SUM                  = 4;        /// Function identifier of the SUM function.
     209                 :            : const sal_uInt16 BIFF_FUNC_TRUE                 = 34;       /// Function identifier of the TRUE function.
     210                 :            : const sal_uInt16 BIFF_FUNC_FALSE                = 35;       /// Function identifier of the FALSE function.
     211                 :            : const sal_uInt16 BIFF_FUNC_ROWS                 = 76;       /// Function identifier of the ROWS function.
     212                 :            : const sal_uInt16 BIFF_FUNC_COLUMNS              = 77;       /// Function identifier of the COLUMNS function.
     213                 :            : const sal_uInt16 BIFF_FUNC_OFFSET               = 78;       /// Function identifier of the OFFSET function.
     214                 :            : const sal_uInt16 BIFF_FUNC_EXTERNCALL           = 255;      /// BIFF function id of the EXTERN.CALL function.
     215                 :            : const sal_uInt16 BIFF_FUNC_FLOOR                = 285;      /// Function identifier of the FLOOR function.
     216                 :            : const sal_uInt16 BIFF_FUNC_CEILING              = 288;      /// Function identifier of the CEILING function.
     217                 :            : const sal_uInt16 BIFF_FUNC_HYPERLINK            = 359;      /// Function identifier of the HYPERLINK function.
     218                 :            : const sal_uInt16 BIFF_FUNC_WEEKNUM              = 465;      /// Function identifier of the WEEKNUM function.
     219                 :            : 
     220                 :            : // Formula type ===============================================================
     221                 :            : 
     222                 :            : /** Enumerates all possible types of a formula. */
     223                 :            : enum FormulaType
     224                 :            : {
     225                 :            :     FORMULATYPE_CELL,           /// Simple cell formula, or reference to a shared formula name.
     226                 :            :     FORMULATYPE_ARRAY,          /// Array (matrix) formula.
     227                 :            :     FORMULATYPE_SHAREDFORMULA,  /// Shared formula definition.
     228                 :            :     FORMULATYPE_CONDFORMAT,     /// Condition of a conditional format rule.
     229                 :            :     FORMULATYPE_VALIDATION,     /// Condition of a data validation.
     230                 :            :     FORMULATYPE_DEFINEDNAME     /// Definition of a defined name.
     231                 :            : };
     232                 :            : 
     233                 :            : // Reference helpers ==========================================================
     234                 :            : 
     235                 :            : /** A 2D formula cell reference struct with relative flags. */
     236                 :            : struct BinSingleRef2d
     237                 :            : {
     238                 :            :     sal_Int32           mnCol;              /// Column index.
     239                 :            :     sal_Int32           mnRow;              /// Row index.
     240                 :            :     bool                mbColRel;           /// True = relative column reference.
     241                 :            :     bool                mbRowRel;           /// True = relative row reference.
     242                 :            : 
     243                 :            :     explicit            BinSingleRef2d();
     244                 :            : 
     245                 :            :     void                setBiff12Data( sal_uInt16 nCol, sal_Int32 nRow, bool bRelativeAsOffset );
     246                 :            :     void                setBiff2Data( sal_uInt8 nCol, sal_uInt16 nRow, bool bRelativeAsOffset );
     247                 :            :     void                setBiff8Data( sal_uInt16 nCol, sal_uInt16 nRow, bool bRelativeAsOffset );
     248                 :            : 
     249                 :            :     void                readBiff12Data( SequenceInputStream& rStrm, bool bRelativeAsOffset );
     250                 :            :     void                readBiff2Data( BiffInputStream& rStrm, bool bRelativeAsOffset );
     251                 :            :     void                readBiff8Data( BiffInputStream& rStrm, bool bRelativeAsOffset );
     252                 :            : };
     253                 :            : 
     254                 :            : // ----------------------------------------------------------------------------
     255                 :            : 
     256                 :            : /** A 2D formula cell range reference struct with relative flags. */
     257                 :          0 : struct BinComplexRef2d
     258                 :            : {
     259                 :            :     BinSingleRef2d      maRef1;             /// Start (top-left) cell address.
     260                 :            :     BinSingleRef2d      maRef2;             /// End (bottom-right) cell address.
     261                 :            : 
     262                 :            :     void                readBiff12Data( SequenceInputStream& rStrm, bool bRelativeAsOffset );
     263                 :            :     void                readBiff2Data( BiffInputStream& rStrm, bool bRelativeAsOffset );
     264                 :            :     void                readBiff8Data( BiffInputStream& rStrm, bool bRelativeAsOffset );
     265                 :            : };
     266                 :            : 
     267                 :            : // Token vector, token sequence ===============================================
     268                 :            : 
     269                 :            : typedef ::com::sun::star::sheet::FormulaToken       ApiToken;
     270                 :            : typedef ::com::sun::star::uno::Sequence< ApiToken > ApiTokenSequence;
     271                 :            : 
     272                 :            : /** Contains the base address and type of a special token representing an array
     273                 :            :     formula or a shared formula (sal_False), or a table operation (sal_True). */
     274                 :            : typedef ::com::sun::star::beans::Pair< ::com::sun::star::table::CellAddress, sal_Bool > ApiSpecialTokenInfo;
     275                 :            : 
     276                 :            : /** A vector of formula tokens with additional convenience functions. */
     277                 :         48 : class ApiTokenVector : public ::std::vector< ApiToken >
     278                 :            : {
     279                 :            : public:
     280                 :            :     explicit            ApiTokenVector();
     281                 :            : 
     282                 :            :     /** Appends a new token with the passed op-code, returns its data field. */
     283                 :            :     ::com::sun::star::uno::Any&
     284                 :            :                         append( sal_Int32 nOpCode );
     285                 :            : 
     286                 :            :     /** Appends a new token with the passed op-code and data. */
     287                 :            :     template< typename Type >
     288                 :          0 :     inline void         append( sal_Int32 nOpCode, const Type& rData ) { append( nOpCode ) <<= rData; }
     289                 :            : };
     290                 :            : 
     291                 :            : // Token sequence iterator ====================================================
     292                 :            : 
     293                 :            : /** Token sequence iterator that is able to skip space tokens. */
     294                 :            : class ApiTokenIterator
     295                 :            : {
     296                 :            : public:
     297                 :            :     explicit            ApiTokenIterator( const ApiTokenSequence& rTokens, sal_Int32 nSpacesOpCode, bool bSkipSpaces );
     298                 :         15 :     inline bool         is() const { return mpToken != mpTokenEnd; }
     299                 :            :     inline const ApiToken* get() const { return mpToken; }
     300                 :          6 :     inline const ApiToken* operator->() const { return mpToken; }
     301                 :            :     inline const ApiToken& operator*() const { return *mpToken; }
     302                 :            : 
     303                 :            :     ApiTokenIterator&   operator++();
     304                 :            : 
     305                 :            : private:
     306                 :            :     void                skipSpaces();
     307                 :            : 
     308                 :            : private:
     309                 :            :     const ApiToken*     mpToken;            /// Pointer to current token of the token sequence.
     310                 :            :     const ApiToken*     mpTokenEnd;         /// Pointer behind last token of the token sequence.
     311                 :            :     const sal_Int32     mnSpacesOpCode;     /// Op-code for whitespace tokens.
     312                 :            :     const bool          mbSkipSpaces;       /// true = Skip whitespace tokens.
     313                 :            : };
     314                 :            : 
     315                 :            : // List of API op-codes =======================================================
     316                 :            : 
     317                 :            : /** Contains all API op-codes needed to build formulas with tokens. */
     318                 :         24 : struct ApiOpCodes
     319                 :            : {
     320                 :            :     // special
     321                 :            :     sal_Int32           OPCODE_UNKNOWN;         /// Internal: function name unknown to mapper.
     322                 :            :     sal_Int32           OPCODE_EXTERNAL;        /// External function call (e.g. add-ins).
     323                 :            :     // formula structure
     324                 :            :     sal_Int32           OPCODE_PUSH;            /// Op-code for common value operands.
     325                 :            :     sal_Int32           OPCODE_MISSING;         /// Placeholder for a missing function parameter.
     326                 :            :     sal_Int32           OPCODE_SPACES;          /// Spaces between other formula tokens.
     327                 :            :     sal_Int32           OPCODE_NAME;            /// Index of a defined name.
     328                 :            :     sal_Int32           OPCODE_DBAREA;          /// Index of a database area.
     329                 :            :     sal_Int32           OPCODE_NLR;             /// Natural language reference.
     330                 :            :     sal_Int32           OPCODE_DDE;             /// DDE link function.
     331                 :            :     sal_Int32           OPCODE_MACRO;           /// Macro function call.
     332                 :            :     sal_Int32           OPCODE_BAD;             /// Bad token (unknown name, formula error).
     333                 :            :     sal_Int32           OPCODE_NONAME;          /// Function style #NAME? error.
     334                 :            :     // separators
     335                 :            :     sal_Int32           OPCODE_OPEN;            /// Opening parenthesis.
     336                 :            :     sal_Int32           OPCODE_CLOSE;           /// Closing parenthesis.
     337                 :            :     sal_Int32           OPCODE_SEP;             /// Function parameter separator.
     338                 :            :     // array separators
     339                 :            :     sal_Int32           OPCODE_ARRAY_OPEN;      /// Opening brace for constant arrays.
     340                 :            :     sal_Int32           OPCODE_ARRAY_CLOSE;     /// Closing brace for constant arrays.
     341                 :            :     sal_Int32           OPCODE_ARRAY_ROWSEP;    /// Row separator in constant arrays.
     342                 :            :     sal_Int32           OPCODE_ARRAY_COLSEP;    /// Column separator in constant arrays.
     343                 :            :     // unary operators
     344                 :            :     sal_Int32           OPCODE_PLUS_SIGN;       /// Unary plus sign.
     345                 :            :     sal_Int32           OPCODE_MINUS_SIGN;      /// Unary minus sign.
     346                 :            :     sal_Int32           OPCODE_PERCENT;         /// Percent sign.
     347                 :            :     // binary operators
     348                 :            :     sal_Int32           OPCODE_ADD;             /// Addition operator.
     349                 :            :     sal_Int32           OPCODE_SUB;             /// Subtraction operator.
     350                 :            :     sal_Int32           OPCODE_MULT;            /// Multiplication operator.
     351                 :            :     sal_Int32           OPCODE_DIV;             /// Division operator.
     352                 :            :     sal_Int32           OPCODE_POWER;           /// Power operator.
     353                 :            :     sal_Int32           OPCODE_CONCAT;          /// String concatenation operator.
     354                 :            :     sal_Int32           OPCODE_EQUAL;           /// Compare equal operator.
     355                 :            :     sal_Int32           OPCODE_NOT_EQUAL;       /// Compare not equal operator.
     356                 :            :     sal_Int32           OPCODE_LESS;            /// Compare less operator.
     357                 :            :     sal_Int32           OPCODE_LESS_EQUAL;      /// Compare less or equal operator.
     358                 :            :     sal_Int32           OPCODE_GREATER;         /// Compare greater operator.
     359                 :            :     sal_Int32           OPCODE_GREATER_EQUAL;   /// Compare greater or equal operator.
     360                 :            :     sal_Int32           OPCODE_INTERSECT;       /// Range intersection operator.
     361                 :            :     sal_Int32           OPCODE_LIST;            /// Range list operator.
     362                 :            :     sal_Int32           OPCODE_RANGE;           /// Range operator.
     363                 :            : };
     364                 :            : 
     365                 :            : // Function parameter info ====================================================
     366                 :            : 
     367                 :            : /** Enumerates validity modes for a function parameter. */
     368                 :            : enum FuncParamValidity
     369                 :            : {
     370                 :            :     FUNC_PARAM_NONE = 0,        /// Default for an unspecified entry in a C-array.
     371                 :            :     FUNC_PARAM_REGULAR,         /// Parameter supported by Calc and Excel.
     372                 :            :     FUNC_PARAM_CALCONLY,        /// Parameter supported by Calc only.
     373                 :            :     FUNC_PARAM_EXCELONLY        /// Parameter supported by Excel only.
     374                 :            : };
     375                 :            : 
     376                 :            : /** Enumerates different types of token class conversion in function parameters. */
     377                 :            : enum FuncParamConversion
     378                 :            : {
     379                 :            :     FUNC_PARAMCONV_ORG,         /// Use original class of current token.
     380                 :            :     FUNC_PARAMCONV_VAL,         /// Convert tokens to VAL class.
     381                 :            :     FUNC_PARAMCONV_ARR,         /// Convert tokens to ARR class.
     382                 :            :     FUNC_PARAMCONV_RPT,         /// Repeat parent conversion in VALTYPE parameters.
     383                 :            :     FUNC_PARAMCONV_RPX,         /// Repeat parent conversion in REFTYPE parameters.
     384                 :            :     FUNC_PARAMCONV_RPO          /// Repeat parent conversion in operands of operators.
     385                 :            : };
     386                 :            : 
     387                 :            : /** Structure that contains all needed information for a parameter in a
     388                 :            :     function.
     389                 :            : 
     390                 :            :     The member meValid specifies which application supports the parameter. If
     391                 :            :     set to CALCONLY, import filters have to insert a default value for this
     392                 :            :     parameter, and export filters have to skip the parameter. If set to
     393                 :            :     EXCELONLY, import filters have to skip the parameter, and export filters
     394                 :            :     have to insert a default value for this parameter.
     395                 :            : 
     396                 :            :     The member mbValType specifies whether the parameter requires tokens to be
     397                 :            :     of value type (VAL or ARR class).
     398                 :            : 
     399                 :            :         If set to false, the parameter is called to be REFTYPE. Tokens with REF
     400                 :            :         default class can be inserted for the parameter (e.g. tAreaR tokens).
     401                 :            : 
     402                 :            :         If set to true, the parameter is called to be VALTYPE. Tokens with REF
     403                 :            :         class need to be converted to VAL tokens first (e.g. tAreaR will be
     404                 :            :         converted to tAreaV), and further conversion is done according to this
     405                 :            :         new token class.
     406                 :            : 
     407                 :            :     The member meConv specifies how to convert the current token class of the
     408                 :            :     token inserted for the parameter. If the token class is still REF this
     409                 :            :     means that the token has default REF class and the parameter is REFTYPE
     410                 :            :     (see member mbValType), the token will not be converted at all and remains
     411                 :            :     in REF class. Otherwise, token class conversion is depending on the actual
     412                 :            :     token class of the return value of the function containing this parameter.
     413                 :            :     The function may return REF class (tFuncR, tFuncVarR, tFuncCER), or it may
     414                 :            :     return VAL or ARR class (tFuncV, tFuncA, tFuncVarV, tFuncVarA, tFuncCEV,
     415                 :            :     tFuncCEA). Even if the function is able to return REF class, it may return
     416                 :            :     VAL or ARR class instead due to the VALTYPE data type of the parent
     417                 :            :     function parameter that calls the own function. Example: The INDIRECT
     418                 :            :     function returns REF class by default. But if called from a VALTYPE
     419                 :            :     function parameter, e.g. in the formula =ABS(INDIRECT("A1")), it returns
     420                 :            :     VAL or ARR class instead. Additionally, the repeating conversion types RPT
     421                 :            :     and RPX rely on the conversion executed for the function token class.
     422                 :            : 
     423                 :            :         1) ORG:
     424                 :            :         Use the original class of the token (VAL or ARR), regardless of any
     425                 :            :         conversion done for the function return class.
     426                 :            : 
     427                 :            :         2) VAL:
     428                 :            :         Convert ARR tokens to VAL class, regardless of any conversion done for
     429                 :            :         the function return class.
     430                 :            : 
     431                 :            :         3) ARR:
     432                 :            :         Convert VAL tokens to ARR class, regardless of any conversion done for
     433                 :            :         the function return class.
     434                 :            : 
     435                 :            :         4) RPT:
     436                 :            :         If the own function returns REF class (thus it is called from a REFTYPE
     437                 :            :         parameter, see above), and the parent conversion type (for the function
     438                 :            :         return class) was ORG, VAL, or ARR, ignore that conversion and always
     439                 :            :         use VAL conversion for the own token instead. If the parent conversion
     440                 :            :         type was RPT or RPX, repeat the conversion that would have been used if
     441                 :            :         the function would return value type.
     442                 :            :         If the own function returns value type (VAL or ARR class, see above),
     443                 :            :         and the parent conversion type (for the function return class) was ORG,
     444                 :            :         VAL, ARR, or RPT, repeat this conversion for the own token. If the
     445                 :            :         parent conversion type was RPX, always use ORG conversion type for the
     446                 :            :         own token instead.
     447                 :            : 
     448                 :            :         5) RPX:
     449                 :            :         This type of conversion only occurs in functions returning VAL class by
     450                 :            :         default. If the own token is value type, and the VAL return class of
     451                 :            :         the own function has been changed to ARR class (due to direct ARR
     452                 :            :         conversion, or due to ARR conversion repeated by RPT or RPX), set the
     453                 :            :         own token to ARR type. Otherwise use the original token type (VAL
     454                 :            :         conversion from parent parameter will not be repeated at all). If
     455                 :            :         nested functions have RPT or value-type RPX parameters, they will not
     456                 :            :         repeat this conversion type, but will use ORG conversion instead (see
     457                 :            :         description of RPT above).
     458                 :            : 
     459                 :            :         6) RPO:
     460                 :            :         This type of conversion is only used for the operands of all operators
     461                 :            :         (unary and binary arithmetic operators, comparison operators, and range
     462                 :            :         operators). It is not used for function parameters. On conversion, it
     463                 :            :         will be replaced by the last conversion type that was not the RPO
     464                 :            :         conversion. This leads to a slightly different behaviour than the RPT
     465                 :            :         conversion for operands in conjunction with a parent RPX conversion.
     466                 :            :  */
     467                 :            : struct FunctionParamInfo
     468                 :            : {
     469                 :            :     FuncParamValidity   meValid;        /// Parameter validity.
     470                 :            :     FuncParamConversion meConv;         /// Token class conversion type.
     471                 :            :     bool                mbValType;      /// Data type (false = REFTYPE, true = VALTYPE).
     472                 :            : };
     473                 :            : 
     474                 :            : // Function data ==============================================================
     475                 :            : 
     476                 :            : /** This enumeration contains constants for all known external libraries
     477                 :            :     containing supported sheet functions. */
     478                 :            : enum FunctionLibraryType
     479                 :            : {
     480                 :            :     FUNCLIB_UNKNOWN = 0,        /// Unknown library (must be zero).
     481                 :            :     FUNCLIB_EUROTOOL            /// EuroTool add-in with EUROCONVERT function.
     482                 :            : };
     483                 :            : 
     484                 :            : // ----------------------------------------------------------------------------
     485                 :            : 
     486                 :            : /** Represents information for a spreadsheet function.
     487                 :            : 
     488                 :            :     The member mpParamInfos points to a C-array of type information structures
     489                 :            :     for all parameters of the function. The last initialized structure
     490                 :            :     describing a regular parameter (member meValid == FUNC_PARAM_REGULAR) in
     491                 :            :     this array is used repeatedly for all following parameters supported by a
     492                 :            :     function.
     493                 :            :  */
     494                 :      20640 : struct FunctionInfo
     495                 :            : {
     496                 :            :     ::rtl::OUString     maOdfFuncName;      /// ODF function name.
     497                 :            :     ::rtl::OUString     maOoxFuncName;      /// OOXML function name.
     498                 :            :     ::rtl::OUString     maBiffMacroName;    /// Expected macro name in EXTERN.CALL function.
     499                 :            :     ::rtl::OUString     maExtProgName;      /// Programmatic function name for external functions.
     500                 :            :     FunctionLibraryType meFuncLibType;      /// The external library this function is part of.
     501                 :            :     sal_Int32           mnApiOpCode;        /// API function opcode.
     502                 :            :     sal_uInt16          mnBiff12FuncId;     /// BIFF12 function identifier.
     503                 :            :     sal_uInt16          mnBiffFuncId;       /// BIFF2-BIFF8 function identifier.
     504                 :            :     sal_uInt8           mnMinParamCount;    /// Minimum number of parameters.
     505                 :            :     sal_uInt8           mnMaxParamCount;    /// Maximum number of parameters.
     506                 :            :     sal_uInt8           mnRetClass;         /// BIFF token class of the return value.
     507                 :            :     const FunctionParamInfo* mpParamInfos;  /// Information about all parameters.
     508                 :            :     bool                mbParamPairs;       /// True = optional parameters are expected to appear in pairs.
     509                 :            :     bool                mbVolatile;         /// True = volatile function.
     510                 :            :     bool                mbExternal;         /// True = external function in Calc.
     511                 :            :     bool                mbMacroFunc;        /// True = macro sheet function or command.
     512                 :            :     bool                mbVarParam;         /// True = use a tFuncVar token, also if min/max are equal.
     513                 :            : };
     514                 :            : 
     515                 :            : typedef RefVector< FunctionInfo > FunctionInfoVector;
     516                 :            : 
     517                 :            : // Function info parameter class iterator =====================================
     518                 :            : 
     519                 :            : /** Iterator working on the mpParamInfos member of the FunctionInfo struct.
     520                 :            : 
     521                 :            :     This iterator can be used to iterate through the array containing the
     522                 :            :     token class conversion information of function parameters. This iterator
     523                 :            :     repeats the last valid structure in the array - it stops automatically
     524                 :            :     before the first empty array entry or before the end of the array, even for
     525                 :            :     repeated calls to the increment operator.
     526                 :            :  */
     527                 :            : class FunctionParamInfoIterator
     528                 :            : {
     529                 :            : public:
     530                 :            :     explicit            FunctionParamInfoIterator( const FunctionInfo& rFuncInfo );
     531                 :            : 
     532                 :            :     bool                isCalcOnlyParam() const;
     533                 :            :     bool                isExcelOnlyParam() const;
     534                 :            :     FunctionParamInfoIterator& operator++();
     535                 :            : 
     536                 :            : private:
     537                 :            :     const FunctionParamInfo* mpParamInfo;
     538                 :            :     const FunctionParamInfo* mpParamInfoEnd;
     539                 :            :     bool                mbParamPairs;
     540                 :            : };
     541                 :            : 
     542                 :            : // Base function provider =====================================================
     543                 :            : 
     544                 :            : struct FunctionProviderImpl;
     545                 :            : 
     546                 :            : /** Provides access to function info structs for all available sheet functions.
     547                 :            :  */
     548                 :         48 : class FunctionProvider  // not derived from WorkbookHelper to make it usable in file dumpers
     549                 :            : {
     550                 :            : public:
     551                 :            :     explicit            FunctionProvider( FilterType eFilter, BiffType eBiff, bool bImportFilter );
     552                 :            :     virtual             ~FunctionProvider();
     553                 :            : 
     554                 :            :     /** Returns the function info for an OOXML function name, or 0 on error. */
     555                 :            :     const FunctionInfo* getFuncInfoFromOoxFuncName( const ::rtl::OUString& rFuncName ) const;
     556                 :            : 
     557                 :            :     /** Returns the function info for a BIFF12 function index, or 0 on error. */
     558                 :            :     const FunctionInfo* getFuncInfoFromBiff12FuncId( sal_uInt16 nFuncId ) const;
     559                 :            : 
     560                 :            :     /** Returns the function info for a BIFF2-BIFF8 function index, or 0 on error. */
     561                 :            :     const FunctionInfo* getFuncInfoFromBiffFuncId( sal_uInt16 nFuncId ) const;
     562                 :            : 
     563                 :            :     /** Returns the function info for a macro function referred by the
     564                 :            :         EXTERN.CALL function, or 0 on error. */
     565                 :            :     const FunctionInfo* getFuncInfoFromMacroName( const ::rtl::OUString& rFuncName ) const;
     566                 :            : 
     567                 :            :     /** Returns the library type associated with the passed URL of a function
     568                 :            :         library (function add-in). */
     569                 :            :     FunctionLibraryType getFuncLibTypeFromLibraryName( const ::rtl::OUString& rLibraryName ) const;
     570                 :            : 
     571                 :            : protected:
     572                 :            :     /** Returns the list of all function infos. */
     573                 :            :     const FunctionInfoVector& getFuncs() const;
     574                 :            : 
     575                 :            : private:
     576                 :            :     typedef ::boost::shared_ptr< FunctionProviderImpl > FunctionProviderImplRef;
     577                 :            :     FunctionProviderImplRef mxFuncImpl;     /// Shared implementation between all copies of the provider.
     578                 :            : };
     579                 :            : 
     580                 :            : // Op-code and function provider ==============================================
     581                 :            : 
     582                 :            : struct OpCodeProviderImpl;
     583                 :            : 
     584                 :            : /** Provides access to API op-codes for all available formula tokens and to
     585                 :            :     function info structs for all available sheet functions.
     586                 :            :  */
     587         [ +  - ]:         48 : class OpCodeProvider : public FunctionProvider // not derived from WorkbookHelper to make it usable as UNO service
     588                 :            : {
     589                 :            : public:
     590                 :            :     explicit            OpCodeProvider(
     591                 :            :                             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxModelFactory,
     592                 :            :                             FilterType eFilter, BiffType eBiff, bool bImportFilter );
     593                 :            :     virtual             ~OpCodeProvider();
     594                 :            : 
     595                 :            :     /** Returns the structure containing all token op-codes for operators and
     596                 :            :         special tokens used by the Calc document and its formula parser. */
     597                 :            :     const ApiOpCodes&   getOpCodes() const;
     598                 :            : 
     599                 :            :     /** Returns the function info for an API token, or 0 on error. */
     600                 :            :     const FunctionInfo* getFuncInfoFromApiToken( const ApiToken& rToken ) const;
     601                 :            : 
     602                 :            :     /** Returns the op-code map that is used by the OOXML formula parser. */
     603                 :            :     ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaOpCodeMapEntry >
     604                 :            :                         getOoxParserMap() const;
     605                 :            : 
     606                 :            : private:
     607                 :            :     typedef ::boost::shared_ptr< OpCodeProviderImpl > OpCodeProviderImplRef;
     608                 :            :     OpCodeProviderImplRef mxOpCodeImpl;     /// Shared implementation between all copies of the provider.
     609                 :            : };
     610                 :            : 
     611                 :            : // API formula parser wrapper =================================================
     612                 :            : 
     613                 :            : /** A wrapper around the FormulaParser service provided by the Calc document. */
     614 [ +  - ][ -  + ]:         24 : class ApiParserWrapper : public OpCodeProvider
     615                 :            : {
     616                 :            : public:
     617                 :            :     explicit            ApiParserWrapper(
     618                 :            :                             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxModelFactory,
     619                 :            :                             const OpCodeProvider& rOpCodeProv );
     620                 :            : 
     621                 :            :     /** Returns read/write access to the formula parser property set. */
     622                 :         18 :     inline PropertySet& getParserProperties() { return maParserProps; }
     623                 :            : 
     624                 :            :     /** Calls the XFormulaParser::parseFormula() function of the API parser. */
     625                 :            :     ApiTokenSequence    parseFormula(
     626                 :            :                             const ::rtl::OUString& rFormula,
     627                 :            :                             const ::com::sun::star::table::CellAddress& rRefPos );
     628                 :            : 
     629                 :            : private:
     630                 :            :     ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XFormulaParser >
     631                 :            :                         mxParser;
     632                 :            :     PropertySet         maParserProps;
     633                 :            : };
     634                 :            : 
     635                 :            : // Formula parser/printer base class for filters ==============================
     636                 :            : 
     637                 :            : /** Base class for import formula parsers and export formula compilers. */
     638 [ +  - ][ -  + ]:         24 : class FormulaProcessorBase : public OpCodeProvider, protected ApiOpCodes, public WorkbookHelper
     639                 :            : {
     640                 :            : public:
     641                 :            :     explicit            FormulaProcessorBase( const WorkbookHelper& rHelper );
     642                 :            : 
     643                 :            :     // ------------------------------------------------------------------------
     644                 :            : 
     645                 :            :     /** Generates a cell address string in A1 notation from the passed cell
     646                 :            :         address.
     647                 :            : 
     648                 :            :         @param rAddress  The cell address containing column and row index.
     649                 :            :         @param bAbsolute  True = adds dollar signs before column and row.
     650                 :            :      */
     651                 :            :     static ::rtl::OUString generateAddress2dString(
     652                 :            :                             const ::com::sun::star::table::CellAddress& rAddress,
     653                 :            :                             bool bAbsolute );
     654                 :            : 
     655                 :            :     /** Generates a cell address string in A1 notation from the passed binary
     656                 :            :         cell address.
     657                 :            : 
     658                 :            :         @param rAddress  The cell address containing column and row index.
     659                 :            :         @param bAbsolute  True = adds dollar signs before column and row.
     660                 :            :      */
     661                 :            :     static ::rtl::OUString generateAddress2dString(
     662                 :            :                             const BinAddress& rAddress,
     663                 :            :                             bool bAbsolute );
     664                 :            : 
     665                 :            :     /** Generates a cell range string in A1:A1 notation from the passed cell
     666                 :            :         range address.
     667                 :            : 
     668                 :            :         @param rRange  The cell range address containing column and row indexes.
     669                 :            :         @param bAbsolute  True = adds dollar signs before columns and rows.
     670                 :            :      */
     671                 :            :     static ::rtl::OUString generateRange2dString(
     672                 :            :                             const ::com::sun::star::table::CellRangeAddress& rRange,
     673                 :            :                             bool bAbsolute );
     674                 :            : 
     675                 :            :     /** Generates a cell range string in A1:A1 notation from the passed binary
     676                 :            :         cell range address.
     677                 :            : 
     678                 :            :         @param rRange  The cell range address containing column and row indexes.
     679                 :            :         @param bAbsolute  True = adds dollar signs before columns and rows.
     680                 :            :      */
     681                 :            :     static ::rtl::OUString generateRange2dString(
     682                 :            :                             const BinRange& rRange,
     683                 :            :                             bool bAbsolute );
     684                 :            : 
     685                 :            :     /** Generates a cell range list string in A1:A1 notation from the passed
     686                 :            :         cell range addresses. May enclose multiple ranges into parentheses.
     687                 :            : 
     688                 :            :         @param rRanges  The list of cell range addresses.
     689                 :            :         @param bAbsolute  True = adds dollar signs before columns and rows.
     690                 :            :         @param cSeparator  Separator character between ranges.
     691                 :            :         @param bEncloseMultiple  True = enclose multiple ranges in parentheses.
     692                 :            :      */
     693                 :            :     static ::rtl::OUString generateRangeList2dString(
     694                 :            :                             const ApiCellRangeList& rRanges,
     695                 :            :                             bool bAbsolute,
     696                 :            :                             sal_Unicode cSeparator,
     697                 :            :                             bool bEncloseMultiple );
     698                 :            : 
     699                 :            :     // ------------------------------------------------------------------------
     700                 :            : 
     701                 :            :     /** Generates a string in Calc formula notation from the passed string.
     702                 :            : 
     703                 :            :         @param rString  The string value.
     704                 :            : 
     705                 :            :         @return  The string enclosed in double quotes, where all contained
     706                 :            :             quote characters are doubled.
     707                 :            :      */
     708                 :            :     static ::rtl::OUString generateApiString( const ::rtl::OUString& rString );
     709                 :            : 
     710                 :            :     /** Generates an array string in Calc formula notation from the passed
     711                 :            :         matrix with Any's containing double values or strings.
     712                 :            : 
     713                 :            :         @param rMatrix  The matrix containing double values or strings.
     714                 :            :      */
     715                 :            :     static ::rtl::OUString generateApiArray( const Matrix< ::com::sun::star::uno::Any >& rMatrix );
     716                 :            : 
     717                 :            :     // ------------------------------------------------------------------------
     718                 :            : 
     719                 :            :     /** Tries to extract a single cell reference from a formula token sequence.
     720                 :            : 
     721                 :            :         @param rTokens  The token sequence to be parsed. Should contain exactly
     722                 :            :             one address token or cell range address token. The token sequence
     723                 :            :             may contain whitespace tokens.
     724                 :            : 
     725                 :            :         @return  If the token sequence is valid, this function returns an Any
     726                 :            :             containing a com.sun.star.sheet.SingleReference object, or a
     727                 :            :             com.sun.star.sheet.ComplexReference object. If the token sequence
     728                 :            :             contains too many, or unexpected tokens, an empty Any is returned.
     729                 :            :      */
     730                 :            :     ::com::sun::star::uno::Any
     731                 :            :                         extractReference( const ApiTokenSequence& rTokens ) const;
     732                 :            : 
     733                 :            :     /** Tries to extract a cell range address from a formula token sequence.
     734                 :            : 
     735                 :            :         @param orAddress  (output parameter) If the token sequence is valid,
     736                 :            :             this parameter will contain the extracted cell range address. If
     737                 :            :             the token sequence contains unexpected tokens, nothing meaningful
     738                 :            :             is inserted, and the function returns false.
     739                 :            : 
     740                 :            :         @param rTokens  The token sequence to be parsed. Should contain exactly
     741                 :            :             one cell range address token. The token sequence may contain
     742                 :            :             whitespace tokens.
     743                 :            : 
     744                 :            :         @param bAllowRelative  True = it is allowed that rTokens contains
     745                 :            :             relative references (based on cell A1 of the current sheet).
     746                 :            :             False = only real absolute references will be accepted.
     747                 :            : 
     748                 :            :         @return  True, if the token sequence contains a valid cell range
     749                 :            :             address which has been extracted to orRange, false otherwise.
     750                 :            :      */
     751                 :            :     bool                extractCellRange(
     752                 :            :                             ::com::sun::star::table::CellRangeAddress& orRange,
     753                 :            :                             const ApiTokenSequence& rTokens,
     754                 :            :                             bool bAllowRelative ) const;
     755                 :            : 
     756                 :            :     /** Tries to extract a cell range list from a formula token sequence.
     757                 :            : 
     758                 :            :         @param orRanges  (output parameter) If the token sequence is valid,
     759                 :            :             this parameter will contain the extracted cell range list. Deleted
     760                 :            :             cells or cell ranges (shown as #REF! error in a formula) will be
     761                 :            :             skipped. If the token sequence contains unexpected tokens, an empty
     762                 :            :             list is returned here.
     763                 :            : 
     764                 :            :         @param rTokens  The token sequence to be parsed. Should contain cell
     765                 :            :             address tokens or cell range address tokens, separated by the
     766                 :            :             standard function parameter separator token. The token sequence may
     767                 :            :             contain parentheses and whitespace tokens.
     768                 :            : 
     769                 :            :         @param bAllowRelative  True = it is allowed that rTokens contains
     770                 :            :             relative references (based on cell A1 of the current sheet).
     771                 :            :             False = only real absolute references will be accepted.
     772                 :            : 
     773                 :            :         @param nFilterBySheet  If non-negative, this function returns only cell
     774                 :            :             ranges located in the specified sheet, otherwise returns all cell
     775                 :            :             ranges contained in the token sequence.
     776                 :            :      */
     777                 :            :     void                extractCellRangeList(
     778                 :            :                             ApiCellRangeList& orRanges,
     779                 :            :                             const ApiTokenSequence& rTokens,
     780                 :            :                             bool bAllowRelative,
     781                 :            :                             sal_Int32 nFilterBySheet = -1 ) const;
     782                 :            : 
     783                 :            :     /** Tries to extract a string from a formula token sequence.
     784                 :            : 
     785                 :            :         @param orString  (output parameter) The extracted string.
     786                 :            : 
     787                 :            :         @param rTokens  The token sequence to be parsed. Should contain exactly
     788                 :            :             one string token, may contain whitespace tokens.
     789                 :            : 
     790                 :            :         @return  True = token sequence is valid, output parameter orString
     791                 :            :             contains the string extracted from the token sequence.
     792                 :            :      */
     793                 :            :     bool                extractString(
     794                 :            :                             ::rtl::OUString& orString,
     795                 :            :                             const ApiTokenSequence& rTokens ) const;
     796                 :            : 
     797                 :            :     /** Tries to extract information about a special token used for array
     798                 :            :         formulas, shared formulas, or table operations.
     799                 :            : 
     800                 :            :         @param orTokenInfo  (output parameter) The extracted information about
     801                 :            :             the token. Contains the base address and the token type (sal_False
     802                 :            :             for array or shared formulas, sal_True for table operations).
     803                 :            : 
     804                 :            :         @param rTokens  The token sequence to be parsed. If it contains exactly
     805                 :            :             one OPCODE_BAD token with special token information, this
     806                 :            :             information will be extracted.
     807                 :            : 
     808                 :            :         @return  True = token sequence is valid, output parameter orTokenInfo
     809                 :            :             contains the token information extracted from the token sequence.
     810                 :            :      */
     811                 :            :     bool                extractSpecialTokenInfo(
     812                 :            :                             ApiSpecialTokenInfo& orTokenInfo,
     813                 :            :                             const ApiTokenSequence& rTokens ) const;
     814                 :            : 
     815                 :            :     /** Converts a single string with separators in the passed formula token
     816                 :            :         sequence to a list of string tokens.
     817                 :            : 
     818                 :            :         @param orTokens  (input/output parameter) Expects a single string token
     819                 :            :             in this token sequence (whitespace tokens are allowed). The string
     820                 :            :             is split into substrings. A list of string tokens separated with
     821                 :            :             parameter separator tokens is returned in this psrameter.
     822                 :            : 
     823                 :            :         @param cStringSep  The separator character used to split the input
     824                 :            :             string.
     825                 :            : 
     826                 :            :         @param bTrimLeadingSpaces  True = removes leading whitespace from all
     827                 :            :             substrings inserted into the formula token sequence.
     828                 :            :      */
     829                 :            :     void                convertStringToStringList(
     830                 :            :                             ApiTokenSequence& orTokens,
     831                 :            :                             sal_Unicode cStringSep,
     832                 :            :                             bool bTrimLeadingSpaces ) const;
     833                 :            : };
     834                 :            : 
     835                 :            : // ============================================================================
     836                 :            : 
     837                 :            : } // namespace xls
     838                 :            : } // namespace oox
     839                 :            : 
     840                 :            : #endif
     841                 :            : 
     842                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10