1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_RSC_INC_RSCDEF_HXX
20 #define INCLUDED_RSC_INC_RSCDEF_HXX
22 #include <sal/config.h>
24 #include <tools/solar.h>
25 #include <tools/unqidx.hxx>
26 #include <rsctree.hxx>
27 #include <rtl/strbuf.hxx>
30 /****************** C L A S S E S ****************************************/
35 /*********** R s c E x p r e s s i o n ***********************************/
39 #define RSCEXP_NOTHING 3
56 bool IsNumber() const { return( RSCEXP_LONG
== cType
); }
57 bool IsExpression()const { return( RSCEXP_EXP
== cType
); }
58 bool IsDefinition()const { return( RSCEXP_DEF
== cType
); }
59 bool IsNothing() const { return( RSCEXP_NOTHING
== cType
); }
60 void SetLong( sal_Int32 lValue
)
62 aExp
.aLong
.nHi
= (short)(lValue
>> 16);
63 aExp
.aLong
.nLo
= (unsigned short)lValue
;
66 sal_Int32
GetLong() const
68 return aExp
.aLong
.nLo
|
69 ((sal_uInt32
)aExp
.aLong
.nHi
<< 16);
71 bool Evaluate( sal_Int32
* pValue
) const;
72 void AppendMacro( OStringBuffer
& ) const;
75 /*********** R s c I d ***************************************************/
78 static bool bNames
;// false, bei den Namenoperation nur Zahlen
80 RscExpType aExp
; // Zahl, Define oder Ausdruck
81 sal_Int32
GetNumber() const;
82 void Create( const RscExpType
& rExpType
);
83 void Create(){ aExp
.cType
= RSCEXP_NOTHING
; }
87 RscId( RscDefine
* pEle
);
88 RscId( sal_Int32 lNumber
)
91 aExp
.SetLong( lNumber
);
94 RscId( const RscExpType
& rExpType
)
95 { Create( rExpType
); }
99 ~RscId() { Destroy(); }
101 RscId( const RscId
& rRscId
);
103 RscId
& operator = ( const RscId
& rRscId
);
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 bool operator <= ( const RscId
& rRscId
) const
112 { return !(operator > ( rRscId
)); }
113 bool operator >= ( const RscId
& rRscId
) const
114 { return !(operator < ( rRscId
)); }
115 bool IsId() const { return !aExp
.IsNothing(); }
118 /*********** R s c D e f i n e *******************************************/
119 class RscDefine
: public StringNode
121 friend class RscFileTab
;
122 friend class RscDefineList
;
123 friend class RscDefTree
;
124 friend class RscExpression
;
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
132 RscDefine( sal_uLong lFileKey
, const OString
& rDefName
,
134 RscDefine( sal_uLong lFileKey
, const OString
& rDefName
,
135 RscExpression
* pExpression
);
136 virtual ~RscDefine();
137 void IncRef(){ nRefCount
++; }
138 sal_uInt32
GetRefCount() const { return nRefCount
; }
140 void DefineToNumber();
141 void SetName(const OString
& rNewName
) { m_aName
= rNewName
; }
143 using StringNode::Search
;
145 RscDefine
* Search( const char * );
146 sal_uLong
GetFileKey() const { return lFileKey
; }
148 sal_Int32
GetNumber() const { return lId
; }
152 typedef ::std::vector
< RscDefine
* > RscSubDefList
;
156 friend class RscFile
;
157 friend class RscFileTab
;
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
);
166 size_t GetPos( RscDefine
* item
)
168 for ( size_t i
= 0, n
= maList
.size(); i
< n
; ++i
)
169 if ( maList
[ i
] == item
)
174 void WriteAll( FILE * fOutput
);
177 /*********** R s c E x p r e s s i o n ***********************************/
180 friend class RscFileTab
;
183 RscExpType aRightExp
;
185 RscExpression( RscExpType aLE
, char cOp
,
188 bool Evaluate( sal_Int32
* pValue
);
192 /********************** R S C F I L E ************************************/
197 RscDepend( sal_uLong lIncKey
){ lKey
= lIncKey
; };
198 sal_uLong
GetFileKey(){ return lKey
; }
201 typedef ::std::vector
< RscDepend
* > RscDependList
;
203 // Tabelle die alle Dateinamen enthaelt
206 friend class RscFileTab
;
207 bool bIncFile
; // Ist es eine Include-Datei
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
219 bool InsertDependFile( sal_uLong lDepFile
, size_t lPos
);
220 bool Depend( sal_uLong lDepend
, sal_uLong lFree
);
221 void SetIncFlag(){ bIncFile
= true; };
222 bool IsIncFile(){ return bIncFile
; };
225 typedef UniqueIndex
<RscFile
> RscSubFileTab
;
226 #define NOFILE_INDEX UNIQUEINDEX_ENTRY_NOTFOUND
230 RscDefine
* pDefRoot
;
232 static bool Evaluate( RscDefine
* pDef
);
233 RscDefTree(){ pDefRoot
= NULL
; }
236 RscDefine
* Search( const char * pName
);
237 void Insert( RscDefine
* pDef
);
238 void Remove( RscDefine
* pDef
);
241 class RscFileTab
: public RscSubFileTab
244 sal_uLong
Find(const OString
& rName
);
249 RscDefine
* FindDef( const char * );
250 RscDefine
* FindDef(const OString
& rStr
)
252 return FindDef(rStr
.getStr());
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
);
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
);
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 RscFile
* GetFile( sal_uLong lFileKey
){ return Get( lFileKey
); }
273 #endif // INCLUDED_RSC_INC_RSCDEF_HXX
275 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */