LCOV - code coverage report
Current view: top level - libreoffice/reportdesign/source/ui/misc - FunctionHelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 104 0.0 %
Date: 2012-12-27 Functions: 0 29 0.0 %
Legend: Lines: hit not hit

          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             : 
      21             : #include "FunctionHelper.hxx"
      22             : 
      23             : // =============================================================================
      24             : namespace rptui
      25             : {
      26             : // =============================================================================
      27             :     using namespace ::com::sun::star;
      28             : 
      29           0 : FunctionManager::FunctionManager(const uno::Reference< report::meta::XFunctionManager>& _xMgr)
      30           0 : : m_xMgr(_xMgr)
      31             : {
      32           0 : }
      33           0 : FunctionManager::~FunctionManager()
      34             : {
      35           0 : }
      36           0 : sal_Unicode FunctionManager::getSingleToken(const formula::IFunctionManager::EToken _eToken) const
      37             : {
      38           0 :     switch(_eToken)
      39             :     {
      40             :         case eOk:
      41           0 :             return sal_Unicode('(');
      42             :         case eClose:
      43           0 :             return sal_Unicode(')');
      44             :         case eSep:
      45           0 :             return sal_Unicode(';');
      46             :         case eArrayOpen:
      47           0 :             return sal_Unicode('{');
      48             :         case eArrayClose:
      49           0 :             return sal_Unicode('}');
      50             :     }
      51           0 :     return 0;
      52             : }
      53             : // -----------------------------------------------------------------------------
      54           0 : sal_uInt32 FunctionManager::getCount() const
      55             : {
      56           0 :     return m_xMgr->getCount();
      57             : }
      58             : // -----------------------------------------------------------------------------
      59           0 : const formula::IFunctionCategory* FunctionManager::getCategory(sal_uInt32 _nPos) const
      60             : {
      61           0 :     if ( _nPos >= m_aCategoryIndex.size() )
      62             :     {
      63           0 :         uno::Reference< report::meta::XFunctionCategory> xCategory = m_xMgr->getCategory(_nPos);
      64           0 :         ::boost::shared_ptr< FunctionCategory > pCategory(new FunctionCategory(this,_nPos + 1,xCategory));
      65           0 :         m_aCategoryIndex.push_back( m_aCategories.insert(TCategoriesMap::value_type(xCategory->getName(),pCategory)).first );
      66             :     }
      67           0 :     return m_aCategoryIndex[_nPos]->second.get();
      68             : }
      69             : // -----------------------------------------------------------------------------
      70           0 : const formula::IFunctionDescription* FunctionManager::getFunctionByName(const ::rtl::OUString& _sFunctionName) const
      71             : {
      72           0 :     const formula::IFunctionDescription* pDesc = NULL;
      73             :     try
      74             :     {
      75           0 :         pDesc = get(m_xMgr->getFunctionByName(_sFunctionName)).get();
      76             :     }
      77           0 :     catch(uno::Exception&)
      78             :     {
      79             :     }
      80           0 :     return pDesc;
      81             : }
      82             : // -----------------------------------------------------------------------------
      83           0 : void FunctionManager::fillLastRecentlyUsedFunctions(::std::vector< const formula::IFunctionDescription*>& /*_rLastRUFunctions*/) const
      84             : {
      85           0 : }
      86             : // -----------------------------------------------------------------------------
      87           0 : ::boost::shared_ptr< FunctionDescription > FunctionManager::get(const uno::Reference< report::meta::XFunctionDescription>& _xFunctionDescription) const
      88             : {
      89           0 :     ::boost::shared_ptr< FunctionDescription > pDesc;
      90           0 :     if ( _xFunctionDescription.is() )
      91             :     {
      92           0 :         const ::rtl::OUString sFunctionName = _xFunctionDescription->getName();
      93           0 :         TFunctionsMap::const_iterator aFunctionFind = m_aFunctions.find(sFunctionName);
      94           0 :         if ( aFunctionFind == m_aFunctions.end() )
      95             :         {
      96           0 :             const uno::Reference< report::meta::XFunctionCategory> xCategory = _xFunctionDescription->getCategory();
      97           0 :             const ::rtl::OUString sCategoryName = xCategory->getName();
      98           0 :             TCategoriesMap::iterator aCategoryFind = m_aCategories.find(sCategoryName);
      99           0 :             if ( aCategoryFind == m_aCategories.end() )
     100             :             {
     101           0 :                 aCategoryFind = m_aCategories.insert(TCategoriesMap::value_type(sCategoryName,::boost::shared_ptr< FunctionCategory > (new FunctionCategory(this,xCategory->getNumber() + 1,xCategory)))).first;
     102           0 :                 m_aCategoryIndex.push_back( aCategoryFind );
     103             :             }
     104           0 :             aFunctionFind = m_aFunctions.insert(TFunctionsMap::value_type(sFunctionName,::boost::shared_ptr<FunctionDescription>(new FunctionDescription(aCategoryFind->second.get(),_xFunctionDescription)))).first;
     105             :         }
     106           0 :         pDesc = aFunctionFind->second;
     107             :     }
     108           0 :     return pDesc;
     109             : }
     110             : // -----------------------------------------------------------------------------
     111           0 : FunctionCategory::FunctionCategory(const FunctionManager* _pFMgr,sal_uInt32 _nPos,const uno::Reference< report::meta::XFunctionCategory>& _xCategory)
     112             : : m_xCategory(_xCategory)
     113           0 : ,m_nFunctionCount(_xCategory->getCount())
     114             : , m_nNumber(_nPos)
     115           0 : ,m_pFunctionManager(_pFMgr)
     116             : {
     117           0 : }
     118             : // -----------------------------------------------------------------------------
     119           0 : sal_uInt32 FunctionCategory::getCount() const
     120             : {
     121           0 :     return m_nFunctionCount;
     122             : }
     123             : // -----------------------------------------------------------------------------
     124           0 : const formula::IFunctionDescription* FunctionCategory::getFunction(sal_uInt32 _nPos) const
     125             : {
     126           0 :     if ( _nPos >= m_aFunctions.size() && _nPos < m_nFunctionCount )
     127             :     {
     128           0 :         uno::Reference< report::meta::XFunctionDescription> xFunctionDescription = m_xCategory->getFunction(_nPos);
     129           0 :         ::boost::shared_ptr< FunctionDescription > pFunction = m_pFunctionManager->get(xFunctionDescription);
     130           0 :         m_aFunctions.push_back( pFunction );
     131             :     }
     132           0 :     return m_aFunctions[_nPos].get();
     133             : }
     134             : // -----------------------------------------------------------------------------
     135           0 : sal_uInt32 FunctionCategory::getNumber() const
     136             : {
     137           0 :     return m_nNumber;
     138             : }
     139             : // -----------------------------------------------------------------------------
     140           0 : const formula::IFunctionManager* FunctionCategory::getFunctionManager() const
     141             : {
     142           0 :     return m_pFunctionManager;
     143             : }
     144             : // -----------------------------------------------------------------------------
     145           0 : ::rtl::OUString FunctionCategory::getName() const
     146             : {
     147           0 :     return m_xCategory->getName();
     148             : }
     149             : // -----------------------------------------------------------------------------
     150           0 : FunctionDescription::FunctionDescription(const formula::IFunctionCategory* _pFunctionCategory,const uno::Reference< report::meta::XFunctionDescription>& _xFunctionDescription)
     151             : : m_xFunctionDescription(_xFunctionDescription)
     152           0 : , m_pFunctionCategory(_pFunctionCategory)
     153             : {
     154           0 :     m_aParameter = m_xFunctionDescription->getArguments();
     155           0 : }
     156           0 : ::rtl::OUString FunctionDescription::getFunctionName() const
     157             : {
     158           0 :     return m_xFunctionDescription->getName();
     159             : }
     160             : // -----------------------------------------------------------------------------
     161           0 : const formula::IFunctionCategory* FunctionDescription::getCategory() const
     162             : {
     163           0 :     return m_pFunctionCategory;
     164             : }
     165             : // -----------------------------------------------------------------------------
     166           0 : ::rtl::OUString FunctionDescription::getDescription() const
     167             : {
     168           0 :     return m_xFunctionDescription->getDescription();
     169             : }
     170             : // -----------------------------------------------------------------------------
     171           0 : xub_StrLen FunctionDescription::getSuppressedArgumentCount() const
     172             : {
     173           0 :     return static_cast<xub_StrLen>(m_aParameter.getLength());
     174             : }
     175             : // -----------------------------------------------------------------------------
     176           0 : ::rtl::OUString FunctionDescription::getFormula(const ::std::vector< ::rtl::OUString >& _aArguments) const
     177             : {
     178           0 :     ::rtl::OUString sFormula;
     179             :     try
     180             :     {
     181           0 :         const ::rtl::OUString *pArguments = _aArguments.empty() ? 0 : &_aArguments[0];
     182           0 :         sFormula = m_xFunctionDescription->createFormula(uno::Sequence< ::rtl::OUString >(pArguments, _aArguments.size()));
     183             :     }
     184           0 :     catch(const uno::Exception&)
     185             :     {
     186             :         OSL_FAIL("Exception caught!");
     187             :     }
     188           0 :     return sFormula;
     189             : }
     190             : // -----------------------------------------------------------------------------
     191           0 : void FunctionDescription::fillVisibleArgumentMapping(::std::vector<sal_uInt16>& _rArguments) const
     192             : {
     193           0 :     const sal_Int32 nCount = m_aParameter.getLength();
     194           0 :     for(sal_uInt16 i = 0;i < nCount; ++i)
     195             :     {
     196           0 :         _rArguments.push_back(i);
     197             :     }
     198           0 : }
     199             : // -----------------------------------------------------------------------------
     200           0 : void FunctionDescription::initArgumentInfo()  const
     201             : {
     202           0 : }
     203             : // -----------------------------------------------------------------------------
     204           0 : ::rtl::OUString FunctionDescription::getSignature() const
     205             : {
     206           0 :     return m_xFunctionDescription->getSignature();
     207             : }
     208             : // -----------------------------------------------------------------------------
     209           0 : rtl::OString FunctionDescription::getHelpId() const
     210             : {
     211           0 :     return rtl::OString();
     212             : }
     213             : // -----------------------------------------------------------------------------
     214           0 : sal_uInt32 FunctionDescription::getParameterCount() const
     215             : {
     216           0 :     return m_aParameter.getLength();
     217             : }
     218             : // -----------------------------------------------------------------------------
     219           0 : ::rtl::OUString FunctionDescription::getParameterName(sal_uInt32 _nPos) const
     220             : {
     221           0 :     if ( _nPos < static_cast<sal_uInt32>(m_aParameter.getLength()) )
     222           0 :         return m_aParameter[_nPos].Name;
     223           0 :     return ::rtl::OUString();
     224             : }
     225             : // -----------------------------------------------------------------------------
     226           0 : ::rtl::OUString FunctionDescription::getParameterDescription(sal_uInt32 _nPos) const
     227             : {
     228           0 :     if ( _nPos < static_cast<sal_uInt32>(m_aParameter.getLength()) )
     229           0 :         return m_aParameter[_nPos].Description;
     230           0 :     return ::rtl::OUString();
     231             : }
     232             : // -----------------------------------------------------------------------------
     233           0 : bool FunctionDescription::isParameterOptional(sal_uInt32 _nPos) const
     234             : {
     235           0 :     if ( _nPos < static_cast<sal_uInt32>(m_aParameter.getLength()) )
     236           0 :         return m_aParameter[_nPos].IsOptional;
     237           0 :     return false;
     238             : }
     239             : // -----------------------------------------------------------------------------
     240             : // =============================================================================
     241             : } // rptui
     242             : // =============================================================================
     243             : 
     244             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10