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 168 : 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 84 : XclImpFmlaCompImpl::XclImpFmlaCompImpl( const XclImpRoot& rRoot ) :
46 : XclImpRoot( rRoot ),
47 84 : maFuncProv( rRoot )
48 : {
49 84 : }
50 :
51 2 : void XclImpFmlaCompImpl::CreateRangeList(
52 : ScRangeList& rScRanges, XclFormulaType /*eType*/,
53 : const XclTokenArray& rXclTokArr, XclImpStream& /*rStrm*/ )
54 : {
55 2 : rScRanges.RemoveAll();
56 :
57 : //FIXME: evil hack, using old formula import :-)
58 2 : if( !rXclTokArr.Empty() )
59 : {
60 2 : SvMemoryStream aMemStrm;
61 2 : aMemStrm.WriteUInt16( EXC_ID_EOF ).WriteUInt16( rXclTokArr.GetSize() );
62 2 : aMemStrm.Write( rXclTokArr.GetData(), rXclTokArr.GetSize() );
63 4 : XclImpStream aFmlaStrm( aMemStrm, GetRoot() );
64 2 : aFmlaStrm.StartNextRecord();
65 4 : GetOldFmlaConverter().GetAbsRefs( rScRanges, aFmlaStrm, aFmlaStrm.GetRecSize() );
66 : }
67 2 : }
68 :
69 101 : const ScTokenArray* XclImpFmlaCompImpl::CreateFormula(
70 : XclFormulaType /*eType*/, const XclTokenArray& rXclTokArr )
71 : {
72 101 : if (rXclTokArr.Empty())
73 0 : return NULL;
74 :
75 : // evil hack! are we trying to phase out the old style formula converter ?
76 101 : SvMemoryStream aMemStrm;
77 101 : aMemStrm.WriteUInt16( EXC_ID_EOF ).WriteUInt16( rXclTokArr.GetSize() );
78 101 : aMemStrm.Write( rXclTokArr.GetData(), rXclTokArr.GetSize() );
79 202 : XclImpStream aFmlaStrm( aMemStrm, GetRoot() );
80 101 : aFmlaStrm.StartNextRecord();
81 101 : const ScTokenArray* pArray = NULL;
82 101 : GetOldFmlaConverter().Reset();
83 101 : GetOldFmlaConverter().Convert(pArray, aFmlaStrm, aFmlaStrm.GetRecSize(), true);
84 202 : return pArray;
85 : }
86 :
87 84 : XclImpFormulaCompiler::XclImpFormulaCompiler( const XclImpRoot& rRoot ) :
88 : XclImpRoot( rRoot ),
89 84 : mxImpl( new XclImpFmlaCompImpl( rRoot ) )
90 : {
91 84 : }
92 :
93 168 : XclImpFormulaCompiler::~XclImpFormulaCompiler()
94 : {
95 168 : }
96 :
97 2 : void XclImpFormulaCompiler::CreateRangeList(
98 : ScRangeList& rScRanges, XclFormulaType eType,
99 : const XclTokenArray& rXclTokArr, XclImpStream& rStrm )
100 : {
101 2 : mxImpl->CreateRangeList( rScRanges, eType, rXclTokArr, rStrm );
102 2 : }
103 :
104 101 : const ScTokenArray* XclImpFormulaCompiler::CreateFormula(
105 : XclFormulaType eType, const XclTokenArray& rXclTokArr )
106 : {
107 101 : return mxImpl->CreateFormula(eType, rXclTokArr);
108 30 : }
109 :
110 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|