LCOV - code coverage report
Current view: top level - include/tools - resmgr.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 14 14 100.0 %
Date: 2014-04-11 Functions: 7 7 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             : #ifndef INCLUDED_TOOLS_RESMGR_HXX
      20             : #define INCLUDED_TOOLS_RESMGR_HXX
      21             : 
      22             : #include <tools/toolsdllapi.h>
      23             : #include <i18nlangtag/languagetag.hxx>
      24             : #include <tools/resid.hxx>
      25             : 
      26             : #include <vector>
      27             : 
      28             : class SvStream;
      29             : class InternalResMgr;
      30             : 
      31             : /// Defines structure used to build resource
      32             : struct RSHEADER_TYPE
      33             : {
      34             : private:
      35             :     sal_uInt32              nId;        ///< Identifier of resource
      36             :     RESOURCE_TYPE           nRT;        ///< Resource type
      37             :     sal_uInt32              nGlobOff;   ///< Global offset
      38             :     sal_uInt32              nLocalOff;  ///< Local offset
      39             : 
      40             : public:
      41             :     inline sal_uInt32       GetId();    ///< Identifier of resource
      42             :     inline RESOURCE_TYPE    GetRT();    ///< Resource type
      43             :     inline sal_uInt32       GetGlobOff();  ///< Global offset
      44             :     inline sal_uInt32       GetLocalOff(); ///< Local offset
      45             : };
      46             : 
      47             : typedef OUString (*ResHookProc)( const OUString& rStr );
      48             : 
      49             : // Initialization
      50             : #define RC_NOTYPE               0x00
      51             : // Global resource
      52             : #define RC_GLOBAL               0x01
      53             : #define RC_AUTORELEASE          0x02
      54             : #define RC_NOTFOUND             0x04
      55             : #define RC_FALLBACK_DOWN        0x08
      56             : #define RC_FALLBACK_UP          0x10
      57             : 
      58             : class Resource;
      59             : class ResMgr;
      60             : 
      61             : struct ImpRCStack
      62             : {
      63             :     // pResource and pClassRes equal NULL: resource was not loaded
      64             :     RSHEADER_TYPE * pResource;  ///< pointer to resource
      65             :     void          * pClassRes;  ///< pointer to class specified init data
      66             :     short           Flags;      ///< resource status
      67             :     void *          aResHandle; ///< Resource-Identifier from InternalResMgr
      68             :     const Resource* pResObj;    ///< pointer to Resource object
      69             :     sal_uInt32      nId;        ///< ResId used for error message
      70             :     ResMgr*         pResMgr;    ///< ResMgr for Resource pResObj
      71             : 
      72             :     void            Clear();
      73             :     void            Init( ResMgr * pMgr, const Resource * pObj, sal_uInt32 nId );
      74             : };
      75             : 
      76             : class TOOLS_DLLPUBLIC ResMgr
      77             : {
      78             : private:
      79             :     InternalResMgr* pImpRes;
      80             :     std::vector< ImpRCStack >  aStack; ///< resource context stack
      81             :     int             nCurStack;
      82             :     ResMgr*         pFallbackResMgr;   ///< fallback ResMgr in case the Resource
      83             :                                        ///< was not contained in this ResMgr
      84             :     ResMgr*         pOriginalResMgr;   ///< the res mgr that fell back to this
      85             :                                        ///< stack level
      86             : 
      87             :     TOOLS_DLLPRIVATE void incStack();
      88             :     TOOLS_DLLPRIVATE void decStack();
      89             : 
      90        1515 :     TOOLS_DLLPRIVATE const ImpRCStack * StackTop( sal_uInt32 nOff = 0 ) const
      91             :     {
      92        1515 :         return (((int)nOff >= nCurStack) ? NULL : &aStack[nCurStack-nOff]);
      93             :     }
      94             :     TOOLS_DLLPRIVATE void  Init( const OUString& rFileName );
      95             : 
      96             :     TOOLS_DLLPRIVATE ResMgr( InternalResMgr * pImp );
      97             : 
      98             :     #ifdef DBG_UTIL
      99             :     TOOLS_DLLPRIVATE static void RscError_Impl( const sal_Char* pMessage,
     100             :                                                 ResMgr* pResMgr,
     101             :                                                 RESOURCE_TYPE nRT,
     102             :                                                 sal_uInt32 nId,
     103             :                                                 std::vector< ImpRCStack >& rResStack,
     104             :                                                 int nDepth );
     105             :     #endif
     106             : 
     107             :     // called from within GetResource() if a resource could not be found
     108             :     TOOLS_DLLPRIVATE ResMgr* CreateFallbackResMgr( const ResId& rId,
     109             :                                                    const Resource* pResource );
     110             :     // creates a 1k sized buffer set to zero for unfound resources
     111             :     // used in case RC_NOTFOUND
     112             :     static void* pEmptyBuffer;
     113             :     TOOLS_DLLPRIVATE static void* getEmptyBuffer();
     114             : 
     115             :     // the next two methods are needed to prevent the string hook called
     116             :     // with the res mgr mutex locked
     117             :     // like GetString, but doesn't call the string hook
     118             :     TOOLS_DLLPRIVATE static sal_uInt32 GetStringWithoutHook( OUString& rStr,
     119             :                                                              const sal_uInt8* pStr );
     120             :     // like ReadString but doesn't call the string hook
     121             :     TOOLS_DLLPRIVATE OUString ReadStringWithoutHook();
     122             : 
     123             :     static ResMgr* ImplCreateResMgr( InternalResMgr* pImpl ) { return new ResMgr( pImpl ); }
     124             : 
     125             :     // no copying
     126             :     ResMgr(const ResMgr&);
     127             :     ResMgr& operator=(const ResMgr&);
     128             : 
     129             : public:
     130             :     static void         DestroyAllResMgr();  ///< Called upon app shutdown
     131             : 
     132             :     ~ResMgr();
     133             : 
     134             :     /// Language-dependent resource library
     135             :     static ResMgr*      SearchCreateResMgr( const sal_Char* pPrefixName,
     136             :                                             LanguageTag& rLocale );
     137             :      static ResMgr*     CreateResMgr( const sal_Char* pPrefixName,
     138             :                                       LanguageTag aLocale = LanguageTag( LANGUAGE_SYSTEM) );
     139             : 
     140             :     #ifdef DBG_UTIL
     141             :     /// Test whether resource still exists
     142             :     void                TestStack( const Resource * );
     143             :     #endif
     144             : 
     145             :     /// Check whether resource is available
     146             :     bool                IsAvailable( const ResId& rId,
     147             :                                      const Resource* = NULL) const;
     148             : 
     149             :     /// Search and load resource, given its ID
     150             :     bool                GetResource( const ResId& rId, const Resource * = NULL );
     151             :     static void *       GetResourceSkipHeader( const ResId& rResId, ResMgr ** ppResMgr );
     152             :     /// Free resource context
     153             :     void                PopContext( const Resource* = NULL );
     154             : 
     155             :     /// Increment resource pointer
     156             :     void*               Increment( sal_uInt32 nSize );
     157             : 
     158             :     /// Size of an object within the resource
     159       29789 :     static sal_uInt32   GetObjSize( RSHEADER_TYPE* pHT )
     160       29789 :                             { return( pHT->GetGlobOff() ); }
     161             : 
     162             :     /// Return a string and its length out of the resource
     163             :     static sal_uInt32   GetString( OUString& rStr, const sal_uInt8* pStr );
     164             :     /// Return a byte string and its length out of the resource
     165             :     static sal_uInt32   GetByteString( OString& rStr, const sal_uInt8* pStr );
     166             : 
     167             :     /// Return the size of a string in the resource
     168      152344 :     static sal_uInt32   GetStringSize( sal_uInt32 nLen )
     169      152344 :                             { nLen++; return (nLen + nLen%2); }
     170             :     static sal_uInt32   GetStringSize( const sal_uInt8* pStr, sal_uInt32& nLen );
     171             : 
     172             :     /// Return a int64
     173             :     static sal_uInt64   GetUInt64( void* pDatum );
     174             :     /// Return a long
     175             :     static sal_Int32    GetLong( void * pLong );
     176             :     /// Return a short
     177             :     static sal_Int16    GetShort( void * pShort );
     178             : 
     179             :     /// Return a pointer to the resource
     180             :     void *              GetClass();
     181             : 
     182             :     RSHEADER_TYPE *     CreateBlock( const ResId & rId );
     183             : 
     184             :     sal_uInt32          GetRemainSize();
     185             : 
     186             :     const OUString& GetFileName() const;
     187             : 
     188             :     sal_Int16           ReadShort();
     189             :     sal_Int32           ReadLong();
     190             :     OUString            ReadString();
     191             :     OString        ReadByteString();
     192             : 
     193             :     /// Generate auto help ID for current resource stack
     194             :     OString        GetAutoHelpId();
     195             : 
     196             :     static void         SetReadStringHook( ResHookProc pProc );
     197             :     static ResHookProc  GetReadStringHook();
     198             :     static void         SetDefaultLocale( const LanguageTag& rLocale );
     199             : };
     200             : 
     201    81466576 : inline sal_uInt32 RSHEADER_TYPE::GetId()
     202             : {
     203    81466576 :     return (sal_uInt32)ResMgr::GetLong( &nId );
     204             : }
     205             : 
     206    81668857 : inline RESOURCE_TYPE RSHEADER_TYPE::GetRT()
     207             : {
     208    81668857 :     return (RESOURCE_TYPE)ResMgr::GetLong( &nRT );
     209             : }
     210             : 
     211    83230389 : inline sal_uInt32 RSHEADER_TYPE::GetGlobOff()
     212             : {
     213    83230389 :     return (sal_uInt32)ResMgr::GetLong( &nGlobOff );
     214             : }
     215             : 
     216     2049791 : inline sal_uInt32 RSHEADER_TYPE::GetLocalOff()
     217             : {
     218     2049791 :     return (sal_uInt32)ResMgr::GetLong( &nLocalOff );
     219             : }
     220             : 
     221             : #endif
     222             : 
     223             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10