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

Generated by: LCOV version 1.10