Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_SC_SOURCE_FILTER_INC_FORMEL_HXX
21 : #define INCLUDED_SC_SOURCE_FILTER_INC_FORMEL_HXX
22 :
23 : #include <compiler.hxx>
24 : #include <global.hxx>
25 :
26 : #include "root.hxx"
27 : #include "tokstack.hxx"
28 :
29 : #include <boost/ptr_container/ptr_map.hpp>
30 : #include <vector>
31 :
32 : namespace svl {
33 :
34 : class SharedStringPool;
35 :
36 : }
37 :
38 : class XclImpStream;
39 : class ScTokenArray;
40 : struct ScSingleRefData;
41 : struct ScComplexRefData;
42 :
43 : enum ConvErr
44 : {
45 : ConvOK = 0,
46 : ConvErrNi, // unimplemented/unknown opcode occurred
47 : ConvErrNoMem, // alloc error
48 : ConvErrExternal,// excel add-ins are not converted
49 : ConvErrCount // did not get all bytes of formula
50 : };
51 :
52 : enum FORMULA_TYPE
53 : {
54 : FT_CellFormula,
55 : FT_RangeName,
56 : FT_SharedFormula,
57 : FT_CondFormat
58 : };
59 :
60 : class _ScRangeListTabs
61 : {
62 : typedef ::std::vector<ScRange> RangeListType;
63 : typedef ::boost::ptr_map<SCTAB, RangeListType> TabRangeType;
64 : TabRangeType maTabRanges;
65 : RangeListType::const_iterator maItrCur;
66 : RangeListType::const_iterator maItrCurEnd;
67 :
68 : public:
69 : _ScRangeListTabs ();
70 : ~_ScRangeListTabs();
71 :
72 : void Append( const ScAddress& aSRD, SCTAB nTab, bool bLimit = true );
73 : void Append( const ScRange& aCRD, SCTAB nTab, bool bLimit = true );
74 :
75 : const ScRange* First ( SCTAB nTab = 0 );
76 : const ScRange* Next ();
77 :
78 168 : bool HasRanges () const { return !maTabRanges.empty(); }
79 : };
80 :
81 : class ConverterBase
82 : {
83 : protected:
84 : TokenPool aPool; // user token + predefined token
85 : TokenStack aStack;
86 : ScAddress aEingPos;
87 : ConvErr eStatus;
88 : sal_Char* pBuffer; // universal buffer
89 : sal_uInt16 nBufferSize; // ...and its size
90 :
91 : ConverterBase( svl::SharedStringPool& rSPool, sal_uInt16 nNewBuffer );
92 : virtual ~ConverterBase();
93 :
94 : void Reset();
95 : };
96 :
97 : class ExcelConverterBase : public ConverterBase
98 : {
99 : protected:
100 : ExcelConverterBase( svl::SharedStringPool& rSPool, sal_uInt16 nNewBuffer );
101 : virtual ~ExcelConverterBase();
102 :
103 : public:
104 : void Reset();
105 : void Reset( const ScAddress& rEingPos );
106 :
107 : virtual ConvErr Convert( const ScTokenArray*& rpErg, XclImpStream& rStrm, sal_Size nFormulaLen,
108 : bool bAllowArrays, const FORMULA_TYPE eFT = FT_CellFormula ) = 0;
109 : virtual ConvErr Convert( _ScRangeListTabs&, XclImpStream& rStrm, sal_Size nFormulaLen, SCsTAB nTab,
110 : const FORMULA_TYPE eFT = FT_CellFormula ) = 0;
111 : };
112 :
113 : class LotusConverterBase : public ConverterBase
114 : {
115 : protected:
116 : SvStream& aIn;
117 : sal_Int32 nBytesLeft;
118 :
119 : inline void Ignore( const long nSeekRel );
120 : inline void Read( sal_Char& nByte );
121 : inline void Read( sal_uInt8& nByte );
122 : inline void Read( sal_uInt16& nUINT16 );
123 : inline void Read( sal_Int16& nINT16 );
124 : inline void Read( double& fDouble );
125 : inline void Read( sal_uInt32& nUINT32 );
126 :
127 : LotusConverterBase( SvStream& rStr, svl::SharedStringPool& rSPool, sal_uInt16 nNewBuffer );
128 : virtual ~LotusConverterBase();
129 :
130 : public:
131 : void Reset( const ScAddress& rEingPos );
132 :
133 : virtual ConvErr Convert( const ScTokenArray*& rpErg, sal_Int32& nRest,
134 : const FORMULA_TYPE eFT = FT_CellFormula ) = 0;
135 :
136 : protected:
137 : using ConverterBase::Reset;
138 : };
139 :
140 0 : inline void LotusConverterBase::Ignore( const long nSeekRel )
141 : {
142 0 : aIn.SeekRel( nSeekRel );
143 0 : nBytesLeft -= nSeekRel;
144 0 : }
145 :
146 : inline void LotusConverterBase::Read( sal_Char& nByte )
147 : {
148 : aIn.ReadChar( nByte );
149 : nBytesLeft--;
150 : }
151 :
152 1150 : inline void LotusConverterBase::Read( sal_uInt8& nByte )
153 : {
154 1150 : aIn.ReadUChar( nByte );
155 1150 : nBytesLeft--;
156 1150 : }
157 :
158 174 : inline void LotusConverterBase::Read( sal_uInt16& nUINT16 )
159 : {
160 174 : aIn.ReadUInt16( nUINT16 );
161 174 : nBytesLeft -= 2;
162 174 : }
163 :
164 2 : inline void LotusConverterBase::Read( sal_Int16& nINT16 )
165 : {
166 2 : aIn.ReadInt16( nINT16 );
167 2 : nBytesLeft -= 2;
168 2 : }
169 :
170 0 : inline void LotusConverterBase::Read( double& fDouble )
171 : {
172 0 : aIn.ReadDouble( fDouble );
173 0 : nBytesLeft -= 8;
174 0 : }
175 :
176 164 : inline void LotusConverterBase::Read( sal_uInt32& nUINT32 )
177 : {
178 164 : aIn.ReadUInt32( nUINT32 );
179 164 : nBytesLeft -= 4;
180 164 : }
181 :
182 : #endif
183 :
184 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|