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 : #include "xiformula.hxx"
21 : #include "rangelst.hxx"
22 : #include "xistream.hxx"
23 :
24 : #include "excform.hxx"
25 :
26 : // Formula compiler ===========================================================
27 :
28 : /** Implementation class of the export formula compiler. */
29 288 : class XclImpFmlaCompImpl : protected XclImpRoot, protected XclTokenArrayHelper
30 : {
31 : public:
32 : explicit XclImpFmlaCompImpl( const XclImpRoot& rRoot );
33 :
34 : /** Creates a range list from the passed Excel token array. */
35 : void CreateRangeList(
36 : ScRangeList& rScRanges, XclFormulaType eType,
37 : const XclTokenArray& rXclTokArr, XclImpStream& rStrm );
38 :
39 : const ScTokenArray* CreateFormula( XclFormulaType eType, const XclTokenArray& rXclTokArr );
40 :
41 : private:
42 : XclFunctionProvider maFuncProv; /// Excel function data provider.
43 : };
44 :
45 144 : XclImpFmlaCompImpl::XclImpFmlaCompImpl( const XclImpRoot& rRoot ) :
46 : XclImpRoot( rRoot ),
47 144 : maFuncProv( rRoot )
48 : {
49 144 : }
50 :
51 4 : void XclImpFmlaCompImpl::CreateRangeList(
52 : ScRangeList& rScRanges, XclFormulaType /*eType*/,
53 : const XclTokenArray& rXclTokArr, XclImpStream& /*rStrm*/ )
54 : {
55 4 : rScRanges.RemoveAll();
56 :
57 : //! evil hack, using old formula import :-)
58 4 : if( !rXclTokArr.Empty() )
59 : {
60 4 : SvMemoryStream aMemStrm;
61 4 : aMemStrm.WriteUInt16( EXC_ID_EOF ).WriteUInt16( rXclTokArr.GetSize() );
62 4 : aMemStrm.Write( rXclTokArr.GetData(), rXclTokArr.GetSize() );
63 8 : XclImpStream aFmlaStrm( aMemStrm, GetRoot() );
64 4 : aFmlaStrm.StartNextRecord();
65 8 : GetOldFmlaConverter().GetAbsRefs( rScRanges, aFmlaStrm, aFmlaStrm.GetRecSize() );
66 : }
67 4 : }
68 :
69 194 : const ScTokenArray* XclImpFmlaCompImpl::CreateFormula(
70 : XclFormulaType /*eType*/, const XclTokenArray& rXclTokArr )
71 : {
72 194 : if (rXclTokArr.Empty())
73 0 : return NULL;
74 :
75 : // evil hack! are we trying to phase out the old style formula converter ?
76 194 : SvMemoryStream aMemStrm;
77 194 : aMemStrm.WriteUInt16( EXC_ID_EOF ).WriteUInt16( rXclTokArr.GetSize() );
78 194 : aMemStrm.Write( rXclTokArr.GetData(), rXclTokArr.GetSize() );
79 388 : XclImpStream aFmlaStrm( aMemStrm, GetRoot() );
80 194 : aFmlaStrm.StartNextRecord();
81 194 : const ScTokenArray* pArray = NULL;
82 194 : GetOldFmlaConverter().Reset();
83 194 : GetOldFmlaConverter().Convert(pArray, aFmlaStrm, aFmlaStrm.GetRecSize(), true);
84 388 : return pArray;
85 : }
86 :
87 144 : XclImpFormulaCompiler::XclImpFormulaCompiler( const XclImpRoot& rRoot ) :
88 : XclImpRoot( rRoot ),
89 144 : mxImpl( new XclImpFmlaCompImpl( rRoot ) )
90 : {
91 144 : }
92 :
93 288 : XclImpFormulaCompiler::~XclImpFormulaCompiler()
94 : {
95 288 : }
96 :
97 4 : void XclImpFormulaCompiler::CreateRangeList(
98 : ScRangeList& rScRanges, XclFormulaType eType,
99 : const XclTokenArray& rXclTokArr, XclImpStream& rStrm )
100 : {
101 4 : mxImpl->CreateRangeList( rScRanges, eType, rXclTokArr, rStrm );
102 4 : }
103 :
104 194 : const ScTokenArray* XclImpFormulaCompiler::CreateFormula(
105 : XclFormulaType eType, const XclTokenArray& rXclTokArr )
106 : {
107 194 : return mxImpl->CreateFormula(eType, rXclTokArr);
108 48 : }
109 :
110 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|