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

Generated by: LCOV version 1.10