LibreOffice Module sc (master)  1
xiformula.cxx
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 #include <xiformula.hxx>
21 #include <rangelst.hxx>
22 #include <xistream.hxx>
23 
24 #include <excform.hxx>
25 
26 // Formula compiler ===========================================================
27 
30 {
31 public:
32  explicit XclImpFmlaCompImpl( const XclImpRoot& rRoot );
33 
35  void CreateRangeList(
36  ScRangeList& rScRanges, XclFormulaType eType,
37  const XclTokenArray& rXclTokArr, XclImpStream& rStrm );
38 
39  std::unique_ptr<ScTokenArray> CreateFormula( XclFormulaType eType, const XclTokenArray& rXclTokArr );
40 
41 };
42 
44  XclImpRoot( rRoot )
45 {
46 }
47 
49  ScRangeList& rScRanges, XclFormulaType /*eType*/,
50  const XclTokenArray& rXclTokArr, XclImpStream& /*rStrm*/ )
51 {
52  rScRanges.RemoveAll();
53 
54  //FIXME: evil hack, using old formula import :-)
55  if( !rXclTokArr.Empty() )
56  {
57  SvMemoryStream aMemStrm;
58  aMemStrm.WriteUInt16( EXC_ID_EOF ).WriteUInt16( rXclTokArr.GetSize() );
59  aMemStrm.WriteBytes(rXclTokArr.GetData(), rXclTokArr.GetSize());
60  XclImpStream aFmlaStrm( aMemStrm, GetRoot() );
61  aFmlaStrm.StartNextRecord();
62  GetOldFmlaConverter().GetAbsRefs( rScRanges, aFmlaStrm, aFmlaStrm.GetRecSize() );
63  }
64 }
65 
66 std::unique_ptr<ScTokenArray> XclImpFmlaCompImpl::CreateFormula(
67  XclFormulaType /*eType*/, const XclTokenArray& rXclTokArr )
68 {
69  if (rXclTokArr.Empty())
70  return nullptr;
71 
72  // evil hack! are we trying to phase out the old style formula converter ?
73  SvMemoryStream aMemStrm;
74  aMemStrm.WriteUInt16( EXC_ID_EOF ).WriteUInt16( rXclTokArr.GetSize() );
75  aMemStrm.WriteBytes(rXclTokArr.GetData(), rXclTokArr.GetSize());
76  XclImpStream aFmlaStrm( aMemStrm, GetRoot() );
77  aFmlaStrm.StartNextRecord();
78  std::unique_ptr<ScTokenArray> pArray;
80  GetOldFmlaConverter().Convert(pArray, aFmlaStrm, aFmlaStrm.GetRecSize(), true);
81  return pArray;
82 }
83 
85  XclImpRoot( rRoot ),
86  mxImpl( std::make_shared<XclImpFmlaCompImpl>( rRoot ) )
87 {
88 }
89 
91 {
92 }
93 
95  ScRangeList& rScRanges, XclFormulaType eType,
96  const XclTokenArray& rXclTokArr, XclImpStream& rStrm )
97 {
98  mxImpl->CreateRangeList( rScRanges, eType, rXclTokArr, rStrm );
99 }
100 
101 std::unique_ptr<ScTokenArray> XclImpFormulaCompiler::CreateFormula(
102  XclFormulaType eType, const XclTokenArray& rXclTokArr )
103 {
104  return mxImpl->CreateFormula(eType, rXclTokArr);
105 }
106 
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< ScTokenArray > CreateFormula(XclFormulaType eType, const XclTokenArray &rXclTokArr)
Definition: xiformula.cxx:66
SvStream & WriteUInt16(sal_uInt16 nUInt16)
void CreateRangeList(ScRangeList &rScRanges, XclFormulaType eType, const XclTokenArray &rXclTokArr, XclImpStream &rStrm)
Creates a range list from the passed Excel token array.
Definition: xiformula.cxx:48
std::unique_ptr< ScTokenArray > CreateFormula(XclFormulaType eType, const XclTokenArray &rXclTokArr)
Creates a formula token array from the Excel token array.
Definition: xiformula.cxx:101
sal_uInt16 GetSize() const
Returns the size of the token array in bytes.
Definition: xlformula.cxx:735
std::shared_ptr< T > make_shared(Args &&...args)
const XclImpRoot & GetRoot() const
Returns this root instance - for code readability in derived classes.
Definition: xiroot.hxx:132
XclFormulaType
Mask for number of appended ranges.
Definition: xlformula.hxx:160
virtual ~XclImpFormulaCompiler() override
Definition: xiformula.cxx:90
bool Empty() const
Returns true, if the token array is empty.
Definition: xlformula.hxx:386
ExcelToSc & GetOldFmlaConverter() const
Returns the old formula converter.
Definition: xiroot.cxx:129
bool StartNextRecord()
Sets stream pointer to the start of the next record content.
Definition: xistream.cxx:455
void CreateRangeList(ScRangeList &rScRanges, XclFormulaType eType, const XclTokenArray &rXclTokArr, XclImpStream &rStrm)
Creates a range list from the passed Excel token array.
Definition: xiformula.cxx:94
XclImpFmlaCompImpl(const XclImpRoot &rRoot)
Definition: xiformula.cxx:43
const sal_uInt8 * GetData() const
Returns read-only access to the byte vector storing token data.
Definition: xlformula.hxx:390
std::size_t GetRecSize()
Returns the data size of the whole record without record headers.
Definition: xistream.cxx:568
DocumentType eType
std::size_t WriteBytes(const void *pData, std::size_t nSize)
virtual ConvErr Convert(std::unique_ptr< ScTokenArray > &, XclImpStream &rStrm, std::size_t nFormulaLen, bool bAllowArrays, const FORMULA_TYPE eFT=FT_CellFormula) override
Definition: excform.cxx:206
Binary representation of an Excel token array.
Definition: xlformula.hxx:377
XclImpFmlaCompImplRef mxImpl
Definition: xiformula.hxx:52
virtual void GetAbsRefs(ScRangeList &rRangeList, XclImpStream &rStrm, std::size_t nLen)
Definition: excform.cxx:1317
XclImpFormulaCompiler(const XclImpRoot &rRoot)
Definition: xiformula.cxx:84
This class is used to import record oriented streams.
Definition: xistream.hxx:278
A helper with Excel specific token array functions.
Definition: xlformula.hxx:486
void SvStream & rStrm
Access to global data from other classes.
Definition: xiroot.hxx:126
Implementation class of the export formula compiler.
Definition: xiformula.cxx:29
void RemoveAll()
Definition: rangelst.cxx:1108
const sal_uInt16 EXC_ID_EOF
Internal use only.
Definition: xlconst.hxx:173