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 
26 #include <memory>
27 #include <vector>
28 #include <map>
29 
30 namespace svl {
31 
32 class SharedStringPool;
33 
34 }
35 
36 class XclImpStream;
37 class ScTokenArray;
38 
39 enum class ConvErr
40 {
41  OK = 0,
42  Ni, // unimplemented/unknown opcode occurred
43  Count // did not get all bytes of formula
44 };
45 
47 {
52 };
53 
55 {
56  typedef ::std::vector<ScRange> RangeListType;
57  typedef ::std::map<SCTAB, std::unique_ptr<RangeListType>> TabRangeType;
58  TabRangeType m_TabRanges;
59  RangeListType::const_iterator maItrCur;
60  RangeListType::const_iterator maItrCurEnd;
61 
62 public:
63  ScRangeListTabs ();
65 
66  void Append( const ScAddress& aSRD, SCTAB nTab );
67  void Append( const ScRange& aCRD, SCTAB nTab );
68 
69  const ScRange* First ( SCTAB nTab );
70  const ScRange* Next ();
71 
72  bool HasRanges () const { return !m_TabRanges.empty(); }
73 };
74 
76 {
77 protected:
78  TokenPool aPool; // user token + predefined token
81 
83  virtual ~ConverterBase();
84 
85  void Reset();
86 };
87 
89 {
90 protected:
92  virtual ~ExcelConverterBase() override;
93 
94 public:
95  void Reset();
96  void Reset( const ScAddress& rEingPos );
97 
98  virtual ConvErr Convert( std::unique_ptr<ScTokenArray>& rpErg, XclImpStream& rStrm, std::size_t nFormulaLen,
99  bool bAllowArrays, const FORMULA_TYPE eFT = FT_CellFormula ) = 0;
100  virtual ConvErr Convert( ScRangeListTabs&, XclImpStream& rStrm, std::size_t nFormulaLen, SCTAB nTab,
101  const FORMULA_TYPE eFT = FT_CellFormula ) = 0;
102 };
103 
105 {
106 protected:
108  sal_Int32 nBytesLeft;
109 
110  inline void Ignore( const tools::Long nSeekRel );
111  inline void Read( sal_uInt8& nByte );
112  inline void Read( sal_uInt16& nUINT16 );
113  inline void Read( sal_Int16& nINT16 );
114  inline void Read( double& fDouble );
115  inline void Read( sal_uInt32& nUINT32 );
116 
118  virtual ~LotusConverterBase() override;
119 
120 public:
121  void Reset( const ScAddress& rEingPos );
122 
123  virtual void Convert( std::unique_ptr<ScTokenArray>& rpErg, sal_Int32& nRest ) = 0;
124 
125  bool good() const { return aIn.good(); }
126 
127 protected:
128  using ConverterBase::Reset;
129 };
130 
131 inline void LotusConverterBase::Ignore( const tools::Long nSeekRel )
132 {
133  aIn.SeekRel( nSeekRel );
134  nBytesLeft -= nSeekRel;
135 }
136 
137 inline void LotusConverterBase::Read( sal_uInt8& nByte )
138 {
139  aIn.ReadUChar( nByte );
140  if (aIn.good())
141  nBytesLeft--;
142  else
143  {
144  // SvStream::ReadUChar() does not init a single char on failure. This
145  // behaviour is even tested in a unit test.
146  nByte = 0;
147  nBytesLeft = -1; // bail out early
148  }
149 }
150 
151 inline void LotusConverterBase::Read( sal_uInt16& nUINT16 )
152 {
153  aIn.ReadUInt16( nUINT16 );
154  if (aIn.good())
155  nBytesLeft -= 2;
156  else
157  nBytesLeft = -1; // bail out early
158 }
159 
160 inline void LotusConverterBase::Read( sal_Int16& nINT16 )
161 {
162  aIn.ReadInt16( nINT16 );
163  if (aIn.good())
164  nBytesLeft -= 2;
165  else
166  nBytesLeft = -1; // bail out early
167 }
168 
169 inline void LotusConverterBase::Read( double& fDouble )
170 {
171  aIn.ReadDouble( fDouble );
172  if (aIn.good())
173  nBytesLeft -= 8;
174  else
175  nBytesLeft = -1; // bail out early
176 }
177 
178 inline void LotusConverterBase::Read( sal_uInt32& nUINT32 )
179 {
180  aIn.ReadUInt32( nUINT32 );
181  if (aIn.good())
182  nBytesLeft -= 4;
183  else
184  nBytesLeft = -1; // bail out early
185 }
186 
187 /* 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:72
ConvErr
Definition: formel.hxx:39
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
long Long
virtual ~LotusConverterBase() override
Definition: frmbase.cxx:195
#define OK
ScAddress aEingPos
Definition: formel.hxx:80
virtual ~ExcelConverterBase() override
Definition: frmbase.cxx:172
sal_uInt64 SeekRel(sal_Int64 nPos)
::std::vector< ScRange > RangeListType
Definition: formel.hxx:56
const ScRange * Next()
Definition: frmbase.cxx:142
TabRangeType m_TabRanges
Definition: formel.hxx:58
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:57
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:46
SvStream & ReadDouble(double &rDouble)
RangeListType::const_iterator maItrCur
Definition: formel.hxx:59
TokenPool aPool
Definition: formel.hxx:78
virtual ~ConverterBase()
Definition: frmbase.cxx:157
unsigned char sal_uInt8
TokenStack aStack
Definition: formel.hxx:79
void Read(sal_uInt8 &nByte)
Definition: formel.hxx:137
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:125
bool good() const
void Ignore(const tools::Long nSeekRel)
Definition: formel.hxx:131
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:277
SvStream & aIn
Definition: formel.hxx:107
sal_Int32 nBytesLeft
Definition: formel.hxx:108
void SvStream & rStrm
virtual void Convert(std::unique_ptr< ScTokenArray > &rpErg, sal_Int32 &nRest)=0
RangeListType::const_iterator maItrCurEnd
Definition: formel.hxx:60
sal_Int16 SCTAB
Definition: types.hxx:22