LCOV - code coverage report
Current view: top level - scaddins/source/datefunc - datefunc.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 56 0.0 %
Date: 2014-04-14 Functions: 0 32 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             : // date functions add in
      21             : 
      22             : #ifndef _SCA_DATEFUNC_HXX
      23             : #define _SCA_DATEFUNC_HXX
      24             : 
      25             : #include <string.h>
      26             : #include <com/sun/star/lang/XServiceName.hpp>
      27             : #include <com/sun/star/lang/XServiceInfo.hpp>
      28             : #include <com/sun/star/sheet/XAddIn.hpp>
      29             : #include <com/sun/star/sheet/XCompatibilityNames.hpp>
      30             : #include <com/sun/star/sheet/addin/XDateFunctions.hpp>
      31             : #include <com/sun/star/sheet/addin/XMiscFunctions.hpp>
      32             : #include <cppuhelper/implbase6.hxx>
      33             : #include <tools/resid.hxx>
      34             : #include <tools/rc.hxx>
      35             : #include <tools/resary.hxx>
      36             : 
      37             : class ScaList
      38             : {
      39             : private:
      40             :     static const sal_uInt32     nStartSize;
      41             :     static const sal_uInt32     nIncrSize;
      42             : 
      43             :     void**                      pData;          // pointer array
      44             :     sal_uInt32                  nSize;          // array size
      45             :     sal_uInt32                  nCount;         // next index to be inserted at
      46             :     sal_uInt32                  nCurr;          // current pos for iterations
      47             : 
      48             :     void                        _Grow();
      49             :     inline void                 Grow();
      50             : 
      51             : public:
      52             :                                 ScaList();
      53             :     virtual                     ~ScaList();
      54             : 
      55           0 :     inline sal_uInt32           Count() const       { return nCount; }
      56             : 
      57           0 :     inline const void*          GetObject( sal_uInt32 nIndex ) const
      58           0 :                                     { return (nIndex < nCount) ? pData[ nIndex ] : NULL; }
      59             : 
      60           0 :     inline void*                First() { return nCount ? pData[ nCurr = 0 ] : NULL; }
      61           0 :     inline void*                Next()  { return (nCurr + 1 < nCount) ? pData[ ++nCurr ] : NULL; }
      62             : 
      63             :     inline void                 Append( void* pNew );
      64             : };
      65             : 
      66             : 
      67           0 : inline void ScaList::Grow()
      68             : {
      69           0 :     if( nCount >= nSize )
      70           0 :         _Grow();
      71           0 : }
      72             : 
      73           0 : inline void ScaList::Append( void* pNew )
      74             : {
      75           0 :     Grow();
      76           0 :     pData[ nCount++ ] = pNew;
      77           0 : }
      78             : 
      79             : 
      80             : class ScaStringList : protected ScaList
      81             : {
      82             : public:
      83           0 :     inline                      ScaStringList() : ScaList() {};
      84             :     virtual                     ~ScaStringList();
      85             : 
      86             :                                 using ScaList::Count;
      87             : 
      88             :     inline const OUString* Get( sal_uInt32 nIndex ) const;
      89             : 
      90             :     inline OUString*     First();
      91             :     inline OUString*     Next();
      92             : 
      93             :     using ScaList::Append;
      94             :     inline void                 Append( OUString* pNew );
      95             :     inline void                 Append( const OUString& rNew );
      96             : };
      97             : 
      98             : 
      99           0 : inline const OUString* ScaStringList::Get( sal_uInt32 nIndex ) const
     100             : {
     101           0 :     return static_cast< const OUString* >( ScaList::GetObject( nIndex ) );
     102             : }
     103             : 
     104           0 : inline OUString* ScaStringList::First()
     105             : {
     106           0 :     return static_cast< OUString* >( ScaList::First() );
     107             : }
     108             : 
     109           0 : inline OUString* ScaStringList::Next()
     110             : {
     111           0 :     return static_cast< OUString* >( ScaList::Next() );
     112             : }
     113             : 
     114             : inline void ScaStringList::Append( OUString* pNew )
     115             : {
     116             :     ScaList::Append( pNew );
     117             : }
     118             : 
     119           0 : inline void ScaStringList::Append( const OUString& rNew )
     120             : {
     121           0 :     ScaList::Append( new OUString( rNew ) );
     122           0 : }
     123             : 
     124             : 
     125             : class ScaResId : public ResId
     126             : {
     127             : public:
     128             :                                 ScaResId( sal_uInt16 nResId, ResMgr& rResMgr );
     129             : };
     130             : 
     131             : 
     132           0 : class ScaResStringLoader : public Resource
     133             : {
     134             : private:
     135             :     OUString                    aStr;
     136             : 
     137             : public:
     138             :     inline                      ScaResStringLoader( sal_uInt16 nResId, sal_uInt16 nStrId, ResMgr& rResMgr );
     139             : 
     140           0 :     inline const OUString&      GetString() const   { return aStr; }
     141             : 
     142             : };
     143             : 
     144             : 
     145           0 : inline ScaResStringLoader::ScaResStringLoader( sal_uInt16 nResId, sal_uInt16 nStrId, ResMgr& rResMgr ) :
     146             :     Resource( ScaResId( nResId, rResMgr ) ),
     147           0 :     aStr( ScaResId( nStrId, rResMgr ) )
     148             : {
     149           0 :     FreeResource();
     150           0 : }
     151             : 
     152             : 
     153           0 : class ScaResStringArrLoader : public Resource
     154             : {
     155             : private:
     156             :     ResStringArray              aStrArray;
     157             : 
     158             : public:
     159             :     inline                      ScaResStringArrLoader( sal_uInt16 nResId, sal_uInt16 nArrayId, ResMgr& rResMgr );
     160             : 
     161           0 :     inline const ResStringArray& GetStringArray() const { return aStrArray; }
     162             : };
     163             : 
     164           0 : inline ScaResStringArrLoader::ScaResStringArrLoader( sal_uInt16 nResId, sal_uInt16 nArrayId, ResMgr& rResMgr ) :
     165             :     Resource( ScaResId( nResId, rResMgr ) ),
     166           0 :     aStrArray( ScaResId( nArrayId, rResMgr ) )
     167             : {
     168           0 :     FreeResource();
     169           0 : }
     170             : 
     171             : 
     172           0 : class ScaResPublisher : public Resource
     173             : {
     174             : public:
     175           0 :     inline                      ScaResPublisher( const ScaResId& rResId ) : Resource( rResId ) {}
     176             : 
     177           0 :     inline sal_Bool             IsAvailableRes( const ResId& rResId ) const
     178           0 :                                     { return Resource::IsAvailableRes( rResId ); }
     179           0 :     inline void                 FreeResource()
     180           0 :                                     { Resource::FreeResource(); }
     181             : };
     182             : 
     183             : 
     184           0 : class ScaFuncRes : public Resource
     185             : {
     186             : public:
     187             :                                 ScaFuncRes( ResId& rResId, ResMgr& rResMgr, sal_uInt16 nIndex, OUString& rRet );
     188             : };
     189             : 
     190             : 
     191             : enum ScaCategory
     192             : {
     193             :     ScaCat_AddIn,
     194             :     ScaCat_DateTime,
     195             :     ScaCat_Text,
     196             :     ScaCat_Finance,
     197             :     ScaCat_Inf,
     198             :     ScaCat_Math,
     199             :     ScaCat_Tech
     200             : };
     201             : 
     202             : struct ScaFuncDataBase
     203             : {
     204             :     const sal_Char*             pIntName;           // internal name (get***)
     205             :     sal_uInt16                  nUINameID;          // resource ID to UI name
     206             :     sal_uInt16                  nDescrID;           // resource ID to description, parameter names and ~ description
     207             :     sal_uInt16                  nCompListID;        // resource ID to list of valid names
     208             :     sal_uInt16                  nParamCount;        // number of named / described parameters
     209             :     ScaCategory                 eCat;               // function category
     210             :     sal_Bool                    bDouble;            // name already exist in Calc
     211             :     sal_Bool                    bWithOpt;           // first parameter is internal
     212             : };
     213             : 
     214             : class ScaFuncData
     215             : {
     216             : private:
     217             :     OUString             aIntName;           // internal name (get***)
     218             :     sal_uInt16                  nUINameID;          // resource ID to UI name
     219             :     sal_uInt16                  nDescrID;           // leads also to parameter descriptions!
     220             :     sal_uInt16                  nCompListID;        // resource ID to list of valid names
     221             :     sal_uInt16                  nParamCount;        // num of parameters
     222             :     ScaStringList               aCompList;          // list of all valid names
     223             :     ScaCategory                 eCat;               // function category
     224             :     sal_Bool                    bDouble;            // name already exist in Calc
     225             :     sal_Bool                    bWithOpt;           // first parameter is internal
     226             : 
     227             : public:
     228             :                                 ScaFuncData( const ScaFuncDataBase& rBaseData, ResMgr& rRscMgr );
     229             :     virtual                     ~ScaFuncData();
     230             : 
     231           0 :     inline sal_uInt16           GetUINameID() const     { return nUINameID; }
     232           0 :     inline sal_uInt16           GetDescrID() const      { return nDescrID; }
     233           0 :     inline ScaCategory          GetCategory() const     { return eCat; }
     234           0 :     inline sal_Bool             IsDouble() const        { return bDouble; }
     235             :     inline sal_Bool             HasIntParam() const     { return bWithOpt; }
     236             : 
     237             :     sal_uInt16                  GetStrIndex( sal_uInt16 nParam ) const;
     238           0 :     inline sal_Bool             Is( const OUString& rCompare ) const
     239           0 :                                                     { return aIntName == rCompare; }
     240             : 
     241           0 :     inline const ScaStringList& GetCompNameList() const { return aCompList; }
     242             : };
     243             : 
     244             : 
     245             : class ScaFuncDataList : private ScaList
     246             : {
     247             :     OUString             aLastName;
     248             :     sal_uInt32                  nLast;
     249             : 
     250             : public:
     251             :                                 ScaFuncDataList( ResMgr& rResMgr );
     252             :     virtual                     ~ScaFuncDataList();
     253             : 
     254             :                                 using ScaList::Count;
     255             : 
     256             :     inline const ScaFuncData*   Get( sal_uInt32 nIndex ) const;
     257             :     const ScaFuncData*          Get( const OUString& rProgrammaticName ) const;
     258             :     inline ScaFuncData*         First();
     259             :     inline ScaFuncData*         Next();
     260             : 
     261             :     using ScaList::Append;
     262           0 :     inline void                 Append( ScaFuncData* pNew ) { ScaList::Append( pNew ); }
     263             : };
     264             : 
     265             : 
     266           0 : inline const ScaFuncData* ScaFuncDataList::Get( sal_uInt32 nIndex ) const
     267             : {
     268           0 :     return static_cast< const ScaFuncData* >( ScaList::GetObject( nIndex ) );
     269             : }
     270             : 
     271           0 : inline ScaFuncData* ScaFuncDataList::First()
     272             : {
     273           0 :     return static_cast< ScaFuncData* >( ScaList::First() );
     274             : }
     275             : 
     276           0 : inline ScaFuncData* ScaFuncDataList::Next()
     277             : {
     278           0 :     return static_cast< ScaFuncData* >( ScaList::Next() );
     279             : }
     280             : 
     281             : 
     282             : 
     283             : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL DateFunctionAddIn_CreateInstance(
     284             :     const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& );
     285             : 
     286             : 
     287             : // THE AddIn class for date functions
     288             : 
     289             : class ScaDateAddIn : public ::cppu::WeakImplHelper6<
     290             :                                 ::com::sun::star::sheet::XAddIn,
     291             :                                 ::com::sun::star::sheet::XCompatibilityNames,
     292             :                                 ::com::sun::star::sheet::addin::XDateFunctions,
     293             :                                 ::com::sun::star::sheet::addin::XMiscFunctions,
     294             :                                 ::com::sun::star::lang::XServiceName,
     295             :                                 ::com::sun::star::lang::XServiceInfo >
     296             : {
     297             : private:
     298             :     ::com::sun::star::lang::Locale  aFuncLoc;
     299             :     ::com::sun::star::lang::Locale* pDefLocales;
     300             :     ResMgr*                     pResMgr;
     301             :     ScaFuncDataList*            pFuncDataList;
     302             : 
     303             : 
     304             :     void                        InitDefLocales();
     305             :     const ::com::sun::star::lang::Locale& GetLocale( sal_uInt32 nIndex );
     306             :     ResMgr&                     GetResMgr() throw( ::com::sun::star::uno::RuntimeException );
     307             :     void                        InitData();
     308             : 
     309             :     OUString             GetDisplFuncStr( sal_uInt16 nResId ) throw( ::com::sun::star::uno::RuntimeException );
     310             :     OUString             GetFuncDescrStr( sal_uInt16 nResId, sal_uInt16 nStrIndex ) throw( ::com::sun::star::uno::RuntimeException );
     311             : 
     312             : public:
     313             :                                 ScaDateAddIn();
     314             :     virtual                     ~ScaDateAddIn();
     315             : 
     316             :     static OUString      getImplementationName_Static();
     317             :     static ::com::sun::star::uno::Sequence< OUString > getSupportedServiceNames_Static();
     318             : 
     319             :                                 // XAddIn
     320             :     virtual OUString SAL_CALL getProgrammaticFuntionName( const OUString& aDisplayName ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     321             :     virtual OUString SAL_CALL getDisplayFunctionName( const OUString& aProgrammaticName ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     322             :     virtual OUString SAL_CALL getFunctionDescription( const OUString& aProgrammaticName ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     323             :     virtual OUString SAL_CALL getDisplayArgumentName( const OUString& aProgrammaticName, sal_Int32 nArgument ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     324             :     virtual OUString SAL_CALL getArgumentDescription( const OUString& aProgrammaticName, sal_Int32 nArgument ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     325             :     virtual OUString SAL_CALL getProgrammaticCategoryName( const OUString& aProgrammaticName ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     326             :     virtual OUString SAL_CALL getDisplayCategoryName( const OUString& aProgrammaticName ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     327             : 
     328             :                                 // XCompatibilityNames
     329             :     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::LocalizedName > SAL_CALL getCompatibilityNames( const OUString& aProgrammaticName ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     330             : 
     331             :                                 // XLocalizable
     332             :     virtual void SAL_CALL       setLocale( const ::com::sun::star::lang::Locale& eLocale ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     333             :     virtual ::com::sun::star::lang::Locale SAL_CALL getLocale() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     334             : 
     335             :                                 // XServiceName
     336             :     virtual OUString SAL_CALL getServiceName() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     337             : 
     338             :                                 // XServiceInfo
     339             :     virtual OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     340             :     virtual sal_Bool SAL_CALL   supportsService( const OUString& ServiceName ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     341             :     virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     342             : 
     343             :     //  methods from own interfaces start here
     344             : 
     345             :                                 // XDateFunctions
     346             :     virtual sal_Int32 SAL_CALL  getDiffWeeks(
     347             :                                     const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xOptions,
     348             :                                     sal_Int32 nEndDate, sal_Int32 nStartDate,
     349             :                                     sal_Int32 nMode )
     350             :                                 throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, std::exception ) SAL_OVERRIDE;
     351             : 
     352             :     virtual sal_Int32 SAL_CALL  getDiffMonths(
     353             :                                     const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xOptions,
     354             :                                     sal_Int32 nEndDate, sal_Int32 nStartDate,
     355             :                                     sal_Int32 nMode )
     356             :                                 throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, std::exception ) SAL_OVERRIDE;
     357             : 
     358             :     virtual sal_Int32 SAL_CALL  getDiffYears(
     359             :                                     const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xOptions,
     360             :                                     sal_Int32 nEndDate, sal_Int32 nStartDate,
     361             :                                     sal_Int32 nMode )
     362             :                                 throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, std::exception ) SAL_OVERRIDE;
     363             : 
     364             :     virtual sal_Int32 SAL_CALL  getIsLeapYear(
     365             :                                     const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xOptions,
     366             :                                     sal_Int32 nDate )
     367             :                                 throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, std::exception ) SAL_OVERRIDE;
     368             : 
     369             :     virtual sal_Int32 SAL_CALL  getDaysInMonth(
     370             :                                     const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xOptions,
     371             :                                     sal_Int32 nDate )
     372             :                                 throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, std::exception ) SAL_OVERRIDE;
     373             : 
     374             :     virtual sal_Int32 SAL_CALL  getDaysInYear(
     375             :                                     const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xOptions,
     376             :                                     sal_Int32 nDate )
     377             :                                 throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, std::exception ) SAL_OVERRIDE;
     378             : 
     379             :     virtual sal_Int32 SAL_CALL  getWeeksInYear(
     380             :                                     const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xOptions,
     381             :                                     sal_Int32 nDate )
     382             :                                 throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, std::exception ) SAL_OVERRIDE;
     383             : 
     384             :                                 // XMiscFunctions
     385             :     virtual OUString SAL_CALL getRot13(
     386             :                                     const OUString& aSrcText )
     387             :                                 throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, std::exception ) SAL_OVERRIDE;
     388             : };
     389             : 
     390             : #endif  // _SCA_DATEFUNC_HXX
     391             : 
     392             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10