LCOV - code coverage report
Current view: top level - rsc/source/res - rscconst.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 81 108 75.0 %
Date: 2012-08-25 Functions: 14 21 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 31 50 62.0 %

           Branch data     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                 :            : /****************** I N C L U D E S **************************************/
      21                 :            : 
      22                 :            : // C and C++ Includes.
      23                 :            : #include <cstdlib>
      24                 :            : #include <cstdio>
      25                 :            : #include <cstring>
      26                 :            : 
      27                 :            : // Solar Definitionen
      28                 :            : #include <tools/solar.h>
      29                 :            : 
      30                 :            : // Programmabhaengige Includes.
      31                 :            : #include <rscconst.hxx>
      32                 :            : #include <rscall.h>
      33                 :            : #include <rschash.hxx>
      34                 :            : #include <tools/resid.hxx>
      35                 :            : 
      36                 :            : /****************** C O D E **********************************************/
      37                 :            : /****************** R s c C o n s t **************************************/
      38                 :            : /*************************************************************************
      39                 :            : |*
      40                 :            : |*    RscConst::RscConst()
      41                 :            : |*
      42                 :            : *************************************************************************/
      43                 :      31680 : RscConst::RscConst( Atom nId, sal_uInt32 nTypeId )
      44                 :      31680 :     : RscTop( nId, nTypeId )
      45                 :            : {
      46                 :      31680 :     pVarArray = NULL;
      47                 :      31680 :     nEntries = 0;
      48                 :      31680 : }
      49                 :            : 
      50                 :            : /*************************************************************************
      51                 :            : |*
      52                 :            : |*    RscConst::~RscConst()
      53                 :            : |*
      54                 :            : *************************************************************************/
      55                 :      31680 : RscConst::~RscConst()
      56                 :            : {
      57         [ +  - ]:      31680 :     if( pVarArray )
      58                 :      31680 :         rtl_freeMemory( (void *)pVarArray );
      59         [ -  + ]:      31680 : }
      60                 :            : 
      61                 :            : /*************************************************************************
      62                 :            : |*
      63                 :            : |*    RscConst::GetClassType()
      64                 :            : |*
      65                 :            : *************************************************************************/
      66                 :          0 : RSCCLASS_TYPE RscConst::GetClassType() const
      67                 :            : {
      68                 :          0 :     return RSCCLASS_CONST;
      69                 :            : }
      70                 :            : 
      71                 :            : /*************************************************************************
      72                 :            : |*
      73                 :            : |*    RscConst::SetConstance()
      74                 :            : |*
      75                 :            : *************************************************************************/
      76                 :    1476000 : ERRTYPE RscConst::SetConstant( Atom nVarName, sal_Int32 lValue ){
      77         [ +  + ]:    1476000 :     if( pVarArray )
      78                 :            :         pVarArray = (VarEle *)
      79                 :            :             rtl_reallocateMemory( (void *)pVarArray,
      80                 :    1444320 :                 ((nEntries +1) * sizeof( VarEle )) );
      81                 :            :     else
      82                 :            :         pVarArray = (VarEle *)
      83                 :      31680 :             rtl_allocateMemory( ((nEntries +1) * sizeof( VarEle )) );
      84                 :    1476000 :     pVarArray[ nEntries ].nId     = nVarName;
      85                 :    1476000 :     pVarArray[ nEntries ].lValue  = lValue;
      86                 :    1476000 :     nEntries++;
      87                 :            : 
      88                 :    1476000 :     return( ERR_OK );
      89                 :            : }
      90                 :            : 
      91                 :            : /*************************************************************************
      92                 :            : |*
      93                 :            : |*    RscConst::GetConstance()
      94                 :            : |*
      95                 :            : *************************************************************************/
      96                 :          0 : Atom RscConst::GetConstant( sal_uInt32 nPos ){
      97         [ #  # ]:          0 :      if( nPos < nEntries )
      98                 :          0 :         return pVarArray[ nPos ].nId;
      99                 :          0 :     return( InvalidAtom );
     100                 :            : }
     101                 :            : 
     102                 :            : /*************************************************************************
     103                 :            : |*
     104                 :            : |*    RscConst::GetConstValue()
     105                 :            : |*
     106                 :            : *************************************************************************/
     107                 :      86124 : sal_Bool RscConst::GetConstValue( Atom nConst, sal_Int32 * pValue ) const
     108                 :            : {
     109                 :      86124 :     sal_uInt32 i = 0;
     110                 :            : 
     111         [ +  - ]:     430924 :     for( i = 0; i < nEntries; i++ )
     112         [ +  + ]:     430924 :         if( pVarArray[ i ].nId == nConst )
     113                 :            :         {
     114                 :      86124 :             *pValue = pVarArray[ i ].lValue;
     115                 :      86124 :             return sal_True;
     116                 :            :         }
     117                 :      86124 :     return sal_False;
     118                 :            : }
     119                 :            : 
     120                 :            : /*************************************************************************
     121                 :            : |*
     122                 :            : |*    RscConst::GetValueConst()
     123                 :            : |*
     124                 :            : *************************************************************************/
     125                 :     129236 : sal_Bool RscConst::GetValueConst( sal_Int32 lValue, Atom * pConst ) const
     126                 :            : {
     127                 :     129236 :     sal_uInt32 i = 0;
     128                 :            : 
     129         [ +  - ]:     646606 :     for( i = 0; i < nEntries; i++ )
     130         [ +  + ]:     646606 :         if( pVarArray[ i ].lValue == lValue )
     131                 :            :         {
     132                 :     129236 :             *pConst = pVarArray[ i ].nId;
     133                 :     129236 :             return sal_True;
     134                 :            :         }
     135                 :     129236 :     return sal_False;
     136                 :            : }
     137                 :            : 
     138                 :            : /*************************************************************************
     139                 :            : |*
     140                 :            : |*    RscConst::GetConstPos()
     141                 :            : |*
     142                 :            : |*    Beschreibung      Sucht die Position der Konstanten
     143                 :            : |*                      Return = nEntries, nicht gefunden
     144                 :            : |*                      Return = Position im Feld
     145                 :            : |*
     146                 :            : *************************************************************************/
     147                 :     865576 : sal_uInt32 RscConst::GetConstPos( Atom nConst )
     148                 :            : {
     149                 :     865576 :     sal_uInt32 i = 0;
     150                 :            : 
     151         [ +  - ]:   11227990 :     for( i = 0; i < nEntries; i++ )
     152                 :            :     {
     153         [ +  + ]:   11227990 :         if( pVarArray[ i ].nId == nConst )
     154                 :     865576 :             return( i );
     155                 :            :     }
     156                 :            : 
     157                 :     865576 :     return( nEntries );
     158                 :            : }
     159                 :            : 
     160                 :            : /*************************************************************************
     161                 :            : |*
     162                 :            : |*    RscEnum::WriteSyntax()
     163                 :            : |*
     164                 :            : *************************************************************************/
     165                 :          0 : void RscConst::WriteSyntax( FILE * fOutput, RscTypCont * pTC )
     166                 :            : {
     167                 :          0 :     RscTop::WriteSyntax( fOutput, pTC );
     168                 :            : 
     169                 :          0 :     sal_uInt32 i = 0;
     170                 :            :     // Wenn eine Variable Maskierung hat, dann Maskenfeld
     171                 :          0 :     fprintf( fOutput, "\t" );
     172         [ #  # ]:          0 :     for( i = 0; i < nEntries; i++ )
     173                 :            :     {
     174                 :          0 :         fprintf( fOutput, "%s, ", pHS->getString( pVarArray[ i ].nId ).getStr() );
     175 [ #  # ][ #  # ]:          0 :         if( 3 == (i % 4) && i < sal_uInt32(nEntries -1) )
     176                 :          0 :             fprintf( fOutput, "\n\t" );
     177                 :            :     };
     178                 :          0 :     fprintf( fOutput, "\n" );
     179                 :          0 : }
     180                 :            : 
     181                 :            : //==================================================================
     182                 :          0 : void RscConst::WriteRcAccess
     183                 :            : (
     184                 :            :     FILE * fOutput,
     185                 :            :     RscTypCont * /*pTC*/,
     186                 :            :     const char * pName
     187                 :            : )
     188                 :            : {
     189                 :          0 :     fprintf( fOutput, "\t\tSet%s( %s( ", pName, pHS->getString( GetId() ).getStr() );
     190                 :          0 :     fprintf( fOutput, "*(short*)(pResData+nOffset) ) );\n" );
     191                 :          0 :     fprintf( fOutput, "\t\tnOffset += sizeof( short );\n" );
     192                 :          0 : }
     193                 :            : 
     194                 :            : /****************** R s c E n u m ****************************************/
     195                 :            : /*************************************************************************
     196                 :            : |*
     197                 :            : |*    RscEnum::RscEnum()
     198                 :            : |*
     199                 :            : *************************************************************************/
     200                 :      24480 : RscEnum::RscEnum( Atom nId, sal_uInt32 nTypeId )
     201                 :      24480 :             : RscConst( nId, nTypeId )
     202                 :            : {
     203                 :      24480 :     nSize = ALIGNED_SIZE( sizeof( RscEnumInst ) );
     204                 :      24480 : }
     205                 :            : 
     206                 :            : /*************************************************************************
     207                 :            : |*
     208                 :            : |*    RscEnum::SetConst()
     209                 :            : |*
     210                 :            : *************************************************************************/
     211                 :      80808 : ERRTYPE RscEnum::SetConst( const RSCINST & rInst, Atom nConst, sal_Int32 /*nVal*/ )
     212                 :            : {
     213                 :      80808 :     sal_uInt32 i = 0;
     214                 :            : 
     215         [ +  - ]:      80808 :     if( nEntries != (i = GetConstPos( nConst )) )
     216                 :            :     {
     217                 :      80808 :         ((RscEnumInst *)rInst.pData)->nValue = i;
     218                 :      80808 :         ((RscEnumInst *)rInst.pData)->bDflt = sal_False;
     219                 :      80808 :         return( ERR_OK );
     220                 :            :     };
     221                 :            : 
     222                 :      80808 :     return( ERR_RSCENUM );
     223                 :            : }
     224                 :            : 
     225                 :            : /*************************************************************************
     226                 :            : |*
     227                 :            : |*    RscEnum::SetNumber()
     228                 :            : |*
     229                 :            : *************************************************************************/
     230                 :          2 : ERRTYPE RscEnum::SetNumber( const RSCINST & rInst, sal_Int32 lValue )
     231                 :            : {
     232                 :          2 :     sal_uInt32  i = 0;
     233                 :            : 
     234         [ +  - ]:         12 :     for( i = 0; i < nEntries; i++ ){
     235         [ +  + ]:         12 :         if( (sal_Int32)pVarArray[ i ].lValue == lValue )
     236                 :          2 :             return( SetConst( rInst, pVarArray[ i ].nId, lValue ) );
     237                 :            :     };
     238                 :            : 
     239                 :          2 :     return( ERR_RSCENUM );
     240                 :            : }
     241                 :            : 
     242                 :            : /*************************************************************************
     243                 :            : |*
     244                 :            : |*    RscEnum::GetConst()
     245                 :            : |*
     246                 :            : *************************************************************************/
     247                 :          0 : ERRTYPE RscEnum::GetConst( const RSCINST & rInst, Atom * pH ){
     248                 :          0 :     *pH = pVarArray[ ((RscEnumInst *)rInst.pData)->nValue ].nId;
     249                 :          0 :     return( ERR_OK );
     250                 :            : }
     251                 :            : 
     252                 :            : /*************************************************************************
     253                 :            : |*
     254                 :            : |*    RscEnum::GetNumber()
     255                 :            : |*
     256                 :            : *************************************************************************/
     257                 :          0 : ERRTYPE RscEnum::GetNumber( const RSCINST & rInst, sal_Int32 * pNumber ){
     258                 :          0 :     *pNumber = pVarArray[ ((RscEnumInst *)rInst.pData)->nValue ].lValue;
     259                 :          0 :     return( ERR_OK );
     260                 :            : }
     261                 :            : 
     262                 :            : /*************************************************************************
     263                 :            : |*
     264                 :            : |*    RscEnum::Create()
     265                 :            : |*
     266                 :            : *************************************************************************/
     267                 :     136588 : RSCINST RscEnum::Create( RSCINST * pInst, const RSCINST & rDflt, sal_Bool bOwnClass ){
     268                 :     136588 :     RSCINST aInst;
     269                 :            : 
     270         [ +  + ]:     136588 :     if( !pInst ){
     271                 :        604 :         aInst.pClass = this;
     272                 :            :         aInst.pData = (CLASS_DATA)
     273                 :        604 :                       rtl_allocateMemory( sizeof( RscEnumInst ) );
     274                 :            :     }
     275                 :            :     else
     276                 :     135984 :         aInst = *pInst;
     277 [ +  - ][ +  + ]:     136588 :     if( !bOwnClass && rDflt.IsInst() )
                 [ +  + ]
     278                 :        738 :         bOwnClass = rDflt.pClass->InHierarchy( this );
     279                 :            : 
     280         [ +  + ]:     136588 :     if( bOwnClass )
     281                 :        738 :         memmove( aInst.pData, rDflt.pData, Size() );
     282                 :            :     else{
     283                 :     135850 :         ((RscEnumInst *)aInst.pData)->nValue = 0;
     284                 :     135850 :         ((RscEnumInst *)aInst.pData)->bDflt = sal_True;
     285                 :            :     }
     286                 :            : 
     287                 :     136588 :     return( aInst );
     288                 :            : }
     289                 :            : 
     290                 :            : /*************************************************************************
     291                 :            : |*
     292                 :            : |*    RscEnum::IsValueDefault()
     293                 :            : |*
     294                 :            : *************************************************************************/
     295                 :       1482 : sal_Bool RscEnum::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef ){
     296         [ +  - ]:       1482 :     if( pDef ){
     297         [ +  + ]:       1482 :         if( ((RscEnumInst*)rInst.pData)->nValue ==
     298                 :            :           ((RscEnumInst*)pDef)->nValue )
     299                 :            :         {
     300                 :        226 :             return sal_True;
     301                 :            :         }
     302                 :            :     }
     303                 :            : 
     304                 :       1482 :     return sal_False;
     305                 :            : }
     306                 :            : 
     307                 :            : /*************************************************************************
     308                 :            : |*
     309                 :            : |*    RscEnum::WriteSrc()
     310                 :            : |*
     311                 :            : *************************************************************************/
     312                 :      40476 : void RscEnum::WriteSrc( const RSCINST & rInst, FILE * fOutput,
     313                 :            :                          RscTypCont *, sal_uInt32, const char * )
     314                 :            : {
     315                 :            :     fprintf( fOutput, "%s", pHS->getString(
     316                 :      40476 :              pVarArray[ ((RscEnumInst *)rInst.pData)->nValue ].nId ).getStr() );
     317                 :      40476 : }
     318                 :            : 
     319                 :            : /*************************************************************************
     320                 :            : |*
     321                 :            : |*    RscEnum::WriteRc()
     322                 :            : |*
     323                 :            : *************************************************************************/
     324                 :      41968 : ERRTYPE RscEnum::WriteRc( const RSCINST & rInst, RscWriteRc & aMem,
     325                 :            :                           RscTypCont *, sal_uInt32, sal_Bool )
     326                 :            : {
     327                 :      41968 :     aMem.Put( (sal_Int32)pVarArray[ ((RscEnumInst *)rInst.pData)->nValue ].lValue );
     328                 :      41968 :     return( ERR_OK );
     329                 :            : }
     330                 :            : 
     331                 :       1440 : RscLangEnum::RscLangEnum()
     332                 :            :         : RscEnum( pHS->getID( "LangEnum" ), RSC_NOTYPE ),
     333 [ +  - ][ +  - ]:       1440 :           mnLangId( 0x400 )
     334                 :            : {
     335                 :       1440 : }
     336                 :            : 
     337                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10