LCOV - code coverage report
Current view: top level - rsc/inc - rscdef.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 27 43 62.8 %
Date: 2012-08-25 Functions: 19 28 67.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 4 0.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                 :            : #ifndef _RSCDEF_HXX
      20                 :            : #define _RSCDEF_HXX
      21                 :            : 
      22                 :            : #include <tools/unqidx.hxx>
      23                 :            : #include <rsctree.hxx>
      24                 :            : #include <rtl/strbuf.hxx>
      25                 :            : #include <vector>
      26                 :            : 
      27                 :            : /****************** C L A S S E S ****************************************/
      28                 :            : class RscExpression;
      29                 :            : class RscFileTab;
      30                 :            : class RscDefine;
      31                 :            : 
      32                 :            : /*********** R s c E x p r e s s i o n ***********************************/
      33                 :            : #define RSCEXP_LONG     0
      34                 :            : #define RSCEXP_EXP      1
      35                 :            : #define RSCEXP_DEF      2
      36                 :            : #define RSCEXP_NOTHING  3
      37                 :            : 
      38                 :            : class RscExpType
      39                 :            : {
      40                 :            : public:
      41                 :            :     union {
      42                 :            :         RscExpression * pExp;
      43                 :            :         RscDefine     * pDef;
      44                 :            :         struct {
      45                 :            :              short           nHi;
      46                 :            :              unsigned short  nLo;
      47                 :            :         } aLong;
      48                 :            :     } aExp;
      49                 :            :     char cType;
      50                 :            :     char cUnused;
      51                 :     225214 :     sal_Bool IsNumber()    const { return( RSCEXP_LONG     == cType ); }
      52                 :    5348710 :     sal_Bool IsExpression()const { return( RSCEXP_EXP      == cType ); }
      53                 :    7886286 :     sal_Bool IsDefinition()const { return( RSCEXP_DEF      == cType ); }
      54                 :    6253380 :     sal_Bool IsNothing()   const { return( RSCEXP_NOTHING  == cType ); }
      55                 :     660210 :     void SetLong( sal_Int32 lValue ){
      56                 :     660210 :             aExp.aLong.nHi = (short)(lValue >> 16);
      57                 :     660210 :             aExp.aLong.nLo = (unsigned short)lValue;
      58                 :     660210 :             cType = RSCEXP_LONG;
      59                 :     660210 :          }
      60                 :    5280744 :     sal_Int32 GetLong() const{
      61                 :            :              return aExp.aLong.nLo |
      62                 :    5280744 :                     ((sal_Int32)aExp.aLong.nHi << 16);
      63                 :            :          }
      64                 :            :     sal_Bool Evaluate( sal_Int32 * pValue ) const;
      65                 :            :     void AppendMacro( rtl::OStringBuffer & ) const;
      66                 :            : };
      67                 :            : 
      68                 :            : /*********** R s c I d ***************************************************/
      69                 :            : class RscId
      70                 :            : {
      71                 :            :     static      sal_Bool bNames;// sal_False, bei den Namenoperation nur Zahlen
      72                 :            : public:
      73                 :            :     RscExpType  aExp;       // Zahl, Define oder Ausdruck
      74                 :            :     sal_Int32   GetNumber() const;
      75                 :            :     void    Create( const RscExpType & rExpType );
      76                 :    1630700 :     void    Create(){ aExp.cType = RSCEXP_NOTHING; }
      77                 :            : 
      78                 :    1115132 :             RscId() { Create();                         }
      79                 :            : 
      80                 :            :             RscId( RscDefine * pEle );
      81                 :     158908 :             RscId( sal_Int32 lNumber )
      82                 :     158908 :                     { aExp.SetLong( lNumber );          }
      83                 :            : 
      84                 :      42476 :             RscId( const RscExpType & rExpType )
      85                 :      42476 :                     { Create( rExpType );               }
      86                 :            : 
      87                 :            :             void Destroy();
      88                 :            : 
      89                 :    1353260 :             ~RscId(){
      90                 :    1353260 :                 Destroy();
      91                 :    1353260 :             }
      92                 :            : 
      93                 :            :             RscId( const RscId& rRscId );
      94                 :            : 
      95                 :            :             RscId& operator = ( const RscId& rRscId );
      96                 :            : 
      97                 :            :     static void    SetNames( sal_Bool bSet = sal_True );
      98                 :            :     operator         sal_Int32() const;   // Gibt Nummer zurueck
      99                 :            :     rtl::OString GetName()  const;   // Gibt den Namen des Defines zurueck
     100                 :            :     sal_Bool    operator <  ( const RscId& rRscId ) const;
     101                 :            :     sal_Bool    operator >  ( const RscId& rRscId ) const;
     102                 :            :     sal_Bool    operator == ( const RscId& rRscId ) const;
     103                 :          0 :     sal_Bool    operator <=  ( const RscId& rRscId ) const
     104                 :          0 :             { return !(operator > ( rRscId )); }
     105                 :          0 :     sal_Bool    operator >= ( const RscId& rRscId ) const
     106                 :          0 :             { return !(operator < ( rRscId )); }
     107                 :     823192 :     sal_Bool    IsId() const { return !aExp.IsNothing(); }
     108                 :            : };
     109                 :            : 
     110                 :            : /*********** R s c D e f i n e *******************************************/
     111                 :            : class RscDefine : public StringNode
     112                 :            : {
     113                 :            : friend class RscFileTab;
     114                 :            : friend class RscDefineList;
     115                 :            : friend class RscDefTree;
     116                 :            : friend class RscExpression;
     117                 :            : friend class RscId;
     118                 :            :     sal_uLong           lFileKey;   // zu welcher Datei gehoert das Define
     119                 :            :     sal_uInt32          nRefCount;  // Wieviele Referenzen auf dieses Objekt
     120                 :            :     sal_Int32           lId;        // Identifier
     121                 :            :     RscExpression * pExp;       // Ausdruck
     122                 :            : protected:
     123                 :            : 
     124                 :            :             RscDefine( sal_uLong lFileKey, const rtl::OString& rDefName,
     125                 :            :                        sal_Int32 lDefId );
     126                 :            :             RscDefine( sal_uLong lFileKey, const rtl::OString& rDefName,
     127                 :            :                        RscExpression * pExpression );
     128                 :            :             ~RscDefine();
     129                 :          0 :     void    IncRef(){ nRefCount++; }
     130                 :            :     sal_uInt32  GetRefCount() const    { return nRefCount; }
     131                 :            :     void    DecRef();
     132                 :            :     void    DefineToNumber();
     133                 :          0 :     void    SetName(const rtl::OString& rNewName) { m_aName = rNewName; }
     134                 :            : 
     135                 :            :     using StringNode::Search;
     136                 :            : public:
     137                 :            :     RscDefine * Search( const char * );
     138                 :          0 :     sal_uLong       GetFileKey() const { return lFileKey; }
     139                 :            :     sal_Bool        Evaluate();
     140                 :          0 :     sal_Int32       GetNumber() const  { return lId;      }
     141                 :            :     rtl::OString    GetMacro();
     142                 :            : };
     143                 :            : 
     144                 :            : typedef ::std::vector< RscDefine* > RscSubDefList;
     145                 :            : 
     146                 :       5528 : class RscDefineList {
     147                 :            : friend class RscFile;
     148                 :            : friend class RscFileTab;
     149                 :            : private:
     150                 :            :     RscSubDefList   maList;
     151                 :            :                 // pExpression wird auf jedenfall Eigentum der Liste
     152                 :            :     RscDefine * New( sal_uLong lFileKey, const rtl::OString& rDefName,
     153                 :            :                      sal_Int32 lDefId, size_t lPos );
     154                 :            :     RscDefine * New( sal_uLong lFileKey, const rtl::OString& rDefName,
     155                 :            :                      RscExpression * pExpression, size_t lPos );
     156                 :            :     sal_Bool        Remove();
     157                 :          0 :     size_t      GetPos( RscDefine* item ) {
     158         [ #  # ]:          0 :                     for ( size_t i = 0, n = maList.size(); i < n; ++i )
     159         [ #  # ]:          0 :                         if ( maList[ i ] == item )
     160                 :          0 :                             return i;
     161                 :          0 :                     return size_t(-1);
     162                 :            :                 }
     163                 :            : public:
     164                 :            :     void        WriteAll( FILE * fOutput );
     165                 :            : };
     166                 :            : 
     167                 :            : /*********** R s c E x p r e s s i o n ***********************************/
     168                 :            : class RscExpression {
     169                 :            : friend class RscFileTab;
     170                 :            :     char        cOperation;
     171                 :            :     RscExpType  aLeftExp;
     172                 :            :     RscExpType  aRightExp;
     173                 :            : public:
     174                 :            :                 RscExpression( RscExpType aLE, char cOp,
     175                 :            :                                RscExpType aRE );
     176                 :            :                 ~RscExpression();
     177                 :            :     sal_Bool        Evaluate( sal_Int32 * pValue );
     178                 :            :     rtl::OString GetMacro();
     179                 :            : };
     180                 :            : 
     181                 :            : /********************** R S C F I L E ************************************/
     182                 :            : class RscDepend {
     183                 :            :     sal_uLong            lKey;
     184                 :            : public:
     185                 :       2764 :             RscDepend( sal_uLong lIncKey ){ lKey = lIncKey; };
     186                 :       1686 :     sal_uLong   GetFileKey(){ return lKey; }
     187                 :            : };
     188                 :            : 
     189                 :            : typedef ::std::vector< RscDepend* > RscDependList;
     190                 :            : 
     191                 :            : // Tabelle die alle Dateinamen enthaelt
     192                 :            : class RscFile
     193                 :            : {
     194                 :            : friend class RscFileTab;
     195                 :            :     sal_Bool            bIncFile;   // Ist es eine Include-Datei
     196                 :            : public:
     197                 :            :     sal_Bool            bLoaded;    // Ist die Datei geladen
     198                 :            :     sal_Bool            bScanned;   // Wurde Datei nach Inclide abgesucht
     199                 :            :     sal_Bool            bDirty;     // Dirty-Flag
     200                 :            :     rtl::OString aFileName;  // Name der Datei
     201                 :            :     rtl::OString aPathName;  // Pfad und Name der Datei
     202                 :            :     RscDefineList   aDefLst;    // Liste der Defines
     203                 :            :     RscDependList   aDepLst;    // List of Depend
     204                 :            : 
     205                 :            :                     RscFile();
     206                 :            :                     ~RscFile();
     207                 :            :     sal_Bool            InsertDependFile( sal_uLong lDepFile, size_t lPos );
     208                 :            :     sal_Bool            Depend( sal_uLong lDepend, sal_uLong lFree );
     209                 :          0 :     void            SetIncFlag(){ bIncFile = sal_True; };
     210                 :       4328 :     sal_Bool            IsIncFile(){  return bIncFile; };
     211                 :            : };
     212                 :            : 
     213                 :            : typedef UniqueIndex<RscFile> RscSubFileTab;
     214                 :            : #define NOFILE_INDEX UNIQUEINDEX_ENTRY_NOTFOUND
     215                 :            : 
     216                 :            : class RscDefTree {
     217                 :            :     RscDefine * pDefRoot;
     218                 :            : public:
     219                 :            :     static sal_Bool Evaluate( RscDefine * pDef );
     220                 :       1440 :                 RscDefTree(){ pDefRoot = NULL; }
     221                 :            :                 ~RscDefTree();
     222                 :            :     void        Remove();
     223                 :            :     RscDefine * Search( const char * pName );
     224                 :            :     void        Insert( RscDefine * pDef );
     225                 :            :     void        Remove( RscDefine * pDef );
     226                 :            : };
     227                 :            : 
     228                 :            : class RscFileTab : public RscSubFileTab
     229                 :            : {
     230                 :            :     RscDefTree aDefTree;
     231                 :            :     sal_uLong       Find(const rtl::OString& rName);
     232                 :            : public:
     233                 :            :                 RscFileTab();
     234                 :            :                 ~RscFileTab();
     235                 :            : 
     236                 :            :     RscDefine * FindDef( const char * );
     237                 :          0 :     RscDefine * FindDef(const rtl::OString& rStr)
     238                 :            :     {
     239                 :          0 :         return FindDef(rStr.getStr());
     240                 :            :     }
     241                 :            : 
     242                 :            :     sal_Bool        Depend( sal_uLong lDepend, sal_uLong lFree );
     243                 :            :     sal_Bool        TestDef( sal_uLong lFileKey, size_t lPos,
     244                 :            :                          const RscDefine * pDefDec );
     245                 :            :     sal_Bool        TestDef( sal_uLong lFileKey, size_t lPos,
     246                 :            :                          const RscExpression * pExpDec );
     247                 :            : 
     248                 :            :     RscDefine * NewDef( sal_uLong lKey, const rtl::OString& rDefName,
     249                 :            :                         sal_Int32 lId, sal_uLong lPos );
     250                 :            :     RscDefine * NewDef( sal_uLong lKey, const rtl::OString& rDefName,
     251                 :            :                         RscExpression *, sal_uLong lPos );
     252                 :            : 
     253                 :            :            // Alle Defines die in dieser Datei Definiert sind loeschen
     254                 :            :     void   DeleteFileContext( sal_uLong lKey );
     255                 :            :     sal_uLong  NewCodeFile(const rtl::OString& rName);
     256                 :            :     sal_uLong  NewIncFile(const rtl::OString& rName, const rtl::OString& rPath);
     257                 :        366 :     RscFile * GetFile( sal_uLong lFileKey ){ return Get( lFileKey ); }
     258                 :            : };
     259                 :            : 
     260                 :            : #endif // _RSCDEF_HXX
     261                 :            : 
     262                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10