LCOV - code coverage report
Current view: top level - libreoffice/lotuswordpro/source/filter - lwptblformula.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 281 0.0 %
Date: 2012-12-27 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 <rtl/ustrbuf.hxx>
      72             : #include <boost/scoped_array.hpp>
      73             : 
      74           0 : LwpFormulaArg::~LwpFormulaArg()
      75             : {
      76           0 : }
      77             : 
      78             : //////////////////////////////////////////////////////////////////
      79           0 :  LwpFormulaInfo::LwpFormulaInfo(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
      80             :     : LwpCellList(objHdr, pStrm)
      81             :     , m_bSupported(sal_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           0 :     }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 : sal_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 sal_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 : sal_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 :     String aText;
     131           0 :     aText += rtl::OUString("\"");
     132           0 :     aText.Append(String(pBuf.get(),nStrLen,osl_getThreadTextEncoding()));
     133           0 :     aText += rtl::OUString("\"");
     134             : 
     135           0 :     m_aStack.push_back(new LwpFormulaText(aText));
     136           0 :     return sal_True;
     137             : }
     138             : /**
     139             : *
     140             : *   @date   03/26/2005
     141             : *   @param
     142             : *   @param
     143             : *   @return sal_Bool.
     144             : */
     145           0 : sal_Bool LwpFormulaInfo::ReadCellID()
     146             : {
     147           0 :     LwpRowSpecifier RowSpecifier;
     148           0 :     LwpColumnSpecifier ColumnSpecifier;
     149           0 :     sal_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 : sal_Bool LwpFormulaInfo::ReadCellRange()
     166             : {
     167           0 :     sal_Bool readSucceeded = sal_True;
     168           0 :     if (!ReadCellID( )) // start
     169           0 :         readSucceeded = false;
     170           0 :     LwpFormulaCellAddr* pStartCellAddr = (LwpFormulaCellAddr*)m_aStack.back();
     171           0 :     m_aStack.pop_back();
     172             : 
     173           0 :     if (!ReadCellID()) // end
     174           0 :         readSucceeded = false;
     175           0 :     LwpFormulaCellAddr* pEndCellAddr = (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 : sal_Bool LwpFormulaInfo::ReadExpression()
     196             : {
     197             :     sal_uInt16 TokenType, DiskLength;
     198           0 :     sal_Bool readSucceeded = sal_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 = sal_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 = sal_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 = sal_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 = sal_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 : sal_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 :     sal_Bool bArgument = sal_False;
     314           0 :     sal_Bool readSucceeded = sal_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 = sal_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 = sal_False;
     346           0 :                 m_pObjStrm->SeekRel(ArgumentDiskLength);
     347           0 :                 readSucceeded = sal_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 =(LwpRowList*)cParent.obj();
     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 : String  LwpFormulaInfo::Convert(LwpTableLayout* pCellsMap)
     400             : {
     401           0 :     String 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 :     String aFormula;
     427           0 :     aFormula = Convert(pCellsMap);
     428           0 :     if (aFormula.Len())
     429             :     {
     430           0 :         pCell->SetFormula(aFormula);
     431             :     }
     432           0 :     LwpCellList::Convert(pCell);
     433           0 : }
     434             : 
     435             : //////////////////////////////////////////////////////////////////
     436             : 
     437             : /**
     438             : *
     439             : *   @date   03/26/2005
     440             : *   @param
     441             : *   @param
     442             : *   @return sal_Bool.
     443             : */
     444           0 : LwpFormulaConst::LwpFormulaConst(double dVal)
     445             : {
     446           0 :     m_dVal = dVal;
     447           0 : }
     448             : 
     449           0 : rtl::OUString LwpFormulaConst::ToString(LwpTableLayout* /*pCellsMap*/)
     450             : {
     451           0 :     return rtl::OUString::valueOf(m_dVal);
     452             : }
     453             : 
     454             : /**
     455             : *
     456             : *   @date   03/26/2005
     457             : *   @param
     458             : *   @param
     459             : *   @return
     460             : */
     461           0 : LwpFormulaText::LwpFormulaText( String aText)
     462             : {
     463           0 :     m_aText = aText;
     464           0 : }
     465             : 
     466             : /**
     467             : *
     468             : *   @date   03/26/2005
     469             : *   @param
     470             : *   @param
     471             : *   @return
     472             : */
     473           0 : LwpFormulaCellAddr::LwpFormulaCellAddr(sal_Int16 aCol, sal_Int16 aRow)
     474             : {
     475           0 :     m_aCol = aCol;
     476           0 :     m_aRow = aRow;
     477           0 : }
     478             : 
     479             : /**
     480             : *
     481             : *   @date   03/26/2005
     482             : *   @param
     483             : *   @param
     484             : *   @return String
     485             : */
     486           0 : rtl::OUString LwpFormulaCellAddr::ToString(LwpTableLayout* pCellsMap)
     487             : {
     488           0 :     String aCellAddr;
     489           0 :     aCellAddr.AppendAscii("<");//&lt;
     490             : 
     491           0 :     aCellAddr += LwpFormulaTools::GetCellAddr(m_aRow,m_aCol,pCellsMap);
     492             : 
     493           0 :     aCellAddr.AppendAscii(">");//&gt;
     494           0 :     return aCellAddr;
     495             : }
     496             : 
     497             : /**
     498             : *
     499             : *   @date   03/26/2005
     500             : *   @param
     501             : *   @param
     502             : *   @return
     503             : */
     504           0 : LwpFormulaCellRangeAddr::LwpFormulaCellRangeAddr(sal_Int16 aStartCol,
     505             :                                                  sal_Int16 aStartRow,
     506             :                                                  sal_Int16 aEndCol,
     507           0 :                                                  sal_Int16 aEndRow)
     508             : {
     509           0 :     m_aStartCol = aStartCol;
     510           0 :     m_aStartRow = aStartRow;
     511           0 :     m_aEndCol = aEndCol;
     512           0 :     m_aEndRow = aEndRow;
     513           0 : }
     514             : 
     515             : /**
     516             : *   Convert the cell range into a string
     517             : *   @date   03/26/2005
     518             : *   @param
     519             : *   @param
     520             : *   @return String.
     521             : */
     522           0 : rtl::OUString LwpFormulaCellRangeAddr::ToString(LwpTableLayout* pCellsMap)
     523             : {
     524           0 :     String aCellAddr;
     525           0 :     aCellAddr.AppendAscii("<");//&lt;
     526             : 
     527           0 :     aCellAddr += LwpFormulaTools::GetCellAddr(m_aStartRow,m_aStartCol,pCellsMap);
     528           0 :     aCellAddr.AppendAscii(":");
     529           0 :     aCellAddr += LwpFormulaTools::GetCellAddr(m_aEndRow,m_aEndCol,pCellsMap);
     530             : 
     531           0 :     aCellAddr.AppendAscii(">");//&gt;
     532             : 
     533           0 :     return aCellAddr;
     534             : }
     535             : 
     536             : /**
     537             : *
     538             : *   @date   03/26/2005
     539             : *   @param
     540             : *   @param
     541             : *   @return
     542             : */
     543           0 : LwpFormulaFunc::LwpFormulaFunc(sal_uInt16 nTokenType)
     544             : {
     545           0 :     m_nTokenType = nTokenType;
     546           0 : }
     547             : 
     548             : /**
     549             : *
     550             : *   @date   03/26/2005
     551             : *   @param
     552             : *   @param
     553             : *   @return
     554             : */
     555           0 : LwpFormulaFunc::~LwpFormulaFunc()
     556             : {
     557             :     try
     558             :     {
     559           0 :         while(m_aArgs.size()>0)
     560             :         {
     561           0 :             LwpFormulaArg* pArg = m_aArgs.back();
     562           0 :             m_aArgs.pop_back();
     563           0 :             delete pArg;pArg=NULL;
     564             :         }
     565           0 :     }catch (...) {
     566             :         assert(false);
     567             :     }
     568             : 
     569           0 : }
     570             : /**
     571             : *
     572             : *   @date   03/26/2005
     573             : *   @param
     574             : *   @param
     575             : *   @return
     576             : */
     577           0 : void LwpFormulaFunc::AddArg(LwpFormulaArg* pArg)
     578             : {
     579           0 :     m_aArgs.push_back(pArg);
     580           0 : }
     581             : /**
     582             : *   Convert the functions to a string, which is a argument of other formula
     583             : *   @date   03/26/2005
     584             : *   @param
     585             : *   @param
     586             : *   @return  String.
     587             : */
     588           0 : String LwpFormulaFunc::ToArgString(LwpTableLayout* pCellsMap)
     589             : {
     590           0 :     rtl::OUStringBuffer aFormula;
     591           0 :     aFormula.append(static_cast<sal_Unicode>('('));
     592           0 :     aFormula.append(ToString(pCellsMap));
     593           0 :     aFormula.append(static_cast<sal_Unicode>(')'));
     594           0 :     return aFormula.makeStringAndClear();
     595             : }
     596             : /**
     597             : *   Convert the function to a formula string.
     598             : *   @date   03/26/2005
     599             : *   @param
     600             : *   @param
     601             : *   @return sal_Bool.
     602             : */
     603           0 : rtl::OUString LwpFormulaFunc::ToString(LwpTableLayout* pCellsMap)
     604             : {
     605           0 :     String aFormula;
     606             : 
     607           0 :     String aFuncName = LwpFormulaTools::GetName(m_nTokenType);
     608           0 :     aFormula += aFuncName;
     609           0 :     aFormula.AppendAscii(" ");//Append a blank space
     610             : 
     611             :     //Append args
     612           0 :     vector<LwpFormulaArg*>::iterator aItr;
     613           0 :     for (aItr=m_aArgs.begin();aItr!=m_aArgs.end();++aItr)
     614             :     {
     615           0 :         aFormula.Append( (*aItr)->ToArgString(pCellsMap) );
     616           0 :         aFormula.AppendAscii("|");//separator
     617             :     }
     618             : 
     619             :     //erase the last "|"
     620           0 :     if (!m_aArgs.empty())
     621             :     {
     622           0 :         aFormula.Erase(aFormula.Len()-1,1);
     623             :     }
     624             :     else
     625             :     {
     626             :         assert(false);
     627             :     }
     628             : 
     629           0 :     return aFormula;
     630             : }
     631             : 
     632             : /**
     633             : *   Convert the formula in operators to a string : e.g. 1+2+3
     634             : *   @date   03/26/2005
     635             : *   @param
     636             : *   @param
     637             : *   @return sal_Bool.
     638             : */
     639           0 : rtl::OUString LwpFormulaOp::ToString(LwpTableLayout* pCellsMap)
     640             : {
     641           0 :     String aFormula;
     642           0 :     if (2==m_aArgs.size())
     643             :     {
     644           0 :         vector<LwpFormulaArg*>::iterator aItr = m_aArgs.end();
     645           0 :         --aItr;
     646           0 :         aFormula.Append( (*aItr)->ToArgString(pCellsMap) );
     647             : 
     648           0 :         aFormula.AppendAscii(" ");
     649             : 
     650           0 :         String aFuncName = LwpFormulaTools::GetName(m_nTokenType);
     651           0 :         aFormula.Append(aFuncName);
     652             : 
     653           0 :         aFormula.AppendAscii(" ");
     654             : 
     655           0 :         --aItr;
     656           0 :         aFormula.Append( (*aItr)->ToArgString(pCellsMap) );
     657             :     }
     658             :     else
     659             :     {
     660             :         assert(false);
     661             :     }
     662           0 :     return aFormula;
     663             : }
     664             : 
     665             : /**
     666             : *   convert the formula in unary operators into string : e.g. -2
     667             : *   @date   03/26/2005
     668             : *   @param
     669             : *   @param
     670             : *   @return sal_Bool.
     671             : */
     672           0 : rtl::OUString LwpFormulaUnaryOp::ToString(LwpTableLayout* pCellsMap)
     673             : {
     674           0 :     String aFormula;
     675           0 :     if (1==m_aArgs.size())
     676             :     {
     677           0 :         String aFuncName = LwpFormulaTools::GetName(m_nTokenType);
     678           0 :         aFormula.Append(aFuncName);
     679             : 
     680           0 :         vector<LwpFormulaArg*>::iterator aItr = m_aArgs.begin();
     681           0 :         aFormula.Append( (*aItr)->ToArgString(pCellsMap) );
     682             :     }
     683             :     else
     684             :     {
     685             :         assert(false);
     686             :     }
     687           0 :     return aFormula;
     688             : }
     689             : /**
     690             : *   Get token name
     691             : *   @date   03/26/2005
     692             : *   @param
     693             : *   @param
     694             : *   @return String.
     695             : */
     696           0 : String LwpFormulaTools::GetName(sal_uInt16 nTokenType)
     697             : {
     698           0 :     String aName;
     699           0 :     switch(nTokenType)
     700             :     {
     701             :     case TK_SUM:
     702           0 :         aName = rtl::OUString("SUM");
     703           0 :         break;
     704             :     case TK_IF:
     705           0 :         aName = rtl::OUString("IF");//Not supported by SODC
     706           0 :         break;
     707             :     case TK_COUNT:
     708           0 :         aName = rtl::OUString("COUNT");//Not supported by SODC
     709           0 :         break;
     710             :     case TK_MINIMUM:
     711           0 :         aName = rtl::OUString("MIN");
     712           0 :         break;
     713             :     case TK_MAXIMUM:
     714           0 :         aName = rtl::OUString("MAX");
     715           0 :         break;
     716             :     case TK_AVERAGE:
     717           0 :         aName = rtl::OUString("MEAN");
     718           0 :         break;
     719             :     case TK_ADD:
     720           0 :         aName = rtl::OUString("+");
     721           0 :         break;
     722             :     case TK_SUBTRACT:
     723           0 :         aName = rtl::OUString("-");
     724           0 :         break;
     725             :     case TK_MULTIPLY:
     726           0 :         aName = rtl::OUString("*");
     727           0 :         break;
     728             :     case TK_DIVIDE:
     729           0 :         aName = rtl::OUString("/");
     730           0 :         break;
     731             :     case TK_UNARY_MINUS:
     732           0 :         aName = rtl::OUString("-");
     733           0 :         break;
     734             :     case TK_LESS:
     735           0 :         aName = rtl::OUString("L");
     736           0 :         break;
     737             :     case TK_LESS_OR_EQUAL:
     738           0 :         aName = rtl::OUString("LEQ");
     739           0 :         break;
     740             :     case TK_GREATER:
     741           0 :         aName = rtl::OUString("G");
     742           0 :         break;
     743             :     case TK_GREATER_OR_EQUAL:
     744           0 :         aName = rtl::OUString("GEQ");
     745           0 :         break;
     746             :     case TK_EQUAL:
     747           0 :         aName = rtl::OUString("EQ");
     748           0 :         break;
     749             :     case TK_NOT_EQUAL:
     750           0 :         aName = rtl::OUString("NEQ");
     751           0 :         break;
     752             :     case TK_NOT:
     753           0 :         aName = rtl::OUString("NOT");
     754           0 :         break;
     755             :     case TK_AND:
     756           0 :         aName = rtl::OUString("AND");
     757           0 :         break;
     758             :     case TK_OR:
     759           0 :         aName = rtl::OUString("OR");
     760           0 :         break;
     761             :     default:
     762             :         assert(false);
     763           0 :         break;
     764             :     }
     765           0 :     return aName;
     766             : }
     767             : 
     768             : /**
     769             : *   Get cell address in String
     770             : *   @date   03/26/2005
     771             : *   @param
     772             : *   @param
     773             : *   @return String.
     774             : */
     775           0 : String LwpFormulaTools::GetCellAddr(sal_Int16 nRow, sal_Int16 nCol, LwpTableLayout* pCellsMap)
     776             : {
     777           0 :     String aCellAddr;
     778           0 :     XFCell* pCell = pCellsMap->GetCellsMap(nRow,(sal_uInt8)nCol);
     779           0 :     if (pCell)
     780             :     {
     781           0 :         aCellAddr = pCell->GetCellName();
     782             :     }
     783             :     else
     784             :     {
     785             :         assert( -1==nRow || -1==(sal_Int8)nCol);
     786             :     }
     787           0 :     return aCellAddr;
     788             : }
     789             : 
     790             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10