LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/lotuswordpro/source/filter - lwptblformula.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 271 0.0 %
Date: 2013-07-09 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 += OUString("\"");
     132           0 :     aText.Append(String(pBuf.get(),nStrLen,osl_getThreadTextEncoding()));
     133           0 :     aText += 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 : OUString LwpFormulaConst::ToString(LwpTableLayout* /*pCellsMap*/)
     450             : {
     451           0 :     return 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 : OUString LwpFormulaCellAddr::ToString(LwpTableLayout* pCellsMap)
     487             : {
     488           0 :     OUString aCellAddr = "<" + LwpFormulaTools::GetCellAddr(m_aRow,m_aCol,pCellsMap) + ">";
     489           0 :     return aCellAddr;
     490             : }
     491             : 
     492             : /**
     493             : *
     494             : *   @date   03/26/2005
     495             : *   @param
     496             : *   @param
     497             : *   @return
     498             : */
     499           0 : LwpFormulaCellRangeAddr::LwpFormulaCellRangeAddr(sal_Int16 aStartCol,
     500             :                                                  sal_Int16 aStartRow,
     501             :                                                  sal_Int16 aEndCol,
     502           0 :                                                  sal_Int16 aEndRow)
     503             : {
     504           0 :     m_aStartCol = aStartCol;
     505           0 :     m_aStartRow = aStartRow;
     506           0 :     m_aEndCol = aEndCol;
     507           0 :     m_aEndRow = aEndRow;
     508           0 : }
     509             : 
     510             : /**
     511             : *   Convert the cell range into a string
     512             : *   @date   03/26/2005
     513             : *   @param
     514             : *   @param
     515             : *   @return String.
     516             : */
     517           0 : OUString LwpFormulaCellRangeAddr::ToString(LwpTableLayout* pCellsMap)
     518             : {
     519             :     OUString aCellAddr = "<"
     520           0 :         + LwpFormulaTools::GetCellAddr(m_aStartRow,m_aStartCol,pCellsMap) + ":"
     521           0 :         + LwpFormulaTools::GetCellAddr(m_aEndRow,m_aEndCol,pCellsMap) + ">";
     522             : 
     523           0 :     return aCellAddr;
     524             : }
     525             : 
     526             : /**
     527             : *
     528             : *   @date   03/26/2005
     529             : *   @param
     530             : *   @param
     531             : *   @return
     532             : */
     533           0 : LwpFormulaFunc::LwpFormulaFunc(sal_uInt16 nTokenType)
     534             : {
     535           0 :     m_nTokenType = nTokenType;
     536           0 : }
     537             : 
     538             : /**
     539             : *
     540             : *   @date   03/26/2005
     541             : *   @param
     542             : *   @param
     543             : *   @return
     544             : */
     545           0 : LwpFormulaFunc::~LwpFormulaFunc()
     546             : {
     547             :     try
     548             :     {
     549           0 :         while(m_aArgs.size()>0)
     550             :         {
     551           0 :             LwpFormulaArg* pArg = m_aArgs.back();
     552           0 :             m_aArgs.pop_back();
     553           0 :             delete pArg;pArg=NULL;
     554             :         }
     555           0 :     }catch (...) {
     556             :         assert(false);
     557             :     }
     558             : 
     559           0 : }
     560             : /**
     561             : *
     562             : *   @date   03/26/2005
     563             : *   @param
     564             : *   @param
     565             : *   @return
     566             : */
     567           0 : void LwpFormulaFunc::AddArg(LwpFormulaArg* pArg)
     568             : {
     569           0 :     m_aArgs.push_back(pArg);
     570           0 : }
     571             : /**
     572             : *   Convert the functions to a string, which is a argument of other formula
     573             : *   @date   03/26/2005
     574             : *   @param
     575             : *   @param
     576             : *   @return  String.
     577             : */
     578           0 : String LwpFormulaFunc::ToArgString(LwpTableLayout* pCellsMap)
     579             : {
     580           0 :     OUStringBuffer aFormula;
     581           0 :     aFormula.append(static_cast<sal_Unicode>('('));
     582           0 :     aFormula.append(ToString(pCellsMap));
     583           0 :     aFormula.append(static_cast<sal_Unicode>(')'));
     584           0 :     return aFormula.makeStringAndClear();
     585             : }
     586             : /**
     587             : *   Convert the function to a formula string.
     588             : *   @date   03/26/2005
     589             : *   @param
     590             : *   @param
     591             : *   @return sal_Bool.
     592             : */
     593           0 : OUString LwpFormulaFunc::ToString(LwpTableLayout* pCellsMap)
     594             : {
     595           0 :     OUString aFormula;
     596             : 
     597           0 :     OUString aFuncName = LwpFormulaTools::GetName(m_nTokenType);
     598           0 :     aFormula += aFuncName;
     599           0 :     aFormula += " ";//Append a blank space
     600             : 
     601             :     //Append args
     602           0 :     vector<LwpFormulaArg*>::iterator aItr;
     603           0 :     for (aItr=m_aArgs.begin();aItr!=m_aArgs.end();++aItr)
     604             :     {
     605           0 :         aFormula += (*aItr)->ToArgString(pCellsMap) + "|"; //separator
     606             :     }
     607             : 
     608             :     //erase the last "|"
     609           0 :     if (!m_aArgs.empty())
     610             :     {
     611           0 :         aFormula = aFormula.replaceAt(aFormula.getLength()-1,1,"");
     612             :     }
     613             :     else
     614             :     {
     615             :         assert(false);
     616             :     }
     617             : 
     618           0 :     return aFormula;
     619             : }
     620             : 
     621             : /**
     622             : *   Convert the formula in operators to a string : e.g. 1+2+3
     623             : *   @date   03/26/2005
     624             : *   @param
     625             : *   @param
     626             : *   @return sal_Bool.
     627             : */
     628           0 : OUString LwpFormulaOp::ToString(LwpTableLayout* pCellsMap)
     629             : {
     630           0 :     OUString aFormula;
     631           0 :     if (2==m_aArgs.size())
     632             :     {
     633           0 :         vector<LwpFormulaArg*>::iterator aItr = m_aArgs.end();
     634           0 :         --aItr;
     635             : 
     636           0 :         aFormula += (*aItr)->ToArgString(pCellsMap) + " ";
     637           0 :         OUString aFuncName = LwpFormulaTools::GetName(m_nTokenType);
     638             : 
     639           0 :         aFormula += aFuncName + " ";
     640             : 
     641           0 :         --aItr;
     642           0 :         aFormula += (*aItr)->ToArgString(pCellsMap);
     643             :     }
     644             :     else
     645             :     {
     646             :         assert(false);
     647             :     }
     648           0 :     return aFormula;
     649             : }
     650             : 
     651             : /**
     652             : *   convert the formula in unary operators into string : e.g. -2
     653             : *   @date   03/26/2005
     654             : *   @param
     655             : *   @param
     656             : *   @return sal_Bool.
     657             : */
     658           0 : OUString LwpFormulaUnaryOp::ToString(LwpTableLayout* pCellsMap)
     659             : {
     660           0 :     String aFormula;
     661           0 :     if (1==m_aArgs.size())
     662             :     {
     663           0 :         String aFuncName = LwpFormulaTools::GetName(m_nTokenType);
     664           0 :         aFormula.Append(aFuncName);
     665             : 
     666           0 :         vector<LwpFormulaArg*>::iterator aItr = m_aArgs.begin();
     667           0 :         aFormula.Append( (*aItr)->ToArgString(pCellsMap) );
     668             :     }
     669             :     else
     670             :     {
     671             :         assert(false);
     672             :     }
     673           0 :     return aFormula;
     674             : }
     675             : /**
     676             : *   Get token name
     677             : *   @date   03/26/2005
     678             : *   @param
     679             : *   @param
     680             : *   @return String.
     681             : */
     682           0 : String LwpFormulaTools::GetName(sal_uInt16 nTokenType)
     683             : {
     684           0 :     String aName;
     685           0 :     switch(nTokenType)
     686             :     {
     687             :     case TK_SUM:
     688           0 :         aName = OUString("SUM");
     689           0 :         break;
     690             :     case TK_IF:
     691           0 :         aName = OUString("IF");//Not supported by SODC
     692           0 :         break;
     693             :     case TK_COUNT:
     694           0 :         aName = OUString("COUNT");//Not supported by SODC
     695           0 :         break;
     696             :     case TK_MINIMUM:
     697           0 :         aName = OUString("MIN");
     698           0 :         break;
     699             :     case TK_MAXIMUM:
     700           0 :         aName = OUString("MAX");
     701           0 :         break;
     702             :     case TK_AVERAGE:
     703           0 :         aName = OUString("MEAN");
     704           0 :         break;
     705             :     case TK_ADD:
     706           0 :         aName = OUString("+");
     707           0 :         break;
     708             :     case TK_SUBTRACT:
     709           0 :         aName = OUString("-");
     710           0 :         break;
     711             :     case TK_MULTIPLY:
     712           0 :         aName = OUString("*");
     713           0 :         break;
     714             :     case TK_DIVIDE:
     715           0 :         aName = OUString("/");
     716           0 :         break;
     717             :     case TK_UNARY_MINUS:
     718           0 :         aName = OUString("-");
     719           0 :         break;
     720             :     case TK_LESS:
     721           0 :         aName = OUString("L");
     722           0 :         break;
     723             :     case TK_LESS_OR_EQUAL:
     724           0 :         aName = OUString("LEQ");
     725           0 :         break;
     726             :     case TK_GREATER:
     727           0 :         aName = OUString("G");
     728           0 :         break;
     729             :     case TK_GREATER_OR_EQUAL:
     730           0 :         aName = OUString("GEQ");
     731           0 :         break;
     732             :     case TK_EQUAL:
     733           0 :         aName = OUString("EQ");
     734           0 :         break;
     735             :     case TK_NOT_EQUAL:
     736           0 :         aName = OUString("NEQ");
     737           0 :         break;
     738             :     case TK_NOT:
     739           0 :         aName = OUString("NOT");
     740           0 :         break;
     741             :     case TK_AND:
     742           0 :         aName = OUString("AND");
     743           0 :         break;
     744             :     case TK_OR:
     745           0 :         aName = OUString("OR");
     746           0 :         break;
     747             :     default:
     748             :         assert(false);
     749           0 :         break;
     750             :     }
     751           0 :     return aName;
     752             : }
     753             : 
     754             : /**
     755             : *   Get cell address in String
     756             : *   @date   03/26/2005
     757             : *   @param
     758             : *   @param
     759             : *   @return String.
     760             : */
     761           0 : String LwpFormulaTools::GetCellAddr(sal_Int16 nRow, sal_Int16 nCol, LwpTableLayout* pCellsMap)
     762             : {
     763           0 :     String aCellAddr;
     764           0 :     XFCell* pCell = pCellsMap->GetCellsMap(nRow,(sal_uInt8)nCol);
     765           0 :     if (pCell)
     766             :     {
     767           0 :         aCellAddr = pCell->GetCellName();
     768             :     }
     769             :     else
     770             :     {
     771             :         assert( -1==nRow || -1==(sal_Int8)nCol);
     772             :     }
     773           0 :     return aCellAddr;
     774             : }
     775             : 
     776             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10