LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - lwptblformula.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 269 0.0 %
Date: 2014-11-03 Functions: 0 32 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*************************************************************************
       3             :  *
       4             :  *  The Contents of this file are made available subject to the terms of
       5             :  *  either of the following licenses
       6             :  *
       7             :  *         - GNU Lesser General Public License Version 2.1
       8             :  *         - Sun Industry Standards Source License Version 1.1
       9             :  *
      10             :  *  Sun Microsystems Inc., October, 2000
      11             :  *
      12             :  *  GNU Lesser General Public License Version 2.1
      13             :  *  =============================================
      14             :  *  Copyright 2000 by Sun Microsystems, Inc.
      15             :  *  901 San Antonio Road, Palo Alto, CA 94303, USA
      16             :  *
      17             :  *  This library is free software; you can redistribute it and/or
      18             :  *  modify it under the terms of the GNU Lesser General Public
      19             :  *  License version 2.1, as published by the Free Software Foundation.
      20             :  *
      21             :  *  This library is distributed in the hope that it will be useful,
      22             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      23             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      24             :  *  Lesser General Public License for more details.
      25             :  *
      26             :  *  You should have received a copy of the GNU Lesser General Public
      27             :  *  License along with this library; if not, write to the Free Software
      28             :  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      29             :  *  MA  02111-1307  USA
      30             :  *
      31             :  *
      32             :  *  Sun Industry Standards Source License Version 1.1
      33             :  *  =================================================
      34             :  *  The contents of this file are subject to the Sun Industry Standards
      35             :  *  Source License Version 1.1 (the "License"); You may not use this file
      36             :  *  except in compliance with the License. You may obtain a copy of the
      37             :  *  License at http://www.openoffice.org/license.html.
      38             :  *
      39             :  *  Software provided under this License is provided on an "AS IS" basis,
      40             :  *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
      41             :  *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
      42             :  *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
      43             :  *  See the License for the specific provisions governing your rights and
      44             :  *  obligations concerning the Software.
      45             :  *
      46             :  *  The Initial Developer of the Original Code is: IBM Corporation
      47             :  *
      48             :  *  Copyright: 2008 by IBM Corporation
      49             :  *
      50             :  *  All Rights Reserved.
      51             :  *
      52             :  *  Contributor(s): _______________________________________
      53             :  *
      54             :  *
      55             :  ************************************************************************/
      56             : /**
      57             :  * @file
      58             :  *  For LWP filter architecture prototype - table cell numerics format
      59             :  */
      60             : /*************************************************************************
      61             :  * Change History
      62             :  Mar 2005           Created
      63             :  ************************************************************************/
      64             : 
      65             : #include "lwpoverride.hxx"
      66             : #include "lwptblcell.hxx"
      67             : #include "lwppara.hxx"
      68             : #include "lwptblformula.hxx"
      69             : 
      70             : #include "lwptablelayout.hxx"
      71             : #include <osl/thread.h>
      72             : #include <rtl/ustrbuf.hxx>
      73             : #include <boost/scoped_array.hpp>
      74             : 
      75           0 : LwpFormulaArg::~LwpFormulaArg()
      76             : {
      77           0 : }
      78             : 
      79           0 :  LwpFormulaInfo::LwpFormulaInfo(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
      80             :     : LwpCellList(objHdr, pStrm)
      81             :     , m_bSupported(true)
      82           0 :     , m_nFormulaRow(0)
      83           0 : {}
      84             : 
      85           0 : LwpFormulaInfo::~LwpFormulaInfo()
      86             : {
      87             :     try{
      88           0 :         while(m_aStack.size()>0)
      89             :         {
      90           0 :             LwpFormulaArg* pArg=m_aStack.back();
      91           0 :             m_aStack.pop_back();
      92           0 :             delete pArg; pArg=NULL;
      93             :         }
      94             :     }catch (...)
      95             :     {
      96             :         assert(false);
      97             :     }
      98           0 : }
      99             : 
     100             : /**
     101             : *
     102             : *   @date   03/26/2005
     103             : *   @param
     104             : *   @param
     105             : *   @return sal_Bool.
     106             : */
     107           0 : bool LwpFormulaInfo::ReadConst()
     108             : {
     109           0 :     double Constant = m_pObjStrm->QuickReadDouble();
     110             : 
     111           0 :     m_aStack.push_back( new LwpFormulaConst(Constant) );
     112             : 
     113           0 :     return true;
     114             : }
     115             : /**
     116             : *   Need more effort for unicode.
     117             : *   @date   03/26/2005
     118             : *   @param
     119             : *   @param
     120             : *   @return sal_Bool.
     121             : */
     122           0 : bool LwpFormulaInfo::ReadText()
     123             : {
     124           0 :     m_pObjStrm->QuickReadInt16(); //Disk Size
     125           0 :     sal_uInt16 nStrLen = m_pObjStrm->QuickReadInt16();
     126             : 
     127           0 :     boost::scoped_array<char> pBuf(new char[nStrLen+1]);
     128           0 :     m_pObjStrm->QuickRead( pBuf.get(), nStrLen );
     129           0 :     *(pBuf.get()+nStrLen)='\0';
     130           0 :     OUString aText;
     131           0 :     aText += "\"";
     132           0 :     aText += OUString(pBuf.get(), nStrLen, osl_getThreadTextEncoding());
     133           0 :     aText += "\"";
     134             : 
     135           0 :     m_aStack.push_back(new LwpFormulaText(aText));
     136           0 :     return true;
     137             : }
     138             : /**
     139             : *
     140             : *   @date   03/26/2005
     141             : *   @param
     142             : *   @param
     143             : *   @return sal_Bool.
     144             : */
     145           0 : bool LwpFormulaInfo::ReadCellID()
     146             : {
     147           0 :     LwpRowSpecifier RowSpecifier;
     148           0 :     LwpColumnSpecifier ColumnSpecifier;
     149           0 :     bool readSucceeded = true;
     150             : 
     151           0 :     RowSpecifier.QuickRead(m_pObjStrm);
     152           0 :     ColumnSpecifier.QuickRead(m_pObjStrm);
     153             : 
     154           0 :     m_aStack.push_back( new LwpFormulaCellAddr(ColumnSpecifier.ColumnID(cColumn),
     155           0 :                                                 RowSpecifier.RowID(m_nFormulaRow)) );
     156           0 :     return readSucceeded;
     157             : }
     158             : /**
     159             : *
     160             : *   @date   03/26/2005
     161             : *   @param
     162             : *   @param
     163             : *   @return sal_Bool.
     164             : */
     165           0 : bool LwpFormulaInfo::ReadCellRange()
     166             : {
     167           0 :     bool readSucceeded = true;
     168           0 :     if (!ReadCellID( )) // start
     169           0 :         readSucceeded = false;
     170           0 :     LwpFormulaCellAddr* pStartCellAddr = static_cast<LwpFormulaCellAddr*>(m_aStack.back());
     171           0 :     m_aStack.pop_back();
     172             : 
     173           0 :     if (!ReadCellID()) // end
     174           0 :         readSucceeded = false;
     175           0 :     LwpFormulaCellAddr* pEndCellAddr = static_cast<LwpFormulaCellAddr*>(m_aStack.back());
     176           0 :     m_aStack.pop_back();
     177             : 
     178           0 :     m_aStack.push_back( new LwpFormulaCellRangeAddr(pStartCellAddr->GetCol(),
     179           0 :                                                     pStartCellAddr->GetRow(),
     180           0 :                                                     pEndCellAddr->GetCol(),
     181           0 :                                                     pEndCellAddr->GetRow()) );
     182           0 :     delete pStartCellAddr;
     183           0 :     delete pEndCellAddr;
     184             : 
     185           0 :     return readSucceeded;
     186             : }
     187             : 
     188             : /**
     189             : *   Read expression from wordpro file
     190             : *   @date   03/26/2005
     191             : *   @param
     192             : *   @param
     193             : *   @return sal_Bool.
     194             : */
     195           0 : bool LwpFormulaInfo::ReadExpression()
     196             : {
     197             :     sal_uInt16 TokenType, DiskLength;
     198           0 :     bool readSucceeded = true;
     199             : 
     200             :     /* Read the compiled expression length */
     201             : //  Len = m_pObjStrm->QuickReaduInt16();
     202           0 :     m_pObjStrm->SeekRel(2);
     203             : 
     204           0 :     while ((TokenType = m_pObjStrm->QuickReaduInt16()) != TK_END)
     205             :     {
     206             :         // Get the disk length of this token
     207           0 :         DiskLength = m_pObjStrm->QuickReaduInt16();
     208             : 
     209           0 :         switch (TokenType)
     210             :         {
     211             :             case TK_CONSTANT:
     212             :             {
     213           0 :                 ReadConst();
     214           0 :                 break;
     215             :             }
     216             : 
     217             :             case TK_CELLID:
     218           0 :                 if (!ReadCellID())
     219           0 :                     readSucceeded = false;
     220           0 :                 break;
     221             : 
     222             :             case TK_CELLRANGE:
     223           0 :                 readSucceeded = ReadCellRange();
     224           0 :                 break;
     225             : 
     226             :             case TK_SUM:
     227             :             case TK_IF:
     228             :             case TK_COUNT:
     229             :             case TK_MINIMUM:
     230             :             case TK_MAXIMUM:
     231             :             case TK_AVERAGE:
     232             :                 {
     233           0 :                     LwpFormulaFunc* pFunc = new LwpFormulaFunc(TokenType);
     234           0 :                     if (!ReadArguments(*pFunc))
     235           0 :                         readSucceeded = false;
     236           0 :                     m_aStack.push_back(pFunc);
     237             :                 }
     238           0 :                 break;
     239             : 
     240             :             case TK_ADD://7
     241             :             case TK_SUBTRACT:
     242             :             case TK_MULTIPLY:
     243             :             case TK_DIVIDE:
     244             :             case TK_LESS:
     245             :             case TK_LESS_OR_EQUAL:
     246             :             case TK_GREATER:
     247             :             case TK_GREATER_OR_EQUAL:
     248             :             case TK_EQUAL:
     249             :             case TK_NOT_EQUAL:
     250             :             case TK_AND:
     251             :             case TK_OR:
     252             :             case TK_NOT:
     253           0 :                 m_pObjStrm->SeekRel(DiskLength); // extensible for future
     254             : 
     255             :                 {//binary operator
     256           0 :                     LwpFormulaOp* pOp = new LwpFormulaOp(TokenType);
     257           0 :                     pOp->AddArg(m_aStack.back()); m_aStack.pop_back();
     258           0 :                     pOp->AddArg(m_aStack.back()); m_aStack.pop_back();
     259           0 :                     m_aStack.push_back(pOp);
     260             :                 }
     261           0 :                 break;
     262             :             case TK_UNARY_MINUS:
     263             :                 {
     264           0 :                     LwpFormulaUnaryOp* pOp = new LwpFormulaUnaryOp(TokenType);
     265           0 :                     pOp->AddArg(m_aStack.back()); m_aStack.pop_back();
     266           0 :                     m_aStack.push_back(pOp);
     267             :                 }
     268           0 :                 break;
     269             :             default:
     270             :                 // We don't know what to do with this token, so eat it.
     271           0 :                 m_pObjStrm->SeekRel(DiskLength);
     272           0 :                 readSucceeded = false;
     273           0 :                 break;
     274             :         }
     275           0 :         MarkUnsupported(TokenType);
     276             :     }
     277           0 :     return readSucceeded;
     278             : }
     279             : 
     280             : /**
     281             : *
     282             : *   @date   03/26/2005
     283             : *   @param
     284             : *   @param
     285             : *   @return
     286             : */
     287           0 : void LwpFormulaInfo::MarkUnsupported(sal_uInt16 TokenType)
     288             : {
     289           0 :     switch(TokenType)
     290             :     {
     291             :     case TK_IF:
     292             :     case TK_COUNT:
     293             :     case TK_NOT:
     294             :         {
     295           0 :             m_bSupported = false;//Not supported formulas
     296             :         }
     297           0 :         break;
     298             :     default:
     299           0 :         break;
     300             :     }
     301           0 : }
     302             : /**
     303             : *   Read arguments of functions from wordpro file
     304             : *   @date   03/26/2005
     305             : *   @param  LwpFormulaFunc& aFunc, functions object
     306             : *   @return sal_Bool.
     307             : */
     308           0 : bool LwpFormulaInfo::ReadArguments(LwpFormulaFunc& aFunc)
     309             : {
     310           0 :     sal_uInt16 NumberOfArguments = m_pObjStrm->QuickReaduInt16();
     311             :     sal_uInt16 ArgumentDiskLength, Count;
     312             :     sal_uInt8 ArgumentType;
     313           0 :     bool bArgument = false;
     314           0 :     bool readSucceeded = true;
     315             : 
     316           0 :     for (Count = 0; Count < NumberOfArguments; Count++)
     317             :     {
     318           0 :         ArgumentType = (sal_uInt8) m_pObjStrm->QuickReaduInt16(); // written as lushort
     319           0 :         ArgumentDiskLength = m_pObjStrm->QuickReaduInt16();
     320           0 :         bArgument = true;
     321             : 
     322           0 :         switch(ArgumentType)
     323             :         {
     324             :             case TK_CELLID:
     325           0 :                 ReadCellID();
     326           0 :                 break;
     327             : 
     328             :             case TK_CELLRANGE:
     329           0 :                 ReadCellRange();
     330           0 :                 break;
     331             : 
     332             :             case TK_CONSTANT:
     333           0 :                 ReadConst();
     334           0 :                 break;
     335             : 
     336             :             case TK_TEXT:
     337           0 :                 ReadText();
     338           0 :                 break;
     339             : 
     340             :             case TK_EXPRESSION:
     341           0 :                 ReadExpression();
     342           0 :                 break;
     343             : 
     344             :             default:
     345           0 :                 bArgument = false;
     346           0 :                 m_pObjStrm->SeekRel(ArgumentDiskLength);
     347           0 :                 readSucceeded = false;
     348           0 :                 break;
     349             :         }
     350             : 
     351           0 :         if (bArgument)
     352             :         {
     353           0 :             aFunc.AddArg( m_aStack.back() );
     354           0 :             m_aStack.pop_back();
     355             :         }
     356             :     }
     357           0 :     return readSucceeded;
     358             : }
     359             : 
     360             : /**
     361             : *
     362             : *   @date   03/26/2005
     363             : *   @param
     364             : *   @param
     365             : *   @return
     366             : */
     367           0 : void LwpFormulaInfo::Read()
     368             : {
     369           0 :     LwpCellList::Read();
     370             :     {
     371           0 :         LwpRowList* pRowList = static_cast<LwpRowList*>(cParent.obj().get());
     372           0 :         if (pRowList)
     373             :         {
     374           0 :             m_nFormulaRow = pRowList->GetRowID();
     375             :         }
     376             :         else
     377             :         {
     378             :             assert(false);
     379             :         }
     380             :     }
     381             : //  sal_uInt8 cFlags = (sal_uInt8) m_pObjStrm->QuickReaduInt16(); // written as a sal_uInt16
     382           0 :     m_pObjStrm->SeekRel(2);//flags, size in file: sal_uInt16
     383             : 
     384           0 :     LwpNotifyListPersistent cNotifyList;
     385           0 :     cNotifyList.Read(m_pObjStrm);
     386             : 
     387           0 :     ReadExpression();
     388             : 
     389           0 :     m_pObjStrm->SkipExtra();
     390           0 : }
     391             : 
     392             : /**
     393             : *   Make the formula string.
     394             : *   @date   03/26/2005
     395             : *   @param
     396             : *   @param
     397             : *   @return sal_Bool.
     398             : */
     399           0 : OUString  LwpFormulaInfo::Convert(LwpTableLayout* pCellsMap)
     400             : {
     401           0 :     OUString aFormula;
     402           0 :     if (m_bSupported)
     403             :     {
     404           0 :         if(1==m_aStack.size())
     405             :         {
     406           0 :             LwpFormulaArg* pFormula = m_aStack.back();
     407           0 :             aFormula = pFormula->ToString(pCellsMap);
     408             :         }
     409             :         else
     410             :         {
     411             :             assert(false);
     412             :         }
     413             :     }
     414           0 :     return aFormula;
     415             : }
     416             : 
     417             : /**
     418             : *   Fill the XFCell content
     419             : *   @date   03/26/2005
     420             : *   @param
     421             : *   @param
     422             : *   @return sal_Bool.
     423             : */
     424           0 : void LwpFormulaInfo::Convert(XFCell * pCell,LwpTableLayout* pCellsMap)
     425             : {
     426           0 :     OUString aFormula;
     427           0 :     aFormula = Convert(pCellsMap);
     428           0 :     if (!aFormula.isEmpty())
     429             :     {
     430           0 :         pCell->SetFormula(aFormula);
     431             :     }
     432           0 :     LwpCellList::Convert(pCell);
     433           0 : }
     434             : 
     435             : /**
     436             : *
     437             : *   @date   03/26/2005
     438             : *   @param
     439             : *   @param
     440             : *   @return sal_Bool.
     441             : */
     442           0 : LwpFormulaConst::LwpFormulaConst(double dVal)
     443             : {
     444           0 :     m_dVal = dVal;
     445           0 : }
     446             : 
     447           0 : OUString LwpFormulaConst::ToString(LwpTableLayout* /*pCellsMap*/)
     448             : {
     449           0 :     return OUString::number(m_dVal);
     450             : }
     451             : 
     452             : /**
     453             : *
     454             : *   @date   03/26/2005
     455             : *   @param
     456             : *   @param
     457             : *   @return
     458             : */
     459           0 : LwpFormulaText::LwpFormulaText( const OUString& aText)
     460             : {
     461           0 :     m_aText = aText;
     462           0 : }
     463             : 
     464             : /**
     465             : *
     466             : *   @date   03/26/2005
     467             : *   @param
     468             : *   @param
     469             : *   @return
     470             : */
     471           0 : LwpFormulaCellAddr::LwpFormulaCellAddr(sal_Int16 aCol, sal_Int16 aRow)
     472             : {
     473           0 :     m_aCol = aCol;
     474           0 :     m_aRow = aRow;
     475           0 : }
     476             : 
     477             : /**
     478             : *
     479             : *   @date   03/26/2005
     480             : *   @param
     481             : *   @param
     482             : *   @return String
     483             : */
     484           0 : OUString LwpFormulaCellAddr::ToString(LwpTableLayout* pCellsMap)
     485             : {
     486           0 :     OUString aCellAddr = "<" + LwpFormulaTools::GetCellAddr(m_aRow,m_aCol,pCellsMap) + ">";
     487           0 :     return aCellAddr;
     488             : }
     489             : 
     490             : /**
     491             : *
     492             : *   @date   03/26/2005
     493             : *   @param
     494             : *   @param
     495             : *   @return
     496             : */
     497           0 : LwpFormulaCellRangeAddr::LwpFormulaCellRangeAddr(sal_Int16 aStartCol,
     498             :                                                  sal_Int16 aStartRow,
     499             :                                                  sal_Int16 aEndCol,
     500           0 :                                                  sal_Int16 aEndRow)
     501             : {
     502           0 :     m_aStartCol = aStartCol;
     503           0 :     m_aStartRow = aStartRow;
     504           0 :     m_aEndCol = aEndCol;
     505           0 :     m_aEndRow = aEndRow;
     506           0 : }
     507             : 
     508             : /**
     509             : *   Convert the cell range into a string
     510             : *   @date   03/26/2005
     511             : *   @param
     512             : *   @param
     513             : *   @return String.
     514             : */
     515           0 : OUString LwpFormulaCellRangeAddr::ToString(LwpTableLayout* pCellsMap)
     516             : {
     517             :     OUString aCellAddr = "<"
     518           0 :         + LwpFormulaTools::GetCellAddr(m_aStartRow,m_aStartCol,pCellsMap) + ":"
     519           0 :         + LwpFormulaTools::GetCellAddr(m_aEndRow,m_aEndCol,pCellsMap) + ">";
     520             : 
     521           0 :     return aCellAddr;
     522             : }
     523             : 
     524             : /**
     525             : *
     526             : *   @date   03/26/2005
     527             : *   @param
     528             : *   @param
     529             : *   @return
     530             : */
     531           0 : LwpFormulaFunc::LwpFormulaFunc(sal_uInt16 nTokenType)
     532             : {
     533           0 :     m_nTokenType = nTokenType;
     534           0 : }
     535             : 
     536             : /**
     537             : *
     538             : *   @date   03/26/2005
     539             : *   @param
     540             : *   @param
     541             : *   @return
     542             : */
     543           0 : LwpFormulaFunc::~LwpFormulaFunc()
     544             : {
     545             :     try
     546             :     {
     547           0 :         while(m_aArgs.size()>0)
     548             :         {
     549           0 :             LwpFormulaArg* pArg = m_aArgs.back();
     550           0 :             m_aArgs.pop_back();
     551           0 :             delete pArg;pArg=NULL;
     552             :         }
     553             :     }catch (...) {
     554             :         assert(false);
     555             :     }
     556             : 
     557           0 : }
     558             : /**
     559             : *
     560             : *   @date   03/26/2005
     561             : *   @param
     562             : *   @param
     563             : *   @return
     564             : */
     565           0 : void LwpFormulaFunc::AddArg(LwpFormulaArg* pArg)
     566             : {
     567           0 :     m_aArgs.push_back(pArg);
     568           0 : }
     569             : /**
     570             : *   Convert the functions to a string, which is a argument of other formula
     571             : *   @date   03/26/2005
     572             : *   @param
     573             : *   @param
     574             : *   @return  String.
     575             : */
     576           0 : OUString LwpFormulaFunc::ToArgString(LwpTableLayout* pCellsMap)
     577             : {
     578           0 :     OUStringBuffer aFormula;
     579           0 :     aFormula.append('(');
     580           0 :     aFormula.append(ToString(pCellsMap));
     581           0 :     aFormula.append(')');
     582           0 :     return aFormula.makeStringAndClear();
     583             : }
     584             : /**
     585             : *   Convert the function to a formula string.
     586             : *   @date   03/26/2005
     587             : *   @param
     588             : *   @param
     589             : *   @return sal_Bool.
     590             : */
     591           0 : OUString LwpFormulaFunc::ToString(LwpTableLayout* pCellsMap)
     592             : {
     593           0 :     OUString aFormula;
     594             : 
     595           0 :     OUString aFuncName = LwpFormulaTools::GetName(m_nTokenType);
     596           0 :     aFormula += aFuncName;
     597           0 :     aFormula += " ";//Append a blank space
     598             : 
     599             :     //Append args
     600           0 :     std::vector<LwpFormulaArg*>::iterator aItr;
     601           0 :     for (aItr=m_aArgs.begin();aItr!=m_aArgs.end();++aItr)
     602             :     {
     603           0 :         aFormula += (*aItr)->ToArgString(pCellsMap) + "|"; //separator
     604             :     }
     605             : 
     606             :     //erase the last "|"
     607           0 :     if (!m_aArgs.empty())
     608             :     {
     609           0 :         aFormula = aFormula.replaceAt(aFormula.getLength()-1,1,"");
     610             :     }
     611             :     else
     612             :     {
     613             :         assert(false);
     614             :     }
     615             : 
     616           0 :     return aFormula;
     617             : }
     618             : 
     619             : /**
     620             : *   Convert the formula in operators to a string : e.g. 1+2+3
     621             : *   @date   03/26/2005
     622             : *   @param
     623             : *   @param
     624             : *   @return sal_Bool.
     625             : */
     626           0 : OUString LwpFormulaOp::ToString(LwpTableLayout* pCellsMap)
     627             : {
     628           0 :     OUString aFormula;
     629           0 :     if (2==m_aArgs.size())
     630             :     {
     631           0 :         std::vector<LwpFormulaArg*>::iterator aItr = m_aArgs.end();
     632           0 :         --aItr;
     633             : 
     634           0 :         aFormula += (*aItr)->ToArgString(pCellsMap) + " ";
     635           0 :         OUString aFuncName = LwpFormulaTools::GetName(m_nTokenType);
     636             : 
     637           0 :         aFormula += aFuncName + " ";
     638             : 
     639           0 :         --aItr;
     640           0 :         aFormula += (*aItr)->ToArgString(pCellsMap);
     641             :     }
     642             :     else
     643             :     {
     644             :         assert(false);
     645             :     }
     646           0 :     return aFormula;
     647             : }
     648             : 
     649             : /**
     650             : *   convert the formula in unary operators into string : e.g. -2
     651             : *   @date   03/26/2005
     652             : *   @param
     653             : *   @param
     654             : *   @return sal_Bool.
     655             : */
     656           0 : OUString LwpFormulaUnaryOp::ToString(LwpTableLayout* pCellsMap)
     657             : {
     658           0 :     OUString aFormula;
     659           0 :     if (1==m_aArgs.size())
     660             :     {
     661           0 :         OUString aFuncName = LwpFormulaTools::GetName(m_nTokenType);
     662           0 :         aFormula += aFuncName;
     663             : 
     664           0 :         std::vector<LwpFormulaArg*>::iterator aItr = m_aArgs.begin();
     665           0 :         aFormula += (*aItr)->ToArgString(pCellsMap);
     666             :     }
     667             :     else
     668             :     {
     669             :         assert(false);
     670             :     }
     671           0 :     return aFormula;
     672             : }
     673             : /**
     674             : *   Get token name
     675             : *   @date   03/26/2005
     676             : *   @param
     677             : *   @param
     678             : *   @return String.
     679             : */
     680           0 : OUString LwpFormulaTools::GetName(sal_uInt16 nTokenType)
     681             : {
     682           0 :     OUString aName;
     683           0 :     switch(nTokenType)
     684             :     {
     685             :     case TK_SUM:
     686           0 :         aName = "SUM";
     687           0 :         break;
     688             :     case TK_IF:
     689           0 :         aName = "IF";//Not supported by SODC
     690           0 :         break;
     691             :     case TK_COUNT:
     692           0 :         aName = "COUNT";//Not supported by SODC
     693           0 :         break;
     694             :     case TK_MINIMUM:
     695           0 :         aName = "MIN";
     696           0 :         break;
     697             :     case TK_MAXIMUM:
     698           0 :         aName = "MAX";
     699           0 :         break;
     700             :     case TK_AVERAGE:
     701           0 :         aName = "MEAN";
     702           0 :         break;
     703             :     case TK_ADD:
     704           0 :         aName = "+";
     705           0 :         break;
     706             :     case TK_SUBTRACT:
     707           0 :         aName = "-";
     708           0 :         break;
     709             :     case TK_MULTIPLY:
     710           0 :         aName = "*";
     711           0 :         break;
     712             :     case TK_DIVIDE:
     713           0 :         aName = "/";
     714           0 :         break;
     715             :     case TK_UNARY_MINUS:
     716           0 :         aName = "-";
     717           0 :         break;
     718             :     case TK_LESS:
     719           0 :         aName = "L";
     720           0 :         break;
     721             :     case TK_LESS_OR_EQUAL:
     722           0 :         aName = "LEQ";
     723           0 :         break;
     724             :     case TK_GREATER:
     725           0 :         aName = "G";
     726           0 :         break;
     727             :     case TK_GREATER_OR_EQUAL:
     728           0 :         aName = "GEQ";
     729           0 :         break;
     730             :     case TK_EQUAL:
     731           0 :         aName = "EQ";
     732           0 :         break;
     733             :     case TK_NOT_EQUAL:
     734           0 :         aName = "NEQ";
     735           0 :         break;
     736             :     case TK_NOT:
     737           0 :         aName = "NOT";
     738           0 :         break;
     739             :     case TK_AND:
     740           0 :         aName = "AND";
     741           0 :         break;
     742             :     case TK_OR:
     743           0 :         aName = "OR";
     744           0 :         break;
     745             :     default:
     746             :         assert(false);
     747           0 :         break;
     748             :     }
     749           0 :     return aName;
     750             : }
     751             : 
     752             : /**
     753             : *   Get cell address in String
     754             : *   @date   03/26/2005
     755             : *   @param
     756             : *   @param
     757             : *   @return String.
     758             : */
     759           0 : OUString LwpFormulaTools::GetCellAddr(sal_Int16 nRow, sal_Int16 nCol, LwpTableLayout* pCellsMap)
     760             : {
     761           0 :     OUString aCellAddr;
     762           0 :     XFCell* pCell = pCellsMap->GetCellsMap(nRow,(sal_uInt8)nCol);
     763           0 :     if (pCell)
     764             :     {
     765           0 :         aCellAddr = pCell->GetCellName();
     766             :     }
     767             :     else
     768             :     {
     769             :         assert( -1==nRow || -1==(sal_Int8)nCol);
     770             :     }
     771           0 :     return aCellAddr;
     772             : }
     773             : 
     774             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10