LCOV - code coverage report
Current view: top level - rsc/source/res - rscflag.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 108 165 65.5 %
Date: 2012-08-25 Functions: 13 19 68.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 46 90 51.1 %

           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 <stdlib.h>
      24                 :            : #include <stdio.h>
      25                 :            : #include <string.h>
      26                 :            : 
      27                 :            : #include <rscflag.hxx>
      28                 :            : 
      29                 :            : /****************** C O D E **********************************************/
      30                 :            : /****************** R s c F l a g ****************************************/
      31                 :            : /*************************************************************************
      32                 :            : |*
      33                 :            : |*    RscFlag::RscFlag()
      34                 :            : |*
      35                 :            : *************************************************************************/
      36                 :       7200 : RscFlag::RscFlag( Atom nId, sal_uInt32 nTypeId )
      37                 :       7200 :             : RscConst( nId, nTypeId )
      38                 :       7200 : {}
      39                 :            : 
      40                 :            : /*************************************************************************
      41                 :            : |*
      42                 :            : |*    RscFlag::Size()
      43                 :            : |*
      44                 :            : |*    Beschreibung      Die Groe�e der Instanzdaten richtet sich nach
      45                 :            : |*                      der Anzahl der Flags
      46                 :            : |*
      47                 :            : *************************************************************************/
      48                 :     461914 : sal_uInt32 RscFlag::Size()
      49                 :            : {
      50                 :            :     return( ALIGNED_SIZE( sizeof( RscFlagInst ) *
      51                 :     461914 :             ( 1 + (nEntries -1) / (sizeof( sal_uInt32 ) * 8) ) ) );
      52                 :            : }
      53                 :            : 
      54                 :            : /*************************************************************************
      55                 :            : |*
      56                 :            : |*    RscFlag::SetNotConst()
      57                 :            : |*
      58                 :            : *************************************************************************/
      59                 :        616 : ERRTYPE RscFlag::SetNotConst( const RSCINST & rInst, Atom nConst )
      60                 :            : {
      61                 :        616 :     sal_uInt32 i = 0;
      62                 :            : 
      63         [ +  - ]:        616 :     if( nEntries != (i = GetConstPos( nConst )) ){
      64                 :        616 :         sal_uInt32 nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
      65                 :        616 :         i = i / (sizeof( sal_uInt32 ) * 8);
      66                 :        616 :         ((RscFlagInst *)rInst.pData)[ i ].nFlags     &= ~nFlag;
      67                 :        616 :         ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags &= ~nFlag;
      68                 :        616 :         return( ERR_OK );
      69                 :            :     };
      70                 :            : 
      71                 :        616 :     return( ERR_RSCFLAG );
      72                 :            : }
      73                 :            : 
      74                 :            : /*************************************************************************
      75                 :            : |*
      76                 :            : |*    RscFlag::SetConst()
      77                 :            : |*
      78                 :            : *************************************************************************/
      79                 :      53072 : ERRTYPE RscFlag::SetConst( const RSCINST & rInst, Atom nConst, sal_Int32 /*nVal*/ )
      80                 :            : {
      81                 :      53072 :     sal_uInt32 i = 0;
      82                 :            : 
      83         [ +  - ]:      53072 :     if( nEntries != (i = GetConstPos( nConst )) ){
      84                 :      53072 :         sal_uInt32 nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
      85                 :      53072 :         i = i / (sizeof( sal_uInt32 ) * 8);
      86                 :      53072 :         ((RscFlagInst *)rInst.pData)[ i ].nFlags     |= nFlag;
      87                 :      53072 :         ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags &= ~nFlag;
      88                 :      53072 :         return( ERR_OK );
      89                 :            :     };
      90                 :            : 
      91                 :      53072 :     return( ERR_RSCFLAG );
      92                 :            : }
      93                 :            : 
      94                 :            : /*************************************************************************
      95                 :            : |*
      96                 :            : |*    RscFlag::CreateBasic()
      97                 :            : |*
      98                 :            : *************************************************************************/
      99                 :     776716 : RSCINST RscFlag::CreateBasic( RSCINST * pInst )
     100                 :            : {
     101                 :     776716 :     RSCINST aInst;
     102                 :            : 
     103         [ +  + ]:     776716 :     if( !pInst ){
     104                 :      49276 :         aInst.pClass = this;
     105                 :      49276 :         aInst.pData = (CLASS_DATA) rtl_allocateMemory( Size() );
     106                 :            :     }
     107                 :            :     else
     108                 :     727440 :         aInst = *pInst;
     109                 :            : 
     110                 :     776716 :     return( aInst );
     111                 :            : }
     112                 :            : 
     113                 :            : /*************************************************************************
     114                 :            : |*
     115                 :            : |*    RscFlag::Create()
     116                 :            : |*
     117                 :            : *************************************************************************/
     118                 :      99444 : RSCINST RscFlag::Create( RSCINST * pInst, const RSCINST & rDflt, sal_Bool bOwnClass )
     119                 :            : {
     120                 :      99444 :     RSCINST aInst = CreateBasic( pInst );
     121                 :            : 
     122 [ +  + ][ +  + ]:      99444 :     if( !bOwnClass && rDflt.IsInst() )
                 [ +  - ]
     123                 :        404 :         bOwnClass = rDflt.pClass->InHierarchy( this );
     124                 :            : 
     125         [ +  + ]:      99444 :     if( bOwnClass )
     126                 :        404 :         memmove( aInst.pData, rDflt.pData, Size() );
     127                 :            :     else
     128                 :            :     {
     129         [ +  + ]:     239434 :         for( sal_uInt32 i = 0; i < Size() / sizeof( RscFlagInst ); i++ )
     130                 :            :         {
     131                 :     140394 :             ((RscFlagInst *)aInst.pData)[ i ].nFlags = 0;
     132                 :     140394 :             ((RscFlagInst *)aInst.pData)[ i ].nDfltFlags = 0xFFFFFFFF;
     133                 :            :         }
     134                 :            :     };
     135                 :            : 
     136                 :      99444 :     return( aInst );
     137                 :            : }
     138                 :            : 
     139                 :            : /*************************************************************************
     140                 :            : |*
     141                 :            : |*    RscFlag::CreateClient()
     142                 :            : |*
     143                 :            : *************************************************************************/
     144                 :     677272 : RSCINST RscFlag::CreateClient( RSCINST * pInst, const RSCINST & rDfltI,
     145                 :            :                                sal_Bool bOwnClass, Atom nConstId )
     146                 :            : {
     147                 :     677272 :     RSCINST aInst = CreateBasic( pInst );
     148                 :     677272 :     sal_uInt32 i = 0;
     149                 :            : 
     150 [ -  + ][ -  + ]:     677272 :     if( !bOwnClass && rDfltI.IsInst() )
                 [ +  + ]
     151                 :          0 :         bOwnClass = rDfltI.pClass->InHierarchy( this );
     152                 :            : 
     153         [ +  - ]:     677272 :     if( nEntries != (i = GetConstPos( nConstId )) )
     154                 :            :     {
     155                 :     677272 :         sal_uInt32 nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
     156                 :     677272 :         i = i / (sizeof( sal_uInt32 ) * 8);
     157         [ +  + ]:     677272 :         if( bOwnClass ){
     158                 :            :             ((RscFlagInst *)aInst.pData)[ i ].nFlags &=
     159                 :       2988 :             ~nFlag | ((RscFlagInst *)rDfltI.pData)[ i ].nFlags;
     160                 :            :             ((RscFlagInst *)aInst.pData)[ i ].nDfltFlags &=
     161                 :       2988 :             ~nFlag | ((RscFlagInst *)rDfltI.pData)[ i ].nDfltFlags;
     162                 :            :         }
     163                 :            :         else{
     164                 :     674284 :             ((RscFlagInst *)aInst.pData)[ i ].nFlags &= ~nFlag;
     165                 :     674284 :             ((RscFlagInst *)aInst.pData)[ i ].nDfltFlags |= nFlag;
     166                 :            :         }
     167                 :            :     }
     168                 :            : 
     169                 :     677272 :     return( aInst );
     170                 :            : }
     171                 :            : 
     172                 :            : /*************************************************************************
     173                 :            : |*
     174                 :            : |*    RscFlag::SetToDefault()
     175                 :            : |*
     176                 :            : *************************************************************************/
     177                 :          0 : void RscFlag::SetToDefault( const RSCINST & rInst )
     178                 :            : {
     179                 :          0 :     sal_uInt32 i = 0;
     180                 :            : 
     181         [ #  # ]:          0 :     for( i = 0; i < Size() / sizeof( RscFlagInst ); i++ )
     182                 :          0 :         ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags = 0xFFFFFFFF;
     183                 :          0 : }
     184                 :            : 
     185                 :            : /*************************************************************************
     186                 :            : |*
     187                 :            : |*    RscFlag::IsDlft()
     188                 :            : |*
     189                 :            : *************************************************************************/
     190                 :          0 : sal_Bool RscFlag::IsDefault( const RSCINST & rInst )
     191                 :            : {
     192                 :          0 :     sal_uInt32 i = 0;
     193                 :            : 
     194         [ #  # ]:          0 :     for( i = 0; i < Size() / sizeof( RscFlagInst ); i++ )
     195         [ #  # ]:          0 :         if( ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags != 0xFFFFFFFF )
     196                 :          0 :             return( sal_False );
     197                 :          0 :     return( sal_True );
     198                 :            : }
     199                 :            : 
     200                 :          0 : sal_Bool RscFlag::IsDefault( const RSCINST & rInst, Atom nConstId )
     201                 :            : {
     202                 :          0 :     sal_uInt32 i = 0, nFlag = 0;
     203                 :            : 
     204         [ #  # ]:          0 :     if( nEntries != (i = GetConstPos( nConstId )) ){
     205                 :          0 :         nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
     206                 :          0 :         i = i / (sizeof( sal_uInt32 ) * 8);
     207         [ #  # ]:          0 :         if( ((RscFlagInst *)rInst.pData)[ i ].nDfltFlags & nFlag )
     208                 :          0 :             return( sal_True );
     209                 :            :         else
     210                 :          0 :             return( sal_False );
     211                 :            :     };
     212                 :          0 :     return( sal_True );
     213                 :            : }
     214                 :            : 
     215                 :            : /*************************************************************************
     216                 :            : |*
     217                 :            : |*    RscFlag::IsValueDefault()
     218                 :            : |*
     219                 :            : *************************************************************************/
     220                 :      27214 : sal_Bool RscFlag::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef,
     221                 :            :                               Atom nConstId )
     222                 :            : {
     223                 :      27214 :     sal_uInt32 i = 0, nFlag = 0;
     224                 :            : 
     225         [ +  - ]:      27214 :     if( nEntries != (i = GetConstPos( nConstId )) ){
     226                 :      27214 :         nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
     227                 :      27214 :         i = i / (sizeof( sal_uInt32 ) * 8);
     228                 :            : 
     229         [ +  - ]:      27214 :         if( pDef ){
     230         [ +  + ]:      27214 :             if( (((RscFlagInst *)rInst.pData)[ i ].nFlags & nFlag)
     231                 :      27214 :               == (((RscFlagInst *)pDef)[ i ].nFlags & nFlag) )
     232                 :            :             {
     233                 :        620 :                 return sal_True;
     234                 :            :             }
     235                 :            :         }
     236                 :            :     };
     237                 :            : 
     238                 :      27214 :     return sal_False;
     239                 :            : }
     240                 :            : 
     241                 :          0 : sal_Bool RscFlag::IsValueDefault( const RSCINST & rInst, CLASS_DATA pDef )
     242                 :            : {
     243         [ #  # ]:          0 :     if( pDef ){
     244                 :          0 :         sal_uInt32  Flag = 0, nIndex = 0;
     245                 :            : 
     246                 :          0 :         Flag = 1;
     247         [ #  # ]:          0 :         for( sal_uInt32 i = 0; i < nEntries; i++ ){
     248                 :          0 :             nIndex = i / (sizeof( sal_uInt32 ) * 8);
     249         [ #  # ]:          0 :             if( (((RscFlagInst *)rInst.pData)[ nIndex ].nFlags & Flag)
     250                 :          0 :               != (((RscFlagInst *)pDef)[ nIndex ].nFlags & Flag)  )
     251                 :            :             {
     252                 :          0 :                 return sal_False;
     253                 :            :             }
     254                 :          0 :             Flag <<= 1;
     255         [ #  # ]:          0 :             if( !Flag )
     256                 :          0 :                 Flag = 1;
     257                 :            :         };
     258                 :            :     }
     259                 :            :     else
     260                 :          0 :         return sal_False;
     261                 :            : 
     262                 :          0 :     return sal_True;
     263                 :            : }
     264                 :            : 
     265                 :            : /*************************************************************************
     266                 :            : |*
     267                 :            : |*    RscFlag::IsSet()
     268                 :            : |*
     269                 :            : *************************************************************************/
     270                 :      26594 : sal_Bool RscFlag::IsSet( const RSCINST & rInst, Atom nConstId )
     271                 :            : {
     272                 :      26594 :     sal_uInt32 i = 0, nFlag = 0;
     273                 :            : 
     274         [ +  - ]:      26594 :     if( nEntries != (i = GetConstPos( nConstId )) ){
     275                 :      26594 :         nFlag = 1 << (i % (sizeof( sal_uInt32 ) * 8) );
     276                 :      26594 :         i = i / (sizeof( sal_uInt32 ) * 8);
     277         [ +  - ]:      26594 :         if( ((RscFlagInst *)rInst.pData)[ i ].nFlags & nFlag )
     278                 :      26594 :             return( sal_True );
     279                 :            :         else
     280                 :          0 :             return( sal_False );
     281                 :            :     };
     282                 :      26594 :     return( sal_True );
     283                 :            : }
     284                 :            : 
     285                 :            : /*************************************************************************
     286                 :            : |*
     287                 :            : |*    RscFlag::WriteSrc()
     288                 :            : |*
     289                 :            : *************************************************************************/
     290                 :          0 : void RscFlag::WriteSrc( const RSCINST & rInst, FILE * fOutput,
     291                 :            :                         RscTypCont *, sal_uInt32, const char * )
     292                 :            : {
     293                 :          0 :     sal_uInt32  i = 0, Flag = 0, nIndex = 0;
     294                 :          0 :     sal_Bool    bComma = sal_False;
     295                 :            : 
     296                 :          0 :     Flag = 1;
     297         [ #  # ]:          0 :     for( i = 0; i < nEntries; i++ ){
     298                 :          0 :         nIndex = i / (sizeof( sal_uInt32 ) * 8);
     299         [ #  # ]:          0 :         if( !( ((RscFlagInst *)rInst.pData)[ nIndex ].nDfltFlags & Flag) ){
     300         [ #  # ]:          0 :             if( bComma )
     301                 :          0 :                 fprintf( fOutput, ", " );
     302         [ #  # ]:          0 :             if( ((RscFlagInst *)rInst.pData)[ nIndex ].nFlags & Flag )
     303                 :          0 :                 fprintf( fOutput, "%s", pHS->getString( pVarArray[ i ].nId ).getStr() );
     304                 :            :             else{
     305                 :          0 :                 fprintf( fOutput, "not " );
     306                 :          0 :                 fprintf( fOutput, "%s", pHS->getString( pVarArray[ i ].nId ).getStr() );
     307                 :            :             }
     308                 :          0 :             bComma = sal_True;
     309                 :            :         }
     310                 :          0 :         Flag <<= 1;
     311         [ #  # ]:          0 :         if( !Flag )
     312                 :          0 :             Flag = 1;
     313                 :            :     };
     314                 :          0 : }
     315                 :            : 
     316                 :            : /*************************************************************************
     317                 :            : |*
     318                 :            : |*    RscFlag::WriteRc()
     319                 :            : |*
     320                 :            : *************************************************************************/
     321                 :      42068 : ERRTYPE RscFlag::WriteRc( const RSCINST & rInst, RscWriteRc & aMem,
     322                 :            :                           RscTypCont *, sal_uInt32, sal_Bool )
     323                 :            : {
     324                 :      42068 :     sal_Int32   lVal = 0;
     325                 :      42068 :     sal_uInt32  i = 0, Flag = 0, nIndex = 0;
     326                 :            : 
     327                 :      42068 :     Flag = 1;
     328         [ +  + ]:    1227284 :     for( i = 0; i < nEntries; i++ ){
     329                 :    1185216 :         nIndex = i / (sizeof( sal_uInt32 ) * 8);
     330         [ +  + ]:    1185216 :         if( ((RscFlagInst *)rInst.pData)[ nIndex ].nFlags & Flag )
     331                 :      26594 :             lVal |= pVarArray[ i ].lValue;
     332                 :            : 
     333                 :    1185216 :         Flag <<= 1;
     334         [ +  + ]:    1185216 :         if( !Flag )
     335                 :      20740 :             Flag = 1;
     336                 :            :     };
     337                 :            : 
     338                 :      42068 :     aMem.Put( (sal_Int32)lVal );
     339                 :      42068 :     return( ERR_OK );
     340                 :            : }
     341                 :            : 
     342                 :            : /*************************************************************************
     343                 :            : |*
     344                 :            : |*    RscClient::RscClient()
     345                 :            : |*
     346                 :            : *************************************************************************/
     347                 :     159840 : RscClient::RscClient( Atom nId, sal_uInt32 nTypeId, RscFlag * pClass,
     348                 :            :                        Atom nConstantId )
     349                 :     159840 :            : RscTop ( nId, nTypeId )
     350                 :            : {
     351                 :     159840 :    pRefClass = pClass;
     352                 :     159840 :    nConstId = nConstantId;
     353                 :     159840 : }
     354                 :            : 
     355                 :            : /*************************************************************************
     356                 :            : |*
     357                 :            : |*    RscClient::GetClassType()
     358                 :            : |*
     359                 :            : *************************************************************************/
     360                 :          0 : RSCCLASS_TYPE RscClient::GetClassType() const
     361                 :            : {
     362                 :          0 :     return RSCCLASS_BOOL;
     363                 :            : }
     364                 :            : 
     365                 :            : /*************************************************************************
     366                 :            : |*
     367                 :            : |*    RscClient::WriteSrc()
     368                 :            : |*
     369                 :            : *************************************************************************/
     370                 :      26594 : void RscClient::WriteSrc( const RSCINST & rInst, FILE * fOutput,
     371                 :            :                           RscTypCont *, sal_uInt32, const char * )
     372                 :            : {
     373         [ +  - ]:      26594 :     if( pRefClass->IsSet( rInst, nConstId ) )
     374                 :      26594 :         fprintf( fOutput, "TRUE" );
     375                 :            :     else
     376                 :          0 :         fprintf( fOutput, "FALSE" );
     377                 :      26594 : }
     378                 :            : 
     379                 :            : /*************************************************************************
     380                 :            : |*
     381                 :            : |*    RscClient::Create()
     382                 :            : |*
     383                 :            : *************************************************************************/
     384                 :     677272 : RSCINST RscClient::Create( RSCINST * pInst, const RSCINST & rDflt,
     385                 :            :                            sal_Bool bOwnClass )
     386                 :            : {
     387                 :     677272 :     RSCINST aTmpI, aDfltI;
     388                 :            : 
     389         [ +  + ]:     677272 :     if( pInst ){
     390                 :     669606 :         aTmpI.pClass = pRefClass;
     391                 :     669606 :         aTmpI.pData  = pInst->pData;
     392                 :            :     }
     393                 :            : 
     394 [ +  - ][ +  + ]:     677272 :     if( !bOwnClass && rDflt.IsInst() ){
                 [ +  + ]
     395         [ +  - ]:       2988 :         bOwnClass = rDflt.pClass->InHierarchy( this );
     396         [ +  - ]:       2988 :         if( bOwnClass ){
     397                 :       2988 :             aDfltI.pClass = pRefClass;
     398                 :       2988 :             aDfltI.pData = rDflt.pData;
     399                 :            :         }
     400                 :            :     }
     401                 :            : 
     402         [ +  + ]:     677272 :     if( pInst )
     403                 :            :         aTmpI = pRefClass->CreateClient( &aTmpI, aDfltI,
     404         [ +  - ]:     669606 :                                          bOwnClass, nConstId );
     405                 :            :     else
     406                 :            :         aTmpI = pRefClass->CreateClient( NULL, aDfltI,
     407         [ +  - ]:       7666 :                                          bOwnClass, nConstId );
     408                 :     677272 :     aTmpI.pClass = this;
     409                 :            : 
     410                 :     677272 :     return( aTmpI );
     411                 :            : }
     412                 :            : 
     413                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10