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

Generated by: LCOV version 1.11