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 #include "precompiled_formula.hxx"
24 #include "formula/FormulaOpCodeMapperObj.hxx"
25 #include "formula/opcode.hxx"
26 #include <comphelper/sequence.hxx>
27
28 // =============================================================================
29 namespace formula
30 {
31 // =============================================================================
32
33 using namespace ::com::sun::star;
34
35 // -----------------------------------------------------------------------------
36 // --------------------------------------------------------------------------------
supportsService(const::rtl::OUString & _rServiceName)37 sal_Bool SAL_CALL FormulaOpCodeMapperObj::supportsService( const ::rtl::OUString& _rServiceName ) throw(uno::RuntimeException)
38 {
39 return ::comphelper::findValue( getSupportedServiceNames_Static(), _rServiceName, sal_True ).getLength() != 0;
40 }
41 //------------------------------------------------------------------------
FormulaOpCodeMapperObj(::std::auto_ptr<FormulaCompiler> _pCompiler)42 FormulaOpCodeMapperObj::FormulaOpCodeMapperObj(::std::auto_ptr<FormulaCompiler> _pCompiler)
43 : m_pCompiler(_pCompiler)
44 {
45 }
46
~FormulaOpCodeMapperObj()47 FormulaOpCodeMapperObj::~FormulaOpCodeMapperObj()
48 {
49 }
50
51
getOpCodeExternal()52 ::sal_Int32 SAL_CALL FormulaOpCodeMapperObj::getOpCodeExternal()
53 throw (::com::sun::star::uno::RuntimeException)
54 {
55 return ocExternal;
56 }
57
58
getOpCodeUnknown()59 ::sal_Int32 SAL_CALL FormulaOpCodeMapperObj::getOpCodeUnknown()
60 throw (::com::sun::star::uno::RuntimeException)
61 {
62 return FormulaCompiler::OpCodeMap::getOpCodeUnknown();
63 }
64
65
66 ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken >
getMappings(const::com::sun::star::uno::Sequence<::rtl::OUString> & rNames,sal_Int32 nLanguage)67 SAL_CALL FormulaOpCodeMapperObj::getMappings(
68 const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rNames,
69 sal_Int32 nLanguage )
70 throw ( ::com::sun::star::lang::IllegalArgumentException,
71 ::com::sun::star::uno::RuntimeException)
72 {
73 FormulaCompiler::OpCodeMapPtr xMap = m_pCompiler->GetOpCodeMap( nLanguage);
74 if (!xMap)
75 throw lang::IllegalArgumentException();
76 return xMap->createSequenceOfFormulaTokens( *m_pCompiler,rNames);
77 }
78
79
80 ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaOpCodeMapEntry >
getAvailableMappings(sal_Int32 nLanguage,sal_Int32 nGroups)81 SAL_CALL FormulaOpCodeMapperObj::getAvailableMappings(
82 sal_Int32 nLanguage, sal_Int32 nGroups )
83 throw ( ::com::sun::star::lang::IllegalArgumentException,
84 ::com::sun::star::uno::RuntimeException)
85 {
86 FormulaCompiler::OpCodeMapPtr xMap = m_pCompiler->GetOpCodeMap( nLanguage);
87 if (!xMap)
88 throw lang::IllegalArgumentException();
89 return xMap->createSequenceOfAvailableMappings( *m_pCompiler,nGroups);
90 }
91 //--------------------------------------------------------------------------
getImplementationName()92 ::rtl::OUString SAL_CALL FormulaOpCodeMapperObj::getImplementationName( ) throw(uno::RuntimeException)
93 {
94 return getImplementationName_Static();
95 }
96 // -----------------------------------------------------------------------------
getImplementationName_Static()97 ::rtl::OUString SAL_CALL FormulaOpCodeMapperObj::getImplementationName_Static()
98 {
99 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "simple.formula.FormulaOpCodeMapperObj" ) );
100 }
101 // --------------------------------------------------------------------------------
getSupportedServiceNames()102 uno::Sequence< ::rtl::OUString > SAL_CALL FormulaOpCodeMapperObj::getSupportedServiceNames( ) throw(uno::RuntimeException)
103 {
104 return getSupportedServiceNames_Static();
105 }
getSupportedServiceNames_Static()106 uno::Sequence< rtl::OUString > SAL_CALL FormulaOpCodeMapperObj::getSupportedServiceNames_Static()
107 {
108 uno::Sequence< rtl::OUString > aSeq( 1 );
109 aSeq[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.FormulaOpCodeMapper" ));
110 return aSeq;
111 }
112
create(uno::Reference<uno::XComponentContext> const &)113 uno::Reference< uno::XInterface > SAL_CALL FormulaOpCodeMapperObj::create(
114 uno::Reference< uno::XComponentContext > const & /*_xContext*/)
115 {
116 return static_cast<sheet::XFormulaOpCodeMapper*>(new FormulaOpCodeMapperObj(::std::auto_ptr<FormulaCompiler>(new FormulaCompiler())));
117 }
118 // -----------------------------------------------------------------------------
119
120 // =============================================================================
121 } // formula
122 // =============================================================================
123