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 SC_FORMEL_HXX
21 : #define SC_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 : class XclImpStream;
33 : class ScTokenArray;
34 : struct ScSingleRefData;
35 : struct ScComplexRefData;
36 :
37 : enum ConvErr
38 : {
39 : ConvOK = 0,
40 : ConvErrNi, // unimplemented/unknown opcode occurred
41 : ConvErrNoMem, // alloc error
42 : ConvErrExternal,// excel add-ins are not converted
43 : ConvErrCount // did not get all bytes of formula
44 : };
45 :
46 : enum FORMULA_TYPE
47 : {
48 : FT_CellFormula,
49 : FT_RangeName,
50 : FT_SharedFormula,
51 : FT_CondFormat
52 : };
53 :
54 : class _ScRangeListTabs
55 : {
56 : typedef ::std::vector<ScRange> RangeListType;
57 : typedef ::boost::ptr_map<SCTAB, RangeListType> TabRangeType;
58 : TabRangeType maTabRanges;
59 : RangeListType::const_iterator maItrCur;
60 : RangeListType::const_iterator maItrCurEnd;
61 :
62 : public:
63 : _ScRangeListTabs ();
64 : ~_ScRangeListTabs();
65 :
66 : void Append( const ScAddress& aSRD, SCTAB nTab, bool bLimit = true );
67 : void Append( const ScRange& aCRD, SCTAB nTab, bool bLimit = true );
68 :
69 : const ScRange* First ( SCTAB nTab = 0 );
70 : const ScRange* Next ();
71 :
72 0 : bool HasRanges () const { return !maTabRanges.empty(); }
73 : };
74 :
75 : class ConverterBase
76 : {
77 : protected:
78 : TokenPool aPool; // user token + predefined token
79 : TokenStack aStack;
80 : ScAddress aEingPos;
81 : ConvErr eStatus;
82 : sal_Char* pBuffer; // universal buffer
83 : sal_uInt16 nBufferSize; // ...and its size
84 :
85 : ConverterBase( sal_uInt16 nNewBuffer );
86 : virtual ~ConverterBase();
87 :
88 : void Reset();
89 : };
90 :
91 : class ExcelConverterBase : public ConverterBase
92 : {
93 : protected:
94 : ExcelConverterBase( sal_uInt16 nNewBuffer );
95 : virtual ~ExcelConverterBase();
96 :
97 : public:
98 : void Reset();
99 : void Reset( const ScAddress& rEingPos );
100 :
101 : virtual ConvErr Convert( const ScTokenArray*& rpErg, XclImpStream& rStrm, sal_Size nFormulaLen,
102 : bool bAllowArrays, const FORMULA_TYPE eFT = FT_CellFormula ) = 0;
103 : virtual ConvErr Convert( _ScRangeListTabs&, XclImpStream& rStrm, sal_Size nFormulaLen, SCsTAB nTab,
104 : const FORMULA_TYPE eFT = FT_CellFormula ) = 0;
105 : };
106 :
107 : class LotusConverterBase : public ConverterBase
108 : {
109 : protected:
110 : SvStream& aIn;
111 : sal_Int32 nBytesLeft;
112 :
113 : inline void Ignore( const long nSeekRel );
114 : inline void Read( sal_Char& nByte );
115 : inline void Read( sal_uInt8& nByte );
116 : inline void Read( sal_uInt16& nUINT16 );
117 : inline void Read( sal_Int16& nINT16 );
118 : inline void Read( double& fDouble );
119 : inline void Read( sal_uInt32& nUINT32 );
120 :
121 : LotusConverterBase( SvStream& rStr, sal_uInt16 nNewBuffer );
122 : virtual ~LotusConverterBase();
123 :
124 : public:
125 : void Reset( const ScAddress& rEingPos );
126 :
127 : virtual ConvErr Convert( const ScTokenArray*& rpErg, sal_Int32& nRest,
128 : const FORMULA_TYPE eFT = FT_CellFormula ) = 0;
129 :
130 : protected:
131 : using ConverterBase::Reset;
132 : };
133 :
134 0 : inline void LotusConverterBase::Ignore( const long nSeekRel )
135 : {
136 0 : aIn.SeekRel( nSeekRel );
137 0 : nBytesLeft -= nSeekRel;
138 0 : }
139 :
140 : inline void LotusConverterBase::Read( sal_Char& nByte )
141 : {
142 : aIn.ReadChar( nByte );
143 : nBytesLeft--;
144 : }
145 :
146 0 : inline void LotusConverterBase::Read( sal_uInt8& nByte )
147 : {
148 0 : aIn.ReadUChar( nByte );
149 0 : nBytesLeft--;
150 0 : }
151 :
152 0 : inline void LotusConverterBase::Read( sal_uInt16& nUINT16 )
153 : {
154 0 : aIn.ReadUInt16( nUINT16 );
155 0 : nBytesLeft -= 2;
156 0 : }
157 :
158 0 : inline void LotusConverterBase::Read( sal_Int16& nINT16 )
159 : {
160 0 : aIn.ReadInt16( nINT16 );
161 0 : nBytesLeft -= 2;
162 0 : }
163 :
164 0 : inline void LotusConverterBase::Read( double& fDouble )
165 : {
166 0 : aIn.ReadDouble( fDouble );
167 0 : nBytesLeft -= 8;
168 0 : }
169 :
170 0 : inline void LotusConverterBase::Read( sal_uInt32& nUINT32 )
171 : {
172 0 : aIn.ReadUInt32( nUINT32 );
173 0 : nBytesLeft -= 4;
174 0 : }
175 :
176 : #endif
177 :
178 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|