sync master with lastest vba changes
[ooovba.git] / rsc / inc / rscdef.hxx
blob926b814155668b16a44dcf8ef144cd256df38ab5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rscdef.hxx,v $
10 * $Revision: 1.7 $
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 ************************************************************************/
30 #ifndef _RSCDEF_HXX
31 #define _RSCDEF_HXX
33 #ifndef _TOOLS_UNQIDX_HXX
34 #include <tools/unqidx.hxx>
35 #endif
36 #include <rsctree.hxx>
38 /****************** C L A S S E S ****************************************/
39 class RscExpression;
40 class RscFileTab;
41 class RscDefine;
43 /*********** R s c E x p r e s s i o n ***********************************/
44 #define RSCEXP_LONG 0
45 #define RSCEXP_EXP 1
46 #define RSCEXP_DEF 2
47 #define RSCEXP_NOTHING 3
49 class RscExpType
51 public:
52 union {
53 RscExpression * pExp;
54 RscDefine * pDef;
55 struct {
56 short nHi;
57 unsigned short nLo;
58 } aLong;
59 } aExp;
60 char cType;
61 char cUnused;
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;
69 cType = RSCEXP_LONG;
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 ***************************************************/
80 class RscId
82 static BOOL bNames;// FALSE, bei den Namenoperation nur Zahlen
83 public:
84 RscExpType aExp; // Zahl, Define oder Ausdruck
85 INT32 GetNumber() const;
86 void Create( const RscExpType & rExpType );
87 void Create(){ aExp.cType = RSCEXP_NOTHING; }
89 RscId() { Create(); }
91 RscId( RscDefine * pEle );
92 RscId( INT32 lNumber )
93 { aExp.SetLong( lNumber ); }
95 RscId( const RscExpType & rExpType )
96 { Create( rExpType ); }
98 void Destroy();
100 ~RscId(){
101 Destroy();
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;
130 friend class RscId;
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
135 protected:
137 RscDefine( ULONG lFileKey, const ByteString & rDefName,
138 INT32 lDefId );
139 RscDefine( ULONG lFileKey, const ByteString & rDefName,
140 RscExpression * pExpression );
141 ~RscDefine();
142 void IncRef(){ nRefCount++; }
143 sal_uInt32 GetRefCount() const { return nRefCount; }
144 void DecRef();
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;
151 public:
152 RscDefine * Search( const char * );
153 ULONG GetFileKey() const { return lFileKey; }
154 BOOL Evaluate();
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;
164 private:
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 );
173 BOOL Remove();
174 public:
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;
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( INT32 * pValue );
189 ByteString GetMacro();
192 /********************** R S C F I L E ************************************/
193 class RscDepend {
194 ULONG lKey;
195 public:
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
206 public:
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
214 RscFile();
215 ~RscFile();
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
226 class RscDefTree {
227 RscDefine * pDefRoot;
228 public:
229 static BOOL Evaluate( RscDefine * pDef );
230 RscDefTree(){ pDefRoot = NULL; }
231 ~RscDefTree();
232 void Remove();
233 BOOL Evaluate();
234 RscDefine * Search( const char * pName );
235 void Insert( RscDefine * pDef );
236 void Remove( RscDefine * pDef );
239 class RscFileTab : public RscSubFileTab {
240 RscDefTree aDefTree;
241 ULONG Find( const ByteString & rName );
242 public:
243 RscFileTab();
244 ~RscFileTab();
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