LCOV - code coverage report
Current view: top level - rsc/source/res - rscconst.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 71 90 78.9 %
Date: 2014-04-11 Functions: 14 19 73.7 %
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             : #include <cstdlib>
      21             : #include <cstdio>
      22             : #include <cstring>
      23             : 
      24             : #include <rscconst.hxx>
      25             : #include <rscall.h>
      26             : #include <rschash.hxx>
      27             : #include <tools/resid.hxx>
      28             : 
      29        9922 : RscConst::RscConst( Atom nId, sal_uInt32 nTypeId )
      30        9922 :     : RscTop( nId, nTypeId )
      31             : {
      32        9922 :     pVarArray = NULL;
      33        9922 :     nEntries = 0;
      34        9922 : }
      35             : 
      36       19844 : RscConst::~RscConst()
      37             : {
      38        9922 :     if( pVarArray )
      39        9922 :         rtl_freeMemory( (void *)pVarArray );
      40        9922 : }
      41             : 
      42           0 : RSCCLASS_TYPE RscConst::GetClassType() const
      43             : {
      44           0 :     return RSCCLASS_CONST;
      45             : }
      46             : 
      47      699952 : ERRTYPE RscConst::SetConstant( Atom nVarName, sal_Int32 lValue )
      48             : {
      49      699952 :     if( pVarArray )
      50             :         pVarArray = (VarEle *) rtl_reallocateMemory( (void *)pVarArray,
      51      690030 :                                                      ((nEntries +1) * sizeof( VarEle )) );
      52             :     else
      53        9922 :         pVarArray = (VarEle *) rtl_allocateMemory( ((nEntries +1) * sizeof( VarEle )) );
      54      699952 :     pVarArray[ nEntries ].nId     = nVarName;
      55      699952 :     pVarArray[ nEntries ].lValue  = lValue;
      56      699952 :     nEntries++;
      57             : 
      58      699952 :     return ERR_OK;
      59             : }
      60             : 
      61           0 : Atom RscConst::GetConstant( sal_uInt32 nPos )
      62             : {
      63           0 :      if( nPos < nEntries )
      64           0 :         return pVarArray[ nPos ].nId;
      65           0 :     return InvalidAtom;
      66             : }
      67             : 
      68       33677 : bool RscConst::GetConstValue( Atom nConst, sal_Int32 * pValue ) const
      69             : {
      70       33677 :     sal_uInt32 i = 0;
      71             : 
      72     8392683 :     for( i = 0; i < nEntries; i++ )
      73             :     {
      74     8392683 :         if( pVarArray[ i ].nId == nConst )
      75             :         {
      76       33677 :             *pValue = pVarArray[ i ].lValue;
      77       33677 :             return true;
      78             :         }
      79             :     }
      80           0 :     return false;
      81             : }
      82             : 
      83       50497 : bool RscConst::GetValueConst( sal_Int32 lValue, Atom * pConst ) const
      84             : {
      85       50497 :     sal_uInt32 i = 0;
      86             : 
      87    12584457 :     for( i = 0; i < nEntries; i++ )
      88             :     {
      89    12584457 :         if( pVarArray[ i ].lValue == lValue )
      90             :         {
      91       50497 :             *pConst = pVarArray[ i ].nId;
      92       50497 :             return true;
      93             :         }
      94             :     }
      95           0 :     return false;
      96             : }
      97             : 
      98      116691 : sal_uInt32 RscConst::GetConstPos( Atom nConst )
      99             : {
     100      116691 :     sal_uInt32 i = 0;
     101             : 
     102     1219670 :     for( i = 0; i < nEntries; i++ )
     103             :     {
     104     1219670 :         if( pVarArray[ i ].nId == nConst )
     105      116691 :             return i;
     106             :     }
     107             : 
     108           0 :     return nEntries;
     109             : }
     110             : 
     111        7667 : RscEnum::RscEnum( Atom nId, sal_uInt32 nTypeId )
     112        7667 :     : RscConst( nId, nTypeId )
     113             : {
     114        7667 :     nSize = ALIGNED_SIZE( sizeof( RscEnumInst ) );
     115        7667 : }
     116             : 
     117        7803 : ERRTYPE RscEnum::SetConst( const RSCINST & rInst, Atom nConst, sal_Int32 /*nVal*/ )
     118             : {
     119        7803 :     sal_uInt32 i = 0;
     120             : 
     121        7803 :     if( nEntries != (i = GetConstPos( nConst )) )
     122             :     {
     123        7803 :         ((RscEnumInst *)rInst.pData)->nValue = i;
     124        7803 :         ((RscEnumInst *)rInst.pData)->bDflt = false;
     125        7803 :         return ERR_OK;
     126             :     };
     127             : 
     128           0 :     return ERR_RSCENUM;
     129             : }
     130             : 
     131           1 : ERRTYPE RscEnum::SetNumber( const RSCINST & rInst, sal_Int32 lValue )
     132             : {
     133           1 :     sal_uInt32  i = 0;
     134             : 
     135           6 :     for( i = 0; i < nEntries; i++ )
     136             :     {
     137           6 :         if( (sal_Int32)pVarArray[ i ].lValue == lValue )
     138           1 :             return SetConst( rInst, pVarArray[ i ].nId, lValue );
     139             :     };
     140             : 
     141           0 :     return ERR_RSCENUM;
     142             : }
     143             : 
     144           0 : ERRTYPE RscEnum::GetConst( const RSCINST & rInst, Atom * pH )
     145             : {
     146           0 :     *pH = pVarArray[ ((RscEnumInst *)rInst.pData)->nValue ].nId;
     147           0 :     return ERR_OK;
     148             : }
     149             : 
     150           0 : ERRTYPE RscEnum::GetNumber( const RSCINST & rInst, sal_Int32 * pNumber ){
     151           0 :     *pNumber = pVarArray[ ((RscEnumInst *)rInst.pData)->nValue ].lValue;
     152           0 :     return ERR_OK;
     153             : }
     154             : 
     155       15586 : RSCINST RscEnum::Create( RSCINST * pInst, const RSCINST & rDflt, bool bOwnClass )
     156             : {
     157       15586 :     RSCINST aInst;
     158             : 
     159       15586 :     if( !pInst )
     160             :     {
     161         180 :         aInst.pClass = this;
     162             :         aInst.pData = (CLASS_DATA)
     163         180 :                       rtl_allocateMemory( sizeof( RscEnumInst ) );
     164             :     }
     165             :     else
     166       15406 :         aInst = *pInst;
     167             : 
     168       15586 :     if( !bOwnClass && rDflt.IsInst() )
     169           0 :         bOwnClass = rDflt.pClass->InHierarchy( this );
     170             : 
     171       15586 :     if( bOwnClass )
     172           0 :         memmove( aInst.pData, rDflt.pData, Size() );
     173             :     else
     174             :     {
     175       15586 :         ((RscEnumInst *)aInst.pData)->nValue = 0;
     176       15586 :         ((RscEnumInst *)aInst.pData)->bDflt = true;
     177             :     }
     178             : 
     179       15586 :     return aInst;
     180             : }
     181             : 
     182         353 : bool RscEnum::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef )
     183             : {
     184         353 :     return pDef && (((RscEnumInst*)rInst.pData)->nValue == ((RscEnumInst*)pDef)->nValue );
     185             : }
     186             : 
     187        3857 : void RscEnum::WriteSrc( const RSCINST & rInst, FILE * fOutput,
     188             :                         RscTypCont *, sal_uInt32, const char * )
     189             : {
     190             :     fprintf( fOutput, "%s",
     191        3857 :              pHS->getString( pVarArray[ ((RscEnumInst *)rInst.pData)->nValue ].nId ).getStr() );
     192        3857 : }
     193             : 
     194        4360 : ERRTYPE RscEnum::WriteRc( const RSCINST & rInst, RscWriteRc & aMem,
     195             :                           RscTypCont *, sal_uInt32, bool )
     196             : {
     197        4360 :     aMem.Put( (sal_Int32)pVarArray[ ((RscEnumInst *)rInst.pData)->nValue ].lValue );
     198        4360 :     return ERR_OK;
     199             : }
     200             : 
     201         451 : RscLangEnum::RscLangEnum()
     202             :     : RscEnum( pHS->getID( "LangEnum" ), RSC_NOTYPE ),
     203         451 :       mnLangId( 0x400 )
     204             : {
     205         451 : }
     206             : 
     207             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10