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 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_FORMEL_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_FORMEL_HXX
22 
23 #include <tools/stream.hxx>
24 
25 #include "tokstack.hxx"
26 
27 #include <memory>
28 #include <vector>
29 #include <map>
30 
31 namespace svl {
32 
33 class SharedStringPool;
34 
35 }
36 
37 class XclImpStream;
38 class ScTokenArray;
39 
40 enum 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 
56 {
57  typedef ::std::vector<ScRange> RangeListType;
58  typedef ::std::map<SCTAB, std::unique_ptr<RangeListType>> TabRangeType;
59  TabRangeType m_TabRanges;
60  RangeListType::const_iterator maItrCur;
61  RangeListType::const_iterator maItrCurEnd;
62 
63 public:
64  ScRangeListTabs ();
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 {
78 protected:
79  TokenPool aPool; // user token + predefined token
82 
84  virtual ~ConverterBase();
85 
86  void Reset();
87 };
88 
90 {
91 protected:
93  virtual ~ExcelConverterBase() override;
94 
95 public:
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 {
107 protected:
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 
121 public:
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 
128 protected:
129  using ConverterBase::Reset;
130 };
131 
132 inline void LotusConverterBase::Ignore( const tools::Long nSeekRel )
133 {
134  aIn.SeekRel( nSeekRel );
135  nBytesLeft -= nSeekRel;
136 }
137 
138 inline void LotusConverterBase::Read( sal_uInt8& nByte )
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 
152 inline 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 
161 inline 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 
170 inline 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 
179 inline 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 #endif
189 
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
LotusConverterBase(SvStream &rStr, svl::SharedStringPool &rSPool)
Definition: frmbase.cxx:188
SvStream & ReadInt16(sal_Int16 &rInt16)
bool HasRanges() const
Definition: formel.hxx:73
ConvErr
Definition: formel.hxx:40
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
long Long
virtual ~LotusConverterBase() override
Definition: frmbase.cxx:195
#define OK
ScAddress aEingPos
Definition: formel.hxx:81
virtual ~ExcelConverterBase() override
Definition: frmbase.cxx:172
sal_uInt64 SeekRel(sal_Int64 nPos)
::std::vector< ScRange > RangeListType
Definition: formel.hxx:57
const ScRange * Next()
Definition: frmbase.cxx:142
TabRangeType m_TabRanges
Definition: formel.hxx:59
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
const ScRange * First(SCTAB nTab)
Definition: frmbase.cxx:127
::std::map< SCTAB, std::unique_ptr< RangeListType > > TabRangeType
Definition: formel.hxx:58
virtual ConvErr Convert(std::unique_ptr< ScTokenArray > &rpErg, XclImpStream &rStrm, std::size_t nFormulaLen, bool bAllowArrays, const FORMULA_TYPE eFT=FT_CellFormula)=0
SvStream & ReadUChar(unsigned char &rChar)
FORMULA_TYPE
Definition: formel.hxx:47
SvStream & ReadDouble(double &rDouble)
RangeListType::const_iterator maItrCur
Definition: formel.hxx:60
TokenPool aPool
Definition: formel.hxx:79
virtual ~ConverterBase()
Definition: frmbase.cxx:157
unsigned char sal_uInt8
TokenStack aStack
Definition: formel.hxx:80
void Read(sal_uInt8 &nByte)
Definition: formel.hxx:138
void Append(const ScAddress &aSRD, SCTAB nTab)
Definition: frmbase.cxx:32
These need to be in global namespace just like their respective types are.
bool good() const
Definition: formel.hxx:126
bool good() const
void Ignore(const tools::Long nSeekRel)
Definition: formel.hxx:132
ConverterBase(svl::SharedStringPool &rSPool)
Definition: frmbase.cxx:151
void Reset()
Definition: frmbase.cxx:161
ExcelConverterBase(svl::SharedStringPool &rSPool)
Definition: frmbase.cxx:167
This class is used to import record oriented streams.
Definition: xistream.hxx:278
SvStream & aIn
Definition: formel.hxx:108
sal_Int32 nBytesLeft
Definition: formel.hxx:109
void SvStream & rStrm
virtual void Convert(std::unique_ptr< ScTokenArray > &rpErg, sal_Int32 &nRest)=0
RangeListType::const_iterator maItrCurEnd
Definition: formel.hxx:61
sal_Int16 SCTAB
Definition: types.hxx:23