1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #include "precompiled_scfilt.hxx"
25 #include "xiformula.hxx"
26 #include "rangelst.hxx"
27 #include "xistream.hxx"
28
29 #include "excform.hxx"
30
31 // Formula compiler ===========================================================
32
33 /** Implementation class of the export formula compiler. */
34 class XclImpFmlaCompImpl : protected XclImpRoot, protected XclTokenArrayHelper
35 {
36 public:
37 explicit XclImpFmlaCompImpl( const XclImpRoot& rRoot );
38
39 /** Creates a range list from the passed Excel token array. */
40 void CreateRangeList(
41 ScRangeList& rScRanges, XclFormulaType eType,
42 const XclTokenArray& rXclTokArr, XclImpStream& rStrm );
43
44 const ScTokenArray* CreateFormula( XclFormulaType eType, const XclTokenArray& rXclTokArr );
45
46 // ------------------------------------------------------------------------
47 private:
48 XclFunctionProvider maFuncProv; /// Excel function data provider.
49 const XclBiff meBiff; /// Cached BIFF version to save GetBiff() calls.
50 };
51
52 // ----------------------------------------------------------------------------
53
XclImpFmlaCompImpl(const XclImpRoot & rRoot)54 XclImpFmlaCompImpl::XclImpFmlaCompImpl( const XclImpRoot& rRoot ) :
55 XclImpRoot( rRoot ),
56 maFuncProv( rRoot ),
57 meBiff( rRoot.GetBiff() )
58 {
59 }
60
CreateRangeList(ScRangeList & rScRanges,XclFormulaType,const XclTokenArray & rXclTokArr,XclImpStream &)61 void XclImpFmlaCompImpl::CreateRangeList(
62 ScRangeList& rScRanges, XclFormulaType /*eType*/,
63 const XclTokenArray& rXclTokArr, XclImpStream& /*rStrm*/ )
64 {
65 rScRanges.RemoveAll();
66
67 //! evil hack, using old formula import :-)
68 if( !rXclTokArr.Empty() )
69 {
70 SvMemoryStream aMemStrm;
71 aMemStrm << EXC_ID_EOF << rXclTokArr.GetSize();
72 aMemStrm.Write( rXclTokArr.GetData(), rXclTokArr.GetSize() );
73 XclImpStream aFmlaStrm( aMemStrm, GetRoot() );
74 aFmlaStrm.StartNextRecord();
75 GetOldFmlaConverter().GetAbsRefs( rScRanges, aFmlaStrm, aFmlaStrm.GetRecSize() );
76 }
77 }
78
CreateFormula(XclFormulaType,const XclTokenArray & rXclTokArr)79 const ScTokenArray* XclImpFmlaCompImpl::CreateFormula(
80 XclFormulaType /*eType*/, const XclTokenArray& rXclTokArr )
81 {
82 if (rXclTokArr.Empty())
83 return NULL;
84
85 // evil hack! are we trying to phase out the old style formula converter ?
86 SvMemoryStream aMemStrm;
87 aMemStrm << EXC_ID_EOF << rXclTokArr.GetSize();
88 aMemStrm.Write( rXclTokArr.GetData(), rXclTokArr.GetSize() );
89 XclImpStream aFmlaStrm( aMemStrm, GetRoot() );
90 aFmlaStrm.StartNextRecord();
91 const ScTokenArray* pArray = NULL;
92 GetOldFmlaConverter().Reset();
93 GetOldFmlaConverter().Convert(pArray, aFmlaStrm, aFmlaStrm.GetRecSize(), true);
94 return pArray;
95 }
96
97 // ----------------------------------------------------------------------------
98
XclImpFormulaCompiler(const XclImpRoot & rRoot)99 XclImpFormulaCompiler::XclImpFormulaCompiler( const XclImpRoot& rRoot ) :
100 XclImpRoot( rRoot ),
101 mxImpl( new XclImpFmlaCompImpl( rRoot ) )
102 {
103 }
104
~XclImpFormulaCompiler()105 XclImpFormulaCompiler::~XclImpFormulaCompiler()
106 {
107 }
108
CreateRangeList(ScRangeList & rScRanges,XclFormulaType eType,const XclTokenArray & rXclTokArr,XclImpStream & rStrm)109 void XclImpFormulaCompiler::CreateRangeList(
110 ScRangeList& rScRanges, XclFormulaType eType,
111 const XclTokenArray& rXclTokArr, XclImpStream& rStrm )
112 {
113 mxImpl->CreateRangeList( rScRanges, eType, rXclTokArr, rStrm );
114 }
115
CreateFormula(XclFormulaType eType,const XclTokenArray & rXclTokArr)116 const ScTokenArray* XclImpFormulaCompiler::CreateFormula(
117 XclFormulaType eType, const XclTokenArray& rXclTokArr )
118 {
119 return mxImpl->CreateFormula(eType, rXclTokArr);
120 }
121
122 // ============================================================================
123
124