LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/rsc/source/res - rscconst.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 73 90 81.1 %
Date: 2013-07-09 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       13772 : RscConst::RscConst( Atom nId, sal_uInt32 nTypeId )
      30       13772 :     : RscTop( nId, nTypeId )
      31             : {
      32       13772 :     pVarArray = NULL;
      33       13772 :     nEntries = 0;
      34       13772 : }
      35             : 
      36       27544 : RscConst::~RscConst()
      37             : {
      38       13772 :     if( pVarArray )
      39       13772 :         rtl_freeMemory( (void *)pVarArray );
      40       13772 : }
      41             : 
      42           0 : RSCCLASS_TYPE RscConst::GetClassType() const
      43             : {
      44           0 :     return RSCCLASS_CONST;
      45             : }
      46             : 
      47      704250 : ERRTYPE RscConst::SetConstant( Atom nVarName, sal_Int32 lValue )
      48             : {
      49      704250 :     if( pVarArray )
      50             :         pVarArray = (VarEle *) rtl_reallocateMemory( (void *)pVarArray,
      51      690478 :                                                      ((nEntries +1) * sizeof( VarEle )) );
      52             :     else
      53       13772 :         pVarArray = (VarEle *) rtl_allocateMemory( ((nEntries +1) * sizeof( VarEle )) );
      54      704250 :     pVarArray[ nEntries ].nId     = nVarName;
      55      704250 :     pVarArray[ nEntries ].lValue  = lValue;
      56      704250 :     nEntries++;
      57             : 
      58      704250 :     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       38731 : bool RscConst::GetConstValue( Atom nConst, sal_Int32 * pValue ) const
      69             : {
      70       38731 :     sal_uInt32 i = 0;
      71             : 
      72      241880 :     for( i = 0; i < nEntries; i++ )
      73             :     {
      74      241880 :         if( pVarArray[ i ].nId == nConst )
      75             :         {
      76       38731 :             *pValue = pVarArray[ i ].lValue;
      77       38731 :             return true;
      78             :         }
      79             :     }
      80           0 :     return false;
      81             : }
      82             : 
      83       58083 : bool RscConst::GetValueConst( sal_Int32 lValue, Atom * pConst ) const
      84             : {
      85       58083 :     sal_uInt32 i = 0;
      86             : 
      87      362748 :     for( i = 0; i < nEntries; i++ )
      88             :     {
      89      362748 :         if( pVarArray[ i ].lValue == lValue )
      90             :         {
      91       58083 :             *pConst = pVarArray[ i ].nId;
      92       58083 :             return true;
      93             :         }
      94             :     }
      95           0 :     return false;
      96             : }
      97             : 
      98      289058 : sal_uInt32 RscConst::GetConstPos( Atom nConst )
      99             : {
     100      289058 :     sal_uInt32 i = 0;
     101             : 
     102     3610968 :     for( i = 0; i < nEntries; i++ )
     103             :     {
     104     3610968 :         if( pVarArray[ i ].nId == nConst )
     105      289058 :             return i;
     106             :     }
     107             : 
     108           0 :     return nEntries;
     109             : }
     110             : 
     111       10642 : RscEnum::RscEnum( Atom nId, sal_uInt32 nTypeId )
     112       10642 :     : RscConst( nId, nTypeId )
     113             : {
     114       10642 :     nSize = ALIGNED_SIZE( sizeof( RscEnumInst ) );
     115       10642 : }
     116             : 
     117       25439 : ERRTYPE RscEnum::SetConst( const RSCINST & rInst, Atom nConst, sal_Int32 /*nVal*/ )
     118             : {
     119       25439 :     sal_uInt32 i = 0;
     120             : 
     121       25439 :     if( nEntries != (i = GetConstPos( nConst )) )
     122             :     {
     123       25439 :         ((RscEnumInst *)rInst.pData)->nValue = i;
     124       25439 :         ((RscEnumInst *)rInst.pData)->bDflt = false;
     125       25439 :         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       44371 : RSCINST RscEnum::Create( RSCINST * pInst, const RSCINST & rDflt, bool bOwnClass )
     156             : {
     157       44371 :     RSCINST aInst;
     158             : 
     159       44371 :     if( !pInst )
     160             :     {
     161         255 :         aInst.pClass = this;
     162             :         aInst.pData = (CLASS_DATA)
     163         255 :                       rtl_allocateMemory( sizeof( RscEnumInst ) );
     164             :     }
     165             :     else
     166       44116 :         aInst = *pInst;
     167             : 
     168       44371 :     if( !bOwnClass && rDflt.IsInst() )
     169          63 :         bOwnClass = rDflt.pClass->InHierarchy( this );
     170             : 
     171       44371 :     if( bOwnClass )
     172          63 :         memmove( aInst.pData, rDflt.pData, Size() );
     173             :     else
     174             :     {
     175       44308 :         ((RscEnumInst *)aInst.pData)->nValue = 0;
     176       44308 :         ((RscEnumInst *)aInst.pData)->bDflt = true;
     177             :     }
     178             : 
     179       44371 :     return aInst;
     180             : }
     181             : 
     182         577 : bool RscEnum::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef )
     183             : {
     184         577 :     return pDef && (((RscEnumInst*)rInst.pData)->nValue == ((RscEnumInst*)pDef)->nValue );
     185             : }
     186             : 
     187       12691 : void RscEnum::WriteSrc( const RSCINST & rInst, FILE * fOutput,
     188             :                         RscTypCont *, sal_uInt32, const char * )
     189             : {
     190             :     fprintf( fOutput, "%s",
     191       12691 :              pHS->getString( pVarArray[ ((RscEnumInst *)rInst.pData)->nValue ].nId ).getStr() );
     192       12691 : }
     193             : 
     194       13305 : ERRTYPE RscEnum::WriteRc( const RSCINST & rInst, RscWriteRc & aMem,
     195             :                           RscTypCont *, sal_uInt32, bool )
     196             : {
     197       13305 :     aMem.Put( (sal_Int32)pVarArray[ ((RscEnumInst *)rInst.pData)->nValue ].lValue );
     198       13305 :     return ERR_OK;
     199             : }
     200             : 
     201         626 : RscLangEnum::RscLangEnum()
     202             :     : RscEnum( pHS->getID( "LangEnum" ), RSC_NOTYPE ),
     203         626 :       mnLangId( 0x400 )
     204             : {
     205         626 : }
     206             : 
     207             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10