1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rscdef.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #ifndef _TOOLS_UNQIDX_HXX
34 #include <tools/unqidx.hxx>
36 #include <rsctree.hxx>
38 /****************** C L A S S E S ****************************************/
43 /*********** R s c E x p r e s s i o n ***********************************/
47 #define RSCEXP_NOTHING 3
62 BOOL
IsNumber() const { return( RSCEXP_LONG
== cType
); }
63 BOOL
IsExpression()const { return( RSCEXP_EXP
== cType
); }
64 BOOL
IsDefinition()const { return( RSCEXP_DEF
== cType
); }
65 BOOL
IsNothing() const { return( RSCEXP_NOTHING
== cType
); }
66 void SetLong( INT32 lValue
){
67 aExp
.aLong
.nHi
= (short)(lValue
>> 16);
68 aExp
.aLong
.nLo
= (unsigned short)lValue
;
71 INT32
GetLong() const{
72 return aExp
.aLong
.nLo
|
73 ((INT32
)aExp
.aLong
.nHi
<< 16);
75 BOOL
Evaluate( INT32
* pValue
) const;
76 void GetMacro( ByteString
& ) const;
79 /*********** R s c I d ***************************************************/
82 static BOOL bNames
;// FALSE, bei den Namenoperation nur Zahlen
84 RscExpType aExp
; // Zahl, Define oder Ausdruck
85 INT32
GetNumber() const;
86 void Create( const RscExpType
& rExpType
);
87 void Create(){ aExp
.cType
= RSCEXP_NOTHING
; }
91 RscId( RscDefine
* pEle
);
92 RscId( INT32 lNumber
)
93 { aExp
.SetLong( lNumber
); }
95 RscId( const RscExpType
& rExpType
)
96 { Create( rExpType
); }
104 RscId( const RscId
& rRscId
);
106 RscId
& operator = ( const RscId
& rRscId
);
108 static BOOL
IsSetNames();
109 static void SetNames( BOOL bSet
= TRUE
);
110 operator INT32() const; // Gibt Nummer zurueck
111 ByteString
GetName() const; // Gibt den Namen des Defines zurueck
112 ByteString
GetMacro() const; // Gibt das Macro zurueck
113 BOOL
operator < ( const RscId
& rRscId
) const;
114 BOOL
operator > ( const RscId
& rRscId
) const;
115 BOOL
operator == ( const RscId
& rRscId
) const;
116 BOOL
operator <= ( const RscId
& rRscId
) const
117 { return !(operator > ( rRscId
)); }
118 BOOL
operator >= ( const RscId
& rRscId
) const
119 { return !(operator < ( rRscId
)); }
120 BOOL
IsId() const { return !aExp
.IsNothing(); }
123 /*********** R s c D e f i n e *******************************************/
124 class RscDefine
: public StringNode
126 friend class RscFileTab
;
127 friend class RscDefineList
;
128 friend class RscDefTree
;
129 friend class RscExpression
;
131 ULONG lFileKey
; // zu welcher Datei gehoert das Define
132 sal_uInt32 nRefCount
; // Wieviele Referenzen auf dieses Objekt
133 INT32 lId
; // Identifier
134 RscExpression
* pExp
; // Ausdruck
137 RscDefine( ULONG lFileKey
, const ByteString
& rDefName
,
139 RscDefine( ULONG lFileKey
, const ByteString
& rDefName
,
140 RscExpression
* pExpression
);
142 void IncRef(){ nRefCount
++; }
143 sal_uInt32
GetRefCount() const { return nRefCount
; }
145 void DefineToNumber();
146 void SetName( const ByteString
& rNewName
){ aName
= rNewName
; }
147 void ChangeMacro( RscExpression
* pExpression
);
148 void ChangeMacro( INT32 lIdentifier
);
150 using StringNode::Search
;
152 RscDefine
* Search( const char * );
153 ULONG
GetFileKey() const { return lFileKey
; }
155 INT32
GetNumber() const { return lId
; }
156 ByteString
GetMacro();
159 DECLARE_LIST( RscSubDefList
, RscDefine
* )
161 class RscDefineList
: public RscSubDefList
{
162 friend class RscFile
;
163 friend class RscFileTab
;
165 // pExpression wird auf jedenfall Eigentum der Liste
166 RscDefine
* New( ULONG lFileKey
, const ByteString
& rDefName
,
167 INT32 lDefId
, ULONG lPos
);
168 RscDefine
* New( ULONG lFileKey
, const ByteString
& rDefName
,
169 RscExpression
* pExpression
, ULONG lPos
);
170 BOOL
Befor( const RscDefine
* pFree
, const RscDefine
* pDepend
);
171 BOOL
Remove( RscDefine
* pDef
);
172 BOOL
Remove( ULONG nIndex
);
175 void WriteAll( FILE * fOutput
);
178 /*********** R s c E x p r e s s i o n ***********************************/
179 class RscExpression
{
180 friend class RscFileTab
;
183 RscExpType aRightExp
;
185 RscExpression( RscExpType aLE
, char cOp
,
188 BOOL
Evaluate( INT32
* pValue
);
189 ByteString
GetMacro();
192 /********************** R S C F I L E ************************************/
196 RscDepend( ULONG lIncKey
){ lKey
= lIncKey
; };
197 ULONG
GetFileKey(){ return lKey
; }
199 DECLARE_LIST( RscDependList
, RscDepend
* )
201 // Tabelle die alle Dateinamen enthaelt
202 class RscFile
: public RscDependList
204 friend class RscFileTab
;
205 BOOL bIncFile
; // Ist es eine Include-Datei
207 BOOL bLoaded
; // Ist die Datei geladen
208 BOOL bScanned
; // Wurde Datei nach Inclide abgesucht
209 BOOL bDirty
; // Dirty-Flag
210 ByteString aFileName
; // Name der Datei
211 ByteString aPathName
; // Pfad und Name der Datei
212 RscDefineList aDefLst
; // Liste der Defines
216 BOOL
InsertDependFile( ULONG lDepFile
, ULONG lPos
);
217 void RemoveDependFile( ULONG lDepFile
);
218 BOOL
Depend( ULONG lDepend
, ULONG lFree
);
219 void SetIncFlag(){ bIncFile
= TRUE
; };
220 BOOL
IsIncFile(){ return bIncFile
; };
223 DECLARE_UNIQUEINDEX( RscSubFileTab
, RscFile
* )
224 #define NOFILE_INDEX UNIQUEINDEX_ENTRY_NOTFOUND
227 RscDefine
* pDefRoot
;
229 static BOOL
Evaluate( RscDefine
* pDef
);
230 RscDefTree(){ pDefRoot
= NULL
; }
234 RscDefine
* Search( const char * pName
);
235 void Insert( RscDefine
* pDef
);
236 void Remove( RscDefine
* pDef
);
239 class RscFileTab
: public RscSubFileTab
{
241 ULONG
Find( const ByteString
& rName
);
246 RscDefine
* FindDef( const char * );
247 RscDefine
* FindDef( const ByteString
& rStr
) { return FindDef( rStr
.GetBuffer() ); }
248 RscDefine
* FindDef( ULONG lKey
, const ByteString
& );
250 BOOL
Depend( ULONG lDepend
, ULONG lFree
);
251 BOOL
TestDef( ULONG lFileKey
, ULONG lPos
,
252 const RscDefine
* pDefDec
);
253 BOOL
TestDef( ULONG lFileKey
, ULONG lPos
,
254 const RscExpression
* pExpDec
);
256 RscDefine
* NewDef( ULONG lKey
, const ByteString
& rDefName
,
257 INT32 lId
, ULONG lPos
);
258 RscDefine
* NewDef( ULONG lKey
, const ByteString
& rDefName
,
259 RscExpression
*, ULONG lPos
);
261 BOOL
ChangeDef( const ByteString
& rDefName
, INT32 lId
);
262 BOOL
ChangeDef( const ByteString
& rDefName
, RscExpression
* );
264 BOOL
IsDefUsed( const ByteString
& );
265 void DeleteDef( const ByteString
& );
266 BOOL
ChangeDefName( const ByteString
& rDefName
,
267 const ByteString
& rNewName
);
269 // Alle Defines die in dieser Datei Definiert sind loeschen
270 void DeleteFileContext( ULONG lKey
);
271 void DeleteFile( ULONG lKey
);
272 ULONG
NewCodeFile( const ByteString
& rName
);
273 ULONG
NewIncFile( const ByteString
& rName
, const ByteString
& rPath
);
274 RscFile
* GetFile( ULONG lFileKey
){ return Get( lFileKey
); }
277 #endif // _RSCDEF_HXX