LCOV - code coverage report
Current view: top level - rsc/source/res - rscconst.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 66 90 73.3 %
Date: 2015-06-13 12:38:46 Functions: 13 19 68.4 %
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        7923 : RscConst::RscConst( Atom nId, sal_uInt32 nTypeId )
      30        7923 :     : RscTop( nId, nTypeId )
      31             : {
      32        7923 :     pVarArray = NULL;
      33        7923 :     nEntries = 0;
      34        7923 : }
      35             : 
      36       15846 : RscConst::~RscConst()
      37             : {
      38        7923 :     if( pVarArray )
      39        7923 :         rtl_freeMemory( static_cast<void *>(pVarArray) );
      40        7923 : }
      41             : 
      42           0 : RSCCLASS_TYPE RscConst::GetClassType() const
      43             : {
      44           0 :     return RSCCLASS_CONST;
      45             : }
      46             : 
      47      645933 : ERRTYPE RscConst::SetConstant( Atom nVarName, sal_Int32 lValue )
      48             : {
      49      645933 :     if( pVarArray )
      50             :         pVarArray = static_cast<VarEle *>(rtl_reallocateMemory( static_cast<void *>(pVarArray),
      51      638010 :                                                      ((nEntries +1) * sizeof( VarEle )) ));
      52             :     else
      53        7923 :         pVarArray = static_cast<VarEle *>(rtl_allocateMemory( ((nEntries +1) * sizeof( VarEle )) ));
      54      645933 :     pVarArray[ nEntries ].nId     = nVarName;
      55      645933 :     pVarArray[ nEntries ].lValue  = lValue;
      56      645933 :     nEntries++;
      57             : 
      58      645933 :     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       31153 : bool RscConst::GetConstValue( Atom nConst, sal_Int32 * pValue ) const
      69             : {
      70       31153 :     sal_uInt32 i = 0;
      71             : 
      72     7768990 :     for( i = 0; i < nEntries; i++ )
      73             :     {
      74     7768990 :         if( pVarArray[ i ].nId == nConst )
      75             :         {
      76       31153 :             *pValue = pVarArray[ i ].lValue;
      77       31153 :             return true;
      78             :         }
      79             :     }
      80           0 :     return false;
      81             : }
      82             : 
      83       46729 : bool RscConst::GetValueConst( sal_Int32 lValue, Atom * pConst ) const
      84             : {
      85       46729 :     sal_uInt32 i = 0;
      86             : 
      87    11653362 :     for( i = 0; i < nEntries; i++ )
      88             :     {
      89    11653362 :         if( pVarArray[ i ].lValue == lValue )
      90             :         {
      91       46729 :             *pConst = pVarArray[ i ].nId;
      92       46729 :             return true;
      93             :         }
      94             :     }
      95           0 :     return false;
      96             : }
      97             : 
      98       43781 : sal_uInt32 RscConst::GetConstPos( Atom nConst )
      99             : {
     100       43781 :     sal_uInt32 i = 0;
     101             : 
     102      214976 :     for( i = 0; i < nEntries; i++ )
     103             :     {
     104      214976 :         if( pVarArray[ i ].nId == nConst )
     105       43781 :             return i;
     106             :     }
     107             : 
     108           0 :     return nEntries;
     109             : }
     110             : 
     111        5838 : RscEnum::RscEnum( Atom nId, sal_uInt32 nTypeId )
     112        5838 :     : RscConst( nId, nTypeId )
     113             : {
     114        5838 :     nSize = ALIGNED_SIZE( sizeof( RscEnumInst ) );
     115        5838 : }
     116             : 
     117         682 : ERRTYPE RscEnum::SetConst( const RSCINST & rInst, Atom nConst, sal_Int32 /*nVal*/ )
     118             : {
     119         682 :     sal_uInt32 i = 0;
     120             : 
     121         682 :     if( nEntries != (i = GetConstPos( nConst )) )
     122             :     {
     123         682 :         reinterpret_cast<RscEnumInst *>(rInst.pData)->nValue = i;
     124         682 :         reinterpret_cast<RscEnumInst *>(rInst.pData)->bDflt = false;
     125         682 :         return ERR_OK;
     126             :     }
     127             : 
     128           0 :     return ERR_RSCENUM;
     129             : }
     130             : 
     131           0 : ERRTYPE RscEnum::SetNumber( const RSCINST & rInst, sal_Int32 lValue )
     132             : {
     133           0 :     sal_uInt32  i = 0;
     134             : 
     135           0 :     for( i = 0; i < nEntries; i++ )
     136             :     {
     137           0 :         if( (sal_Int32)pVarArray[ i ].lValue == lValue )
     138           0 :             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[ reinterpret_cast<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[ reinterpret_cast<RscEnumInst *>(rInst.pData)->nValue ].lValue;
     152           0 :     return ERR_OK;
     153             : }
     154             : 
     155        2932 : RSCINST RscEnum::Create( RSCINST * pInst, const RSCINST & rDflt, bool bOwnClass )
     156             : {
     157        2932 :     RSCINST aInst;
     158             : 
     159        2932 :     if( !pInst )
     160             :     {
     161          40 :         aInst.pClass = this;
     162             :         aInst.pData = static_cast<CLASS_DATA>(
     163          40 :                       rtl_allocateMemory( sizeof( RscEnumInst ) ));
     164             :     }
     165             :     else
     166        2892 :         aInst = *pInst;
     167             : 
     168        2932 :     if( !bOwnClass && rDflt.IsInst() )
     169           0 :         bOwnClass = rDflt.pClass->InHierarchy( this );
     170             : 
     171        2932 :     if( bOwnClass )
     172           0 :         memmove( aInst.pData, rDflt.pData, Size() );
     173             :     else
     174             :     {
     175        2932 :         reinterpret_cast<RscEnumInst *>(aInst.pData)->nValue = 0;
     176        2932 :         reinterpret_cast<RscEnumInst *>(aInst.pData)->bDflt = true;
     177             :     }
     178             : 
     179        2932 :     return aInst;
     180             : }
     181             : 
     182          86 : bool RscEnum::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef )
     183             : {
     184          86 :     return pDef && (reinterpret_cast<RscEnumInst*>(rInst.pData)->nValue == reinterpret_cast<RscEnumInst*>(pDef)->nValue );
     185             : }
     186             : 
     187         337 : void RscEnum::WriteSrc( const RSCINST & rInst, FILE * fOutput,
     188             :                         RscTypCont *, sal_uInt32, const char * )
     189             : {
     190             :     fprintf( fOutput, "%s",
     191         337 :              pHS->getString( pVarArray[ reinterpret_cast<RscEnumInst *>(rInst.pData)->nValue ].nId ).getStr() );
     192         337 : }
     193             : 
     194         600 : ERRTYPE RscEnum::WriteRc( const RSCINST & rInst, RscWriteRc & aMem,
     195             :                           RscTypCont *, sal_uInt32, bool )
     196             : {
     197         600 :     aMem.Put( (sal_Int32)pVarArray[ reinterpret_cast<RscEnumInst *>(rInst.pData)->nValue ].lValue );
     198         600 :     return ERR_OK;
     199             : }
     200             : 
     201         417 : RscLangEnum::RscLangEnum()
     202             :     : RscEnum( pHS->getID( "LangEnum" ), RSC_NOTYPE ),
     203         417 :       mnLangId( 0x400 )
     204             : {
     205         417 : }
     206             : 
     207             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11