xref: /aoo42x/main/rsc/inc/rscdef.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _RSCDEF_HXX
28 #define _RSCDEF_HXX
29 
30 #ifndef _TOOLS_UNQIDX_HXX
31 #include <tools/unqidx.hxx>
32 #endif
33 #include <rsctree.hxx>
34 
35 /****************** C L A S S E S ****************************************/
36 class RscExpression;
37 class RscFileTab;
38 class RscDefine;
39 
40 /*********** R s c E x p r e s s i o n ***********************************/
41 #define RSCEXP_LONG 	0
42 #define RSCEXP_EXP		1
43 #define RSCEXP_DEF		2
44 #define RSCEXP_NOTHING	3
45 
46 class RscExpType
47 {
48 public:
49 	union {
50 		RscExpression * pExp;
51 		RscDefine	  * pDef;
52 		struct {
53 			 short			 nHi;
54 			 unsigned short  nLo;
55 		} aLong;
56 	} aExp;
57 	char cType;
58 	char cUnused;
59 	sal_Bool IsNumber()    const { return( RSCEXP_LONG	   == cType ); }
60 	sal_Bool IsExpression()const { return( RSCEXP_EXP	   == cType ); }
61 	sal_Bool IsDefinition()const { return( RSCEXP_DEF	   == cType ); }
62 	sal_Bool IsNothing()   const { return( RSCEXP_NOTHING  == cType ); }
63 	void SetLong( sal_Int32 lValue ){
64 			aExp.aLong.nHi = (short)(lValue >> 16);
65 			aExp.aLong.nLo = (unsigned short)lValue;
66 			cType = RSCEXP_LONG;
67 		 }
68 	sal_Int32 GetLong() const{
69 			 return aExp.aLong.nLo |
70 					((sal_Int32)aExp.aLong.nHi << 16);
71 		 }
72 	sal_Bool Evaluate( sal_Int32 * pValue ) const;
73 	void GetMacro( ByteString & ) const;
74 };
75 
76 /*********** R s c I d ***************************************************/
77 class RscId
78 {
79 	static		sal_Bool bNames;// sal_False, bei den Namenoperation nur Zahlen
80 public:
81 	RscExpType	aExp;		// Zahl, Define oder Ausdruck
82 	sal_Int32	GetNumber() const;
83 	void	Create( const RscExpType & rExpType );
84 	void	Create(){ aExp.cType = RSCEXP_NOTHING; }
85 
86 			RscId() { Create(); 						}
87 
88 			RscId( RscDefine * pEle );
89 			RscId( sal_Int32 lNumber )
90 					{ aExp.SetLong( lNumber );			}
91 
92 			RscId( const RscExpType & rExpType )
93 					{ Create( rExpType );				}
94 
95 			void Destroy();
96 
97 			~RscId(){
98 				Destroy();
99 			}
100 
101 			RscId( const RscId& rRscId );
102 
103 			RscId& operator = ( const RscId& rRscId );
104 
105 	static sal_Bool    IsSetNames();
106 	static void    SetNames( sal_Bool bSet = sal_True );
107 	operator	     sal_Int32() const;   // Gibt Nummer zurueck
108 	ByteString	   GetName()  const;   // Gibt den Namen des Defines zurueck
109 	ByteString	   GetMacro()  const;  // Gibt das Macro zurueck
110 	sal_Bool	operator <	( const RscId& rRscId ) const;
111 	sal_Bool	operator >	( const RscId& rRscId ) const;
112 	sal_Bool	operator == ( const RscId& rRscId ) const;
113 	sal_Bool	operator <=  ( const RscId& rRscId ) const
114 			{ return !(operator > ( rRscId )); }
115 	sal_Bool	operator >= ( const RscId& rRscId ) const
116 			{ return !(operator < ( rRscId )); }
117 	sal_Bool	IsId() const { return !aExp.IsNothing(); }
118 };
119 
120 /*********** R s c D e f i n e *******************************************/
121 class RscDefine : public StringNode
122 {
123 friend class RscFileTab;
124 friend class RscDefineList;
125 friend class RscDefTree;
126 friend class RscExpression;
127 friend class RscId;
128 	sal_uLong			lFileKey;	// zu welcher Datei gehoert das Define
129 	sal_uInt32			nRefCount;	// Wieviele Referenzen auf dieses Objekt
130 	sal_Int32			lId;		// Identifier
131 	RscExpression * pExp;		// Ausdruck
132 protected:
133 
134 			RscDefine( sal_uLong lFileKey, const ByteString & rDefName,
135 					   sal_Int32 lDefId );
136 			RscDefine( sal_uLong lFileKey, const ByteString & rDefName,
137 					   RscExpression * pExpression );
138 			~RscDefine();
139 	void	IncRef(){ nRefCount++; }
140 	sal_uInt32	GetRefCount() const    { return nRefCount; }
141 	void	DecRef();
142 	void	DefineToNumber();
143 	void	SetName( const ByteString & rNewName ){ aName = rNewName; }
144 	void	ChangeMacro( RscExpression * pExpression );
145 	void	ChangeMacro( sal_Int32 lIdentifier );
146 
147     using StringNode::Search;
148 public:
149 	RscDefine * Search( const char * );
150 	sal_uLong		GetFileKey() const { return lFileKey; }
151 	sal_Bool		Evaluate();
152 	sal_Int32		GetNumber() const  { return lId;	  }
153 	ByteString	GetMacro();
154 };
155 
156 DECLARE_LIST( RscSubDefList, RscDefine * )
157 
158 class RscDefineList : public RscSubDefList {
159 friend class RscFile;
160 friend class RscFileTab;
161 private:
162 				// pExpression wird auf jedenfall Eigentum der Liste
163 	RscDefine * New( sal_uLong lFileKey, const ByteString & rDefName,
164 					 sal_Int32 lDefId, sal_uLong lPos );
165 	RscDefine * New( sal_uLong lFileKey, const ByteString & rDefName,
166 					 RscExpression * pExpression, sal_uLong lPos );
167 	sal_Bool		Befor( const RscDefine * pFree, const RscDefine * pDepend );
168 	sal_Bool		Remove( RscDefine * pDef );
169 	sal_Bool		Remove( sal_uLong nIndex );
170 	sal_Bool		Remove();
171 public:
172 	void		WriteAll( FILE * fOutput );
173 };
174 
175 /*********** R s c E x p r e s s i o n ***********************************/
176 class RscExpression {
177 friend class RscFileTab;
178 	char		cOperation;
179 	RscExpType	aLeftExp;
180 	RscExpType	aRightExp;
181 public:
182 				RscExpression( RscExpType aLE, char cOp,
183 							   RscExpType aRE );
184 				~RscExpression();
185 	sal_Bool		Evaluate( sal_Int32 * pValue );
186 	ByteString	GetMacro();
187 };
188 
189 /********************** R S C F I L E ************************************/
190 class RscDepend {
191 	sal_uLong			 lKey;
192 public:
193 			RscDepend( sal_uLong lIncKey ){ lKey = lIncKey; };
194 	sal_uLong	GetFileKey(){ return lKey; }
195 };
196 DECLARE_LIST( RscDependList, RscDepend * )
197 
198 // Tabelle die alle Dateinamen enthaelt
199 class RscFile : public RscDependList
200 {
201 friend class RscFileTab;
202 	sal_Bool			bIncFile;	// Ist es eine Include-Datei
203 public:
204 	sal_Bool			bLoaded;	// Ist die Datei geladen
205 	sal_Bool			bScanned;	// Wurde Datei nach Inclide abgesucht
206 	sal_Bool			bDirty; 	// Dirty-Flag
207 	ByteString		aFileName;	// Name der Datei
208 	ByteString		aPathName;	// Pfad und Name der Datei
209 	RscDefineList	aDefLst;	// Liste der Defines
210 
211 					RscFile();
212 					~RscFile();
213 	sal_Bool			InsertDependFile( sal_uLong lDepFile, sal_uLong lPos );
214 	void			RemoveDependFile( sal_uLong lDepFile );
215 	sal_Bool			Depend( sal_uLong lDepend, sal_uLong lFree );
216 	void			SetIncFlag(){ bIncFile = sal_True; };
217 	sal_Bool			IsIncFile(){  return bIncFile; };
218 };
219 
220 DECLARE_UNIQUEINDEX( RscSubFileTab, RscFile * )
221 #define NOFILE_INDEX UNIQUEINDEX_ENTRY_NOTFOUND
222 
223 class RscDefTree {
224 	RscDefine * pDefRoot;
225 public:
226 	static sal_Bool Evaluate( RscDefine * pDef );
227 				RscDefTree(){ pDefRoot = NULL; }
228 				~RscDefTree();
229 	void		Remove();
230 	sal_Bool		Evaluate();
231 	RscDefine * Search( const char * pName );
232 	void		Insert( RscDefine * pDef );
233 	void		Remove( RscDefine * pDef );
234 };
235 
236 class RscFileTab : public RscSubFileTab {
237 	RscDefTree aDefTree;
238 	sal_uLong		Find( const ByteString & rName );
239 public:
240 				RscFileTab();
241 				~RscFileTab();
242 
243 	RscDefine * FindDef( const char * );
244 	RscDefine * FindDef( const ByteString& rStr ) { return FindDef( rStr.GetBuffer() ); }
245 	RscDefine * FindDef( sal_uLong lKey, const ByteString & );
246 
247 	sal_Bool		Depend( sal_uLong lDepend, sal_uLong lFree );
248 	sal_Bool		TestDef( sal_uLong lFileKey, sal_uLong lPos,
249 						 const RscDefine * pDefDec );
250 	sal_Bool		TestDef( sal_uLong lFileKey, sal_uLong lPos,
251 						 const RscExpression * pExpDec );
252 
253 	RscDefine * NewDef( sal_uLong lKey, const ByteString & rDefName,
254 						sal_Int32 lId, sal_uLong lPos );
255 	RscDefine * NewDef( sal_uLong lKey, const ByteString & rDefName,
256 						RscExpression *, sal_uLong lPos );
257 
258 	sal_Bool		ChangeDef( const ByteString & rDefName, sal_Int32 lId );
259 	sal_Bool		ChangeDef( const ByteString & rDefName, RscExpression * );
260 
261 	sal_Bool IsDefUsed( const ByteString & );
262 	void DeleteDef( const ByteString & );
263 	sal_Bool ChangeDefName( const ByteString & rDefName,
264 						const ByteString & rNewName );
265 
266 		   // Alle Defines die in dieser Datei Definiert sind loeschen
267 	void   DeleteFileContext( sal_uLong lKey );
268 	void   DeleteFile( sal_uLong lKey );
269 	sal_uLong  NewCodeFile( const ByteString & rName );
270 	sal_uLong  NewIncFile( const ByteString & rName, const ByteString & rPath );
271 	RscFile * GetFile( sal_uLong lFileKey ){ return Get( lFileKey ); }
272 };
273 
274 #endif // _RSCDEF_HXX
275