Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "FunctionHelper.hxx"
31 : :
32 : : // =============================================================================
33 : : namespace rptui
34 : : {
35 : : // =============================================================================
36 : : using namespace ::com::sun::star;
37 : :
38 : 0 : FunctionManager::FunctionManager(const uno::Reference< report::meta::XFunctionManager>& _xMgr)
39 : 0 : : m_xMgr(_xMgr)
40 : : {
41 : 0 : }
42 : 0 : FunctionManager::~FunctionManager()
43 : : {
44 : 0 : }
45 : 0 : sal_Unicode FunctionManager::getSingleToken(const formula::IFunctionManager::EToken _eToken) const
46 : : {
47 : 0 : switch(_eToken)
48 : : {
49 : : case eOk:
50 : 0 : return sal_Unicode('(');
51 : : case eClose:
52 : 0 : return sal_Unicode(')');
53 : : case eSep:
54 : 0 : return sal_Unicode(';');
55 : : case eArrayOpen:
56 : 0 : return sal_Unicode('{');
57 : : case eArrayClose:
58 : 0 : return sal_Unicode('}');
59 : : }
60 : 0 : return 0;
61 : : }
62 : : // -----------------------------------------------------------------------------
63 : 0 : sal_uInt32 FunctionManager::getCount() const
64 : : {
65 : 0 : return m_xMgr->getCount();
66 : : }
67 : : // -----------------------------------------------------------------------------
68 : 0 : const formula::IFunctionCategory* FunctionManager::getCategory(sal_uInt32 _nPos) const
69 : : {
70 : 0 : if ( _nPos >= m_aCategoryIndex.size() )
71 : : {
72 : 0 : uno::Reference< report::meta::XFunctionCategory> xCategory = m_xMgr->getCategory(_nPos);
73 : 0 : ::boost::shared_ptr< FunctionCategory > pCategory(new FunctionCategory(this,_nPos + 1,xCategory));
74 : 0 : m_aCategoryIndex.push_back( m_aCategories.insert(TCategoriesMap::value_type(xCategory->getName(),pCategory)).first );
75 : : }
76 : 0 : return m_aCategoryIndex[_nPos]->second.get();
77 : : }
78 : : // -----------------------------------------------------------------------------
79 : 0 : const formula::IFunctionDescription* FunctionManager::getFunctionByName(const ::rtl::OUString& _sFunctionName) const
80 : : {
81 : 0 : const formula::IFunctionDescription* pDesc = NULL;
82 : : try
83 : : {
84 : 0 : pDesc = get(m_xMgr->getFunctionByName(_sFunctionName)).get();
85 : : }
86 : 0 : catch(uno::Exception&)
87 : : {
88 : : }
89 : 0 : return pDesc;
90 : : }
91 : : // -----------------------------------------------------------------------------
92 : 0 : void FunctionManager::fillLastRecentlyUsedFunctions(::std::vector< const formula::IFunctionDescription*>& /*_rLastRUFunctions*/) const
93 : : {
94 : 0 : }
95 : : // -----------------------------------------------------------------------------
96 : 0 : ::boost::shared_ptr< FunctionDescription > FunctionManager::get(const uno::Reference< report::meta::XFunctionDescription>& _xFunctionDescription) const
97 : : {
98 : 0 : ::boost::shared_ptr< FunctionDescription > pDesc;
99 : 0 : if ( _xFunctionDescription.is() )
100 : : {
101 : 0 : const ::rtl::OUString sFunctionName = _xFunctionDescription->getName();
102 : 0 : TFunctionsMap::const_iterator aFunctionFind = m_aFunctions.find(sFunctionName);
103 : 0 : if ( aFunctionFind == m_aFunctions.end() )
104 : : {
105 : 0 : const uno::Reference< report::meta::XFunctionCategory> xCategory = _xFunctionDescription->getCategory();
106 : 0 : const ::rtl::OUString sCategoryName = xCategory->getName();
107 : 0 : TCategoriesMap::iterator aCategoryFind = m_aCategories.find(sCategoryName);
108 : 0 : if ( aCategoryFind == m_aCategories.end() )
109 : : {
110 : 0 : aCategoryFind = m_aCategories.insert(TCategoriesMap::value_type(sCategoryName,::boost::shared_ptr< FunctionCategory > (new FunctionCategory(this,xCategory->getNumber() + 1,xCategory)))).first;
111 : 0 : m_aCategoryIndex.push_back( aCategoryFind );
112 : : }
113 : 0 : aFunctionFind = m_aFunctions.insert(TFunctionsMap::value_type(sFunctionName,::boost::shared_ptr<FunctionDescription>(new FunctionDescription(aCategoryFind->second.get(),_xFunctionDescription)))).first;
114 : : }
115 : 0 : pDesc = aFunctionFind->second;
116 : : }
117 : 0 : return pDesc;
118 : : }
119 : : // -----------------------------------------------------------------------------
120 : 0 : FunctionCategory::FunctionCategory(const FunctionManager* _pFMgr,sal_uInt32 _nPos,const uno::Reference< report::meta::XFunctionCategory>& _xCategory)
121 : : : m_xCategory(_xCategory)
122 : 0 : ,m_nFunctionCount(_xCategory->getCount())
123 : : , m_nNumber(_nPos)
124 : 0 : ,m_pFunctionManager(_pFMgr)
125 : : {
126 : 0 : }
127 : : // -----------------------------------------------------------------------------
128 : 0 : sal_uInt32 FunctionCategory::getCount() const
129 : : {
130 : 0 : return m_nFunctionCount;
131 : : }
132 : : // -----------------------------------------------------------------------------
133 : 0 : const formula::IFunctionDescription* FunctionCategory::getFunction(sal_uInt32 _nPos) const
134 : : {
135 : 0 : if ( _nPos >= m_aFunctions.size() && _nPos < m_nFunctionCount )
136 : : {
137 : 0 : uno::Reference< report::meta::XFunctionDescription> xFunctionDescription = m_xCategory->getFunction(_nPos);
138 : 0 : ::boost::shared_ptr< FunctionDescription > pFunction = m_pFunctionManager->get(xFunctionDescription);
139 : 0 : m_aFunctions.push_back( pFunction );
140 : : }
141 : 0 : return m_aFunctions[_nPos].get();
142 : : }
143 : : // -----------------------------------------------------------------------------
144 : 0 : sal_uInt32 FunctionCategory::getNumber() const
145 : : {
146 : 0 : return m_nNumber;
147 : : }
148 : : // -----------------------------------------------------------------------------
149 : 0 : const formula::IFunctionManager* FunctionCategory::getFunctionManager() const
150 : : {
151 : 0 : return m_pFunctionManager;
152 : : }
153 : : // -----------------------------------------------------------------------------
154 : 0 : ::rtl::OUString FunctionCategory::getName() const
155 : : {
156 : 0 : return m_xCategory->getName();
157 : : }
158 : : // -----------------------------------------------------------------------------
159 : 0 : FunctionDescription::FunctionDescription(const formula::IFunctionCategory* _pFunctionCategory,const uno::Reference< report::meta::XFunctionDescription>& _xFunctionDescription)
160 : : : m_xFunctionDescription(_xFunctionDescription)
161 : 0 : , m_pFunctionCategory(_pFunctionCategory)
162 : : {
163 : 0 : m_aParameter = m_xFunctionDescription->getArguments();
164 : 0 : }
165 : 0 : ::rtl::OUString FunctionDescription::getFunctionName() const
166 : : {
167 : 0 : return m_xFunctionDescription->getName();
168 : : }
169 : : // -----------------------------------------------------------------------------
170 : 0 : const formula::IFunctionCategory* FunctionDescription::getCategory() const
171 : : {
172 : 0 : return m_pFunctionCategory;
173 : : }
174 : : // -----------------------------------------------------------------------------
175 : 0 : ::rtl::OUString FunctionDescription::getDescription() const
176 : : {
177 : 0 : return m_xFunctionDescription->getDescription();
178 : : }
179 : : // -----------------------------------------------------------------------------
180 : 0 : xub_StrLen FunctionDescription::getSuppressedArgumentCount() const
181 : : {
182 : 0 : return static_cast<xub_StrLen>(m_aParameter.getLength());
183 : : }
184 : : // -----------------------------------------------------------------------------
185 : 0 : ::rtl::OUString FunctionDescription::getFormula(const ::std::vector< ::rtl::OUString >& _aArguments) const
186 : : {
187 : 0 : ::rtl::OUString sFormula;
188 : : try
189 : : {
190 : 0 : const ::rtl::OUString *pArguments = _aArguments.empty() ? 0 : &_aArguments[0];
191 : 0 : sFormula = m_xFunctionDescription->createFormula(uno::Sequence< ::rtl::OUString >(pArguments, _aArguments.size()));
192 : : }
193 : 0 : catch(const uno::Exception&)
194 : : {
195 : : OSL_FAIL("Exception caught!");
196 : : }
197 : 0 : return sFormula;
198 : : }
199 : : // -----------------------------------------------------------------------------
200 : 0 : void FunctionDescription::fillVisibleArgumentMapping(::std::vector<sal_uInt16>& _rArguments) const
201 : : {
202 : 0 : const sal_Int32 nCount = m_aParameter.getLength();
203 : 0 : for(sal_uInt16 i = 0;i < nCount; ++i)
204 : : {
205 : 0 : _rArguments.push_back(i);
206 : : }
207 : 0 : }
208 : : // -----------------------------------------------------------------------------
209 : 0 : void FunctionDescription::initArgumentInfo() const
210 : : {
211 : 0 : }
212 : : // -----------------------------------------------------------------------------
213 : 0 : ::rtl::OUString FunctionDescription::getSignature() const
214 : : {
215 : 0 : return m_xFunctionDescription->getSignature();
216 : : }
217 : : // -----------------------------------------------------------------------------
218 : 0 : rtl::OString FunctionDescription::getHelpId() const
219 : : {
220 : 0 : return rtl::OString();
221 : : }
222 : : // -----------------------------------------------------------------------------
223 : 0 : sal_uInt32 FunctionDescription::getParameterCount() const
224 : : {
225 : 0 : return m_aParameter.getLength();
226 : : }
227 : : // -----------------------------------------------------------------------------
228 : 0 : ::rtl::OUString FunctionDescription::getParameterName(sal_uInt32 _nPos) const
229 : : {
230 : 0 : if ( _nPos < static_cast<sal_uInt32>(m_aParameter.getLength()) )
231 : 0 : return m_aParameter[_nPos].Name;
232 : 0 : return ::rtl::OUString();
233 : : }
234 : : // -----------------------------------------------------------------------------
235 : 0 : ::rtl::OUString FunctionDescription::getParameterDescription(sal_uInt32 _nPos) const
236 : : {
237 : 0 : if ( _nPos < static_cast<sal_uInt32>(m_aParameter.getLength()) )
238 : 0 : return m_aParameter[_nPos].Description;
239 : 0 : return ::rtl::OUString();
240 : : }
241 : : // -----------------------------------------------------------------------------
242 : 0 : bool FunctionDescription::isParameterOptional(sal_uInt32 _nPos) const
243 : : {
244 : 0 : if ( _nPos < static_cast<sal_uInt32>(m_aParameter.getLength()) )
245 : 0 : return m_aParameter[_nPos].IsOptional;
246 : 0 : return false;
247 : : }
248 : : // -----------------------------------------------------------------------------
249 : : // =============================================================================
250 : : } // rptui
251 : : // =============================================================================
252 : :
253 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|