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

Generated by: LCOV version 1.10