2010-10-12 15:59:03 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-10-01 16:08:38 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2009-02-20 10:24:14 +00:00
|
|
|
|
|
|
|
#include "FunctionHelper.hxx"
|
|
|
|
|
2014-11-14 22:52:35 +01:00
|
|
|
#include <osl/diagnose.h>
|
|
|
|
|
2014-02-25 19:49:46 +01:00
|
|
|
|
2009-02-20 10:24:14 +00:00
|
|
|
namespace rptui
|
|
|
|
{
|
2014-02-25 19:49:46 +01:00
|
|
|
|
2009-02-20 10:24:14 +00:00
|
|
|
using namespace ::com::sun::star;
|
|
|
|
|
|
|
|
FunctionManager::FunctionManager(const uno::Reference< report::meta::XFunctionManager>& _xMgr)
|
|
|
|
: m_xMgr(_xMgr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
FunctionManager::~FunctionManager()
|
|
|
|
{
|
|
|
|
}
|
2009-03-09 15:10:32 +00:00
|
|
|
sal_Unicode FunctionManager::getSingleToken(const formula::IFunctionManager::EToken _eToken) const
|
2009-02-20 10:24:14 +00:00
|
|
|
{
|
|
|
|
switch(_eToken)
|
|
|
|
{
|
|
|
|
case eOk:
|
2013-11-14 08:16:35 +02:00
|
|
|
return '(';
|
2009-02-20 10:24:14 +00:00
|
|
|
case eClose:
|
2013-11-14 08:16:35 +02:00
|
|
|
return ')';
|
2009-02-20 10:24:14 +00:00
|
|
|
case eSep:
|
2013-11-14 08:16:35 +02:00
|
|
|
return ';';
|
2009-02-20 10:24:14 +00:00
|
|
|
case eArrayOpen:
|
2013-11-14 08:16:35 +02:00
|
|
|
return '{';
|
2009-02-20 10:24:14 +00:00
|
|
|
case eArrayClose:
|
2013-11-14 08:16:35 +02:00
|
|
|
return '}';
|
2010-11-29 23:29:33 +09:00
|
|
|
}
|
2009-02-20 10:24:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2009-02-20 10:24:14 +00:00
|
|
|
sal_uInt32 FunctionManager::getCount() const
|
|
|
|
{
|
|
|
|
return m_xMgr->getCount();
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2009-02-20 10:24:14 +00:00
|
|
|
const formula::IFunctionCategory* FunctionManager::getCategory(sal_uInt32 _nPos) const
|
|
|
|
{
|
|
|
|
if ( _nPos >= m_aCategoryIndex.size() )
|
|
|
|
{
|
|
|
|
uno::Reference< report::meta::XFunctionCategory> xCategory = m_xMgr->getCategory(_nPos);
|
|
|
|
::boost::shared_ptr< FunctionCategory > pCategory(new FunctionCategory(this,_nPos + 1,xCategory));
|
|
|
|
m_aCategoryIndex.push_back( m_aCategories.insert(TCategoriesMap::value_type(xCategory->getName(),pCategory)).first );
|
|
|
|
}
|
|
|
|
return m_aCategoryIndex[_nPos]->second.get();
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
const formula::IFunctionDescription* FunctionManager::getFunctionByName(const OUString& _sFunctionName) const
|
2009-02-20 10:24:14 +00:00
|
|
|
{
|
|
|
|
const formula::IFunctionDescription* pDesc = NULL;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
pDesc = get(m_xMgr->getFunctionByName(_sFunctionName)).get();
|
|
|
|
}
|
|
|
|
catch(uno::Exception&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
return pDesc;
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2009-02-20 10:24:14 +00:00
|
|
|
void FunctionManager::fillLastRecentlyUsedFunctions(::std::vector< const formula::IFunctionDescription*>& /*_rLastRUFunctions*/) const
|
|
|
|
{
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2009-02-20 10:24:14 +00:00
|
|
|
::boost::shared_ptr< FunctionDescription > FunctionManager::get(const uno::Reference< report::meta::XFunctionDescription>& _xFunctionDescription) const
|
|
|
|
{
|
|
|
|
::boost::shared_ptr< FunctionDescription > pDesc;
|
|
|
|
if ( _xFunctionDescription.is() )
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString sFunctionName = _xFunctionDescription->getName();
|
2009-02-20 10:24:14 +00:00
|
|
|
TFunctionsMap::const_iterator aFunctionFind = m_aFunctions.find(sFunctionName);
|
|
|
|
if ( aFunctionFind == m_aFunctions.end() )
|
|
|
|
{
|
|
|
|
const uno::Reference< report::meta::XFunctionCategory> xCategory = _xFunctionDescription->getCategory();
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString sCategoryName = xCategory->getName();
|
2009-02-20 10:24:14 +00:00
|
|
|
TCategoriesMap::iterator aCategoryFind = m_aCategories.find(sCategoryName);
|
|
|
|
if ( aCategoryFind == m_aCategories.end() )
|
|
|
|
{
|
|
|
|
aCategoryFind = m_aCategories.insert(TCategoriesMap::value_type(sCategoryName,::boost::shared_ptr< FunctionCategory > (new FunctionCategory(this,xCategory->getNumber() + 1,xCategory)))).first;
|
|
|
|
m_aCategoryIndex.push_back( aCategoryFind );
|
|
|
|
}
|
|
|
|
aFunctionFind = m_aFunctions.insert(TFunctionsMap::value_type(sFunctionName,::boost::shared_ptr<FunctionDescription>(new FunctionDescription(aCategoryFind->second.get(),_xFunctionDescription)))).first;
|
2010-11-29 23:29:33 +09:00
|
|
|
}
|
2009-02-20 10:24:14 +00:00
|
|
|
pDesc = aFunctionFind->second;
|
2010-11-29 23:29:33 +09:00
|
|
|
}
|
2009-02-20 10:24:14 +00:00
|
|
|
return pDesc;
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2009-02-20 10:24:14 +00:00
|
|
|
FunctionCategory::FunctionCategory(const FunctionManager* _pFMgr,sal_uInt32 _nPos,const uno::Reference< report::meta::XFunctionCategory>& _xCategory)
|
|
|
|
: m_xCategory(_xCategory)
|
|
|
|
,m_nFunctionCount(_xCategory->getCount())
|
|
|
|
, m_nNumber(_nPos)
|
|
|
|
,m_pFunctionManager(_pFMgr)
|
|
|
|
{
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2009-02-20 10:24:14 +00:00
|
|
|
sal_uInt32 FunctionCategory::getCount() const
|
|
|
|
{
|
|
|
|
return m_nFunctionCount;
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2009-02-20 10:24:14 +00:00
|
|
|
const formula::IFunctionDescription* FunctionCategory::getFunction(sal_uInt32 _nPos) const
|
|
|
|
{
|
|
|
|
if ( _nPos >= m_aFunctions.size() && _nPos < m_nFunctionCount )
|
|
|
|
{
|
|
|
|
uno::Reference< report::meta::XFunctionDescription> xFunctionDescription = m_xCategory->getFunction(_nPos);
|
|
|
|
::boost::shared_ptr< FunctionDescription > pFunction = m_pFunctionManager->get(xFunctionDescription);
|
|
|
|
m_aFunctions.push_back( pFunction );
|
|
|
|
}
|
|
|
|
return m_aFunctions[_nPos].get();
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2009-02-20 10:24:14 +00:00
|
|
|
sal_uInt32 FunctionCategory::getNumber() const
|
|
|
|
{
|
|
|
|
return m_nNumber;
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2009-02-20 10:24:14 +00:00
|
|
|
const formula::IFunctionManager* FunctionCategory::getFunctionManager() const
|
|
|
|
{
|
|
|
|
return m_pFunctionManager;
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString FunctionCategory::getName() const
|
2009-02-20 10:24:14 +00:00
|
|
|
{
|
|
|
|
return m_xCategory->getName();
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2009-02-20 10:24:14 +00:00
|
|
|
FunctionDescription::FunctionDescription(const formula::IFunctionCategory* _pFunctionCategory,const uno::Reference< report::meta::XFunctionDescription>& _xFunctionDescription)
|
|
|
|
: m_xFunctionDescription(_xFunctionDescription)
|
|
|
|
, m_pFunctionCategory(_pFunctionCategory)
|
|
|
|
{
|
|
|
|
m_aParameter = m_xFunctionDescription->getArguments();
|
|
|
|
}
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString FunctionDescription::getFunctionName() const
|
2009-02-20 10:24:14 +00:00
|
|
|
{
|
|
|
|
return m_xFunctionDescription->getName();
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2009-02-20 10:24:14 +00:00
|
|
|
const formula::IFunctionCategory* FunctionDescription::getCategory() const
|
|
|
|
{
|
|
|
|
return m_pFunctionCategory;
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString FunctionDescription::getDescription() const
|
2009-02-20 10:24:14 +00:00
|
|
|
{
|
|
|
|
return m_xFunctionDescription->getDescription();
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2013-11-29 15:35:12 +02:00
|
|
|
sal_Int32 FunctionDescription::getSuppressedArgumentCount() const
|
2009-02-20 10:24:14 +00:00
|
|
|
{
|
2013-11-29 15:35:12 +02:00
|
|
|
return m_aParameter.getLength();
|
2009-02-20 10:24:14 +00:00
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString FunctionDescription::getFormula(const ::std::vector< OUString >& _aArguments) const
|
2009-02-20 10:24:14 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sFormula;
|
2009-02-20 10:24:14 +00:00
|
|
|
try
|
|
|
|
{
|
2015-01-28 17:53:30 +01:00
|
|
|
sFormula = m_xFunctionDescription->createFormula(uno::Sequence< OUString >(_aArguments.data(), _aArguments.size()));
|
2009-02-20 10:24:14 +00:00
|
|
|
}
|
|
|
|
catch(const uno::Exception&)
|
|
|
|
{
|
2011-02-26 10:45:02 +01:00
|
|
|
OSL_FAIL("Exception caught!");
|
2009-02-20 10:24:14 +00:00
|
|
|
}
|
|
|
|
return sFormula;
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2011-01-14 17:40:56 +01:00
|
|
|
void FunctionDescription::fillVisibleArgumentMapping(::std::vector<sal_uInt16>& _rArguments) const
|
2009-02-20 10:24:14 +00:00
|
|
|
{
|
|
|
|
const sal_Int32 nCount = m_aParameter.getLength();
|
2011-01-14 17:40:56 +01:00
|
|
|
for(sal_uInt16 i = 0;i < nCount; ++i)
|
2009-02-20 10:24:14 +00:00
|
|
|
{
|
|
|
|
_rArguments.push_back(i);
|
|
|
|
}
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2009-02-20 10:24:14 +00:00
|
|
|
void FunctionDescription::initArgumentInfo() const
|
|
|
|
{
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString FunctionDescription::getSignature() const
|
2009-02-20 10:24:14 +00:00
|
|
|
{
|
|
|
|
return m_xFunctionDescription->getSignature();
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OString FunctionDescription::getHelpId() const
|
2009-02-20 10:24:14 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
return OString();
|
2009-02-20 10:24:14 +00:00
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2009-02-20 10:24:14 +00:00
|
|
|
sal_uInt32 FunctionDescription::getParameterCount() const
|
|
|
|
{
|
|
|
|
return m_aParameter.getLength();
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString FunctionDescription::getParameterName(sal_uInt32 _nPos) const
|
2009-02-20 10:24:14 +00:00
|
|
|
{
|
|
|
|
if ( _nPos < static_cast<sal_uInt32>(m_aParameter.getLength()) )
|
|
|
|
return m_aParameter[_nPos].Name;
|
2013-04-07 12:06:47 +02:00
|
|
|
return OUString();
|
2009-02-20 10:24:14 +00:00
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString FunctionDescription::getParameterDescription(sal_uInt32 _nPos) const
|
2009-02-20 10:24:14 +00:00
|
|
|
{
|
|
|
|
if ( _nPos < static_cast<sal_uInt32>(m_aParameter.getLength()) )
|
|
|
|
return m_aParameter[_nPos].Description;
|
2013-04-07 12:06:47 +02:00
|
|
|
return OUString();
|
2009-02-20 10:24:14 +00:00
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2009-02-20 10:24:14 +00:00
|
|
|
bool FunctionDescription::isParameterOptional(sal_uInt32 _nPos) const
|
|
|
|
{
|
|
|
|
if ( _nPos < static_cast<sal_uInt32>(m_aParameter.getLength()) )
|
|
|
|
return m_aParameter[_nPos].IsOptional;
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2014-02-25 19:49:46 +01:00
|
|
|
|
2009-02-20 10:24:14 +00:00
|
|
|
} // rptui
|
2014-02-25 19:49:46 +01:00
|
|
|
|
2010-10-12 15:59:03 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|