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

Generated by: LCOV version 1.10