Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef SC_FORMEL_HXX
30 : : #define SC_FORMEL_HXX
31 : :
32 : : #include <tools/solar.h>
33 : :
34 : : #include <compiler.hxx>
35 : : #include <global.hxx>
36 : :
37 : : #include "root.hxx"
38 : : #include "tokstack.hxx"
39 : :
40 : : #include <boost/ptr_container/ptr_map.hpp>
41 : : #include <vector>
42 : :
43 : : class XclImpStream;
44 : : class ScTokenArray;
45 : : struct ScSingleRefData;
46 : : struct ScComplexRefData;
47 : :
48 : : enum ConvErr
49 : : {
50 : : ConvOK = 0,
51 : : ConvErrNi, // unimplemented/unknown opcode occurred
52 : : ConvErrNoMem, // alloc error
53 : : ConvErrExternal,// excel add-ins are not converted
54 : : ConvErrCount // did not get all bytes of formula
55 : : };
56 : :
57 : : enum FORMULA_TYPE
58 : : {
59 : : FT_CellFormula,
60 : : FT_RangeName,
61 : : FT_SharedFormula
62 : : };
63 : :
64 : : class _ScRangeListTabs
65 : : {
66 : : typedef ::std::vector<ScRange> RangeListType;
67 : : typedef ::boost::ptr_map<SCTAB, RangeListType> TabRangeType;
68 : : TabRangeType maTabRanges;
69 : : RangeListType::const_iterator maItrCur;
70 : : RangeListType::const_iterator maItrCurEnd;
71 : :
72 : : public:
73 : : _ScRangeListTabs ();
74 : : ~_ScRangeListTabs();
75 : :
76 : : void Append( ScSingleRefData aSRD, SCTAB nTab, bool bLimit = true );
77 : : void Append( ScComplexRefData aCRD, SCTAB nTab, bool bLimit = true );
78 : :
79 : : const ScRange* First ( SCTAB nTab = 0 );
80 : : const ScRange* Next ();
81 : :
82 : 110 : bool HasRanges () const { return !maTabRanges.empty(); }
83 : : };
84 : :
85 : : class ConverterBase
86 : : {
87 : : protected:
88 : : TokenPool aPool; // user token + predefined token
89 : : TokenStack aStack;
90 : : ScAddress aEingPos;
91 : : ConvErr eStatus;
92 : : sal_Char* pBuffer; // universal buffer
93 : : sal_uInt16 nBufferSize; // ...and its size
94 : :
95 : : ConverterBase( sal_uInt16 nNewBuffer );
96 : : virtual ~ConverterBase();
97 : :
98 : : void Reset();
99 : : };
100 : :
101 : :
102 : :
103 : : class ExcelConverterBase : public ConverterBase
104 : : {
105 : : protected:
106 : : ExcelConverterBase( sal_uInt16 nNewBuffer );
107 : : virtual ~ExcelConverterBase();
108 : :
109 : : public:
110 : : void Reset();
111 : : void Reset( const ScAddress& rEingPos );
112 : :
113 : : virtual ConvErr Convert( const ScTokenArray*& rpErg, XclImpStream& rStrm, sal_Size nFormulaLen,
114 : : bool bAllowArrays, const FORMULA_TYPE eFT = FT_CellFormula ) = 0;
115 : : virtual ConvErr Convert( _ScRangeListTabs&, XclImpStream& rStrm, sal_Size nFormulaLen, SCsTAB nTab,
116 : : const FORMULA_TYPE eFT = FT_CellFormula ) = 0;
117 : : };
118 : :
119 : :
120 : :
121 : : class LotusConverterBase : public ConverterBase
122 : : {
123 : : protected:
124 : : SvStream& aIn;
125 : : sal_Int32 nBytesLeft;
126 : :
127 : : inline void Ignore( const long nSeekRel );
128 : : inline void Read( sal_Char& nByte );
129 : : inline void Read( sal_uInt8& nByte );
130 : : inline void Read( sal_uInt16& nUINT16 );
131 : : inline void Read( sal_Int16& nINT16 );
132 : : inline void Read( double& fDouble );
133 : : inline void Read( sal_uInt32& nUINT32 );
134 : :
135 : : LotusConverterBase( SvStream& rStr, sal_uInt16 nNewBuffer );
136 : : virtual ~LotusConverterBase();
137 : :
138 : : public:
139 : : void Reset( const ScAddress& rEingPos );
140 : :
141 : : virtual ConvErr Convert( const ScTokenArray*& rpErg, sal_Int32& nRest,
142 : : const FORMULA_TYPE eFT = FT_CellFormula ) = 0;
143 : :
144 : : protected:
145 : : using ConverterBase::Reset;
146 : : };
147 : :
148 : :
149 : 0 : inline void LotusConverterBase::Ignore( const long nSeekRel )
150 : : {
151 : 0 : aIn.SeekRel( nSeekRel );
152 : 0 : nBytesLeft -= nSeekRel;
153 : 0 : }
154 : :
155 : : inline void LotusConverterBase::Read( sal_Char& nByte )
156 : : {
157 : : aIn >> nByte;
158 : : nBytesLeft--;
159 : : }
160 : :
161 : 0 : inline void LotusConverterBase::Read( sal_uInt8& nByte )
162 : : {
163 : 0 : aIn >> nByte;
164 : 0 : nBytesLeft--;
165 : 0 : }
166 : :
167 : 0 : inline void LotusConverterBase::Read( sal_uInt16& nUINT16 )
168 : : {
169 : 0 : aIn >> nUINT16;
170 : 0 : nBytesLeft -= 2;
171 : 0 : }
172 : :
173 : 0 : inline void LotusConverterBase::Read( sal_Int16& nINT16 )
174 : : {
175 : 0 : aIn >> nINT16;
176 : 0 : nBytesLeft -= 2;
177 : 0 : }
178 : :
179 : 0 : inline void LotusConverterBase::Read( double& fDouble )
180 : : {
181 : 0 : aIn >> fDouble;
182 : 0 : nBytesLeft -= 8;
183 : 0 : }
184 : :
185 : 0 : inline void LotusConverterBase::Read( sal_uInt32& nUINT32 )
186 : : {
187 : 0 : aIn >> nUINT32;
188 : 0 : nBytesLeft -= 4;
189 : 0 : }
190 : :
191 : : #endif
192 : :
193 : :
194 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|