LibreOffice Module sc (master) 1
formel.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <tools/stream.hxx>
23
24#include "tokstack.hxx"
25#include "xiroot.hxx"
26
27#include <memory>
28#include <vector>
29#include <map>
30
31namespace svl {
32
33class SharedStringPool;
34
35}
36
37class XclImpStream;
38class ScTokenArray;
39
40enum class ConvErr
41{
42 OK = 0,
43 Ni, // unimplemented/unknown opcode occurred
44 Count // did not get all bytes of formula
45};
46
48{
53};
54
55class ScRangeListTabs : protected XclImpRoot
56{
57 typedef ::std::vector<ScRange> RangeListType;
58 typedef ::std::map<SCTAB, RangeListType> TabRangeType;
60 RangeListType::const_iterator maItrCur;
61 RangeListType::const_iterator maItrCurEnd;
62
63public:
64 ScRangeListTabs( const XclImpRoot& rRoot );
66
67 void Append( const ScAddress& aSRD, SCTAB nTab );
68 void Append( const ScRange& aCRD, SCTAB nTab );
69
70 const ScRange* First ( SCTAB nTab );
71 const ScRange* Next ();
72
73 bool HasRanges () const { return !m_TabRanges.empty(); }
74};
75
77{
78protected:
79 TokenPool aPool; // user token + predefined token
82
84 virtual ~ConverterBase();
85
86 void Reset();
87};
88
90{
91protected:
93 virtual ~ExcelConverterBase() override;
94
95public:
96 void Reset();
97 void Reset( const ScAddress& rEingPos );
98
99 virtual ConvErr Convert( std::unique_ptr<ScTokenArray>& rpErg, XclImpStream& rStrm, std::size_t nFormulaLen,
100 bool bAllowArrays, const FORMULA_TYPE eFT = FT_CellFormula ) = 0;
101 virtual ConvErr Convert( ScRangeListTabs&, XclImpStream& rStrm, std::size_t nFormulaLen, SCTAB nTab,
102 const FORMULA_TYPE eFT = FT_CellFormula ) = 0;
103};
104
106{
107protected:
109 sal_Int32 nBytesLeft;
110
111 inline void Ignore( const tools::Long nSeekRel );
112 inline void Read( sal_uInt8& nByte );
113 inline void Read( sal_uInt16& nUINT16 );
114 inline void Read( sal_Int16& nINT16 );
115 inline void Read( double& fDouble );
116 inline void Read( sal_uInt32& nUINT32 );
117
119 virtual ~LotusConverterBase() override;
120
121public:
122 void Reset( const ScAddress& rEingPos );
123
124 virtual void Convert( std::unique_ptr<ScTokenArray>& rpErg, sal_Int32& nRest ) = 0;
125
126 bool good() const { return aIn.good(); }
127
128protected:
130};
131
132inline void LotusConverterBase::Ignore( const tools::Long nSeekRel )
133{
134 aIn.SeekRel( nSeekRel );
135 nBytesLeft -= nSeekRel;
136}
137
139{
140 aIn.ReadUChar( nByte );
141 if (aIn.good())
142 nBytesLeft--;
143 else
144 {
145 // SvStream::ReadUChar() does not init a single char on failure. This
146 // behaviour is even tested in a unit test.
147 nByte = 0;
148 nBytesLeft = -1; // bail out early
149 }
150}
151
152inline void LotusConverterBase::Read( sal_uInt16& nUINT16 )
153{
154 aIn.ReadUInt16( nUINT16 );
155 if (aIn.good())
156 nBytesLeft -= 2;
157 else
158 nBytesLeft = -1; // bail out early
159}
160
161inline void LotusConverterBase::Read( sal_Int16& nINT16 )
162{
163 aIn.ReadInt16( nINT16 );
164 if (aIn.good())
165 nBytesLeft -= 2;
166 else
167 nBytesLeft = -1; // bail out early
168}
169
170inline void LotusConverterBase::Read( double& fDouble )
171{
172 aIn.ReadDouble( fDouble );
173 if (aIn.good())
174 nBytesLeft -= 8;
175 else
176 nBytesLeft = -1; // bail out early
177}
178
179inline void LotusConverterBase::Read( sal_uInt32& nUINT32 )
180{
181 aIn.ReadUInt32( nUINT32 );
182 if (aIn.good())
183 nBytesLeft -= 4;
184 else
185 nBytesLeft = -1; // bail out early
186}
187
188/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScAddress aEingPos
Definition: formel.hxx:81
void Reset()
Definition: frmbase.cxx:164
ConverterBase(svl::SharedStringPool &rSPool)
Definition: frmbase.cxx:154
TokenPool aPool
Definition: formel.hxx:79
TokenStack aStack
Definition: formel.hxx:80
virtual ~ConverterBase()
Definition: frmbase.cxx:160
virtual ConvErr Convert(std::unique_ptr< ScTokenArray > &rpErg, XclImpStream &rStrm, std::size_t nFormulaLen, bool bAllowArrays, const FORMULA_TYPE eFT=FT_CellFormula)=0
ExcelConverterBase(svl::SharedStringPool &rSPool)
Definition: frmbase.cxx:170
virtual ConvErr Convert(ScRangeListTabs &, XclImpStream &rStrm, std::size_t nFormulaLen, SCTAB nTab, const FORMULA_TYPE eFT=FT_CellFormula)=0
virtual ~ExcelConverterBase() override
Definition: frmbase.cxx:175
virtual ~LotusConverterBase() override
Definition: frmbase.cxx:198
void Read(sal_uInt8 &nByte)
Definition: formel.hxx:138
SvStream & aIn
Definition: formel.hxx:108
LotusConverterBase(SvStream &rStr, svl::SharedStringPool &rSPool)
Definition: frmbase.cxx:191
virtual void Convert(std::unique_ptr< ScTokenArray > &rpErg, sal_Int32 &nRest)=0
bool good() const
Definition: formel.hxx:126
sal_Int32 nBytesLeft
Definition: formel.hxx:109
void Ignore(const tools::Long nSeekRel)
Definition: formel.hxx:132
::std::map< SCTAB, RangeListType > TabRangeType
Definition: formel.hxx:58
::std::vector< ScRange > RangeListType
Definition: formel.hxx:57
void Append(const ScAddress &aSRD, SCTAB nTab)
Definition: frmbase.cxx:33
RangeListType::const_iterator maItrCurEnd
Definition: formel.hxx:61
const ScRange * First(SCTAB nTab)
Definition: frmbase.cxx:130
const ScRange * Next()
Definition: frmbase.cxx:145
ScRangeListTabs(const XclImpRoot &rRoot)
Definition: frmbase.cxx:24
bool HasRanges() const
Definition: formel.hxx:73
RangeListType::const_iterator maItrCur
Definition: formel.hxx:60
TabRangeType m_TabRanges
Definition: formel.hxx:59
bool good() const
SvStream & ReadDouble(double &rDouble)
SvStream & ReadInt16(sal_Int16 &rInt16)
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
sal_uInt64 SeekRel(sal_Int64 nPos)
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
SvStream & ReadUChar(unsigned char &rChar)
Access to global data from other classes.
Definition: xiroot.hxx:129
This class is used to import record oriented streams.
Definition: xistream.hxx:278
#define OK
ConvErr
Definition: formel.hxx:41
FORMULA_TYPE
Definition: formel.hxx:48
@ FT_CondFormat
Definition: formel.hxx:52
@ FT_RangeName
Definition: formel.hxx:50
@ FT_SharedFormula
Definition: formel.hxx:51
@ FT_CellFormula
Definition: formel.hxx:49
These need to be in global namespace just like their respective types are.
long Long
unsigned char sal_uInt8
sal_Int16 SCTAB
Definition: types.hxx:22
Count