xref: /trunk/main/rsc/inc/rscdef.hxx (revision f7c60c9c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _RSCDEF_HXX
24 #define _RSCDEF_HXX
25 
26 #ifndef _TOOLS_UNQIDX_HXX
27 #include <tools/unqidx.hxx>
28 #endif
29 #include <rsctree.hxx>
30 
31 /****************** C L A S S E S ****************************************/
32 class RscExpression;
33 class RscFileTab;
34 class RscDefine;
35 
36 /*********** R s c E x p r e s s i o n ***********************************/
37 #define RSCEXP_LONG 	0
38 #define RSCEXP_EXP		1
39 #define RSCEXP_DEF		2
40 #define RSCEXP_NOTHING	3
41 
42 class RscExpType
43 {
44 public:
45 	union {
46 		RscExpression * pExp;
47 		RscDefine	  * pDef;
48 		struct {
49 			 short			 nHi;
50 			 unsigned short  nLo;
51 		} aLong;
52 	} aExp;
53 	char cType;
54 	char cUnused;
IsNumber() const55 	sal_Bool IsNumber()    const { return( RSCEXP_LONG	   == cType ); }
IsExpression() const56 	sal_Bool IsExpression()const { return( RSCEXP_EXP	   == cType ); }
IsDefinition() const57 	sal_Bool IsDefinition()const { return( RSCEXP_DEF	   == cType ); }
IsNothing() const58 	sal_Bool IsNothing()   const { return( RSCEXP_NOTHING  == cType ); }
SetLong(sal_Int32 lValue)59 	void SetLong( sal_Int32 lValue ){
60 			aExp.aLong.nHi = (short)(lValue >> 16);
61 			aExp.aLong.nLo = (unsigned short)lValue;
62 			cType = RSCEXP_LONG;
63 		 }
GetLong() const64 	sal_Int32 GetLong() const{
65 			 return aExp.aLong.nLo |
66 					((sal_Int32)aExp.aLong.nHi << 16);
67 		 }
68 	sal_Bool Evaluate( sal_Int32 * pValue ) const;
69 	void GetMacro( ByteString & ) const;
70 };
71 
72 /*********** R s c I d ***************************************************/
73 class RscId
74 {
75 	static		sal_Bool bNames;// sal_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 );
Create()80 	void	Create(){ aExp.cType = RSCEXP_NOTHING; }
81 
RscId()82 			RscId() { Create(); 						}
83 
84 			RscId( RscDefine * pEle );
RscId(sal_Int32 lNumber)85 			RscId( sal_Int32 lNumber )
86 					{ aExp.SetLong( lNumber );			}
87 
RscId(const RscExpType & rExpType)88 			RscId( const RscExpType & rExpType )
89 					{ Create( rExpType );				}
90 
91 			void Destroy();
92 
~RscId()93 			~RscId(){
94 				Destroy();
95 			}
96 
97 			RscId( const RscId& rRscId );
98 
99 			RscId& operator = ( const RscId& rRscId );
100 
101 	static sal_Bool    IsSetNames();
102 	static void    SetNames( sal_Bool bSet = sal_True );
103 	operator	     sal_Int32() const;   // Gibt Nummer zurueck
104 	ByteString	   GetName()  const;   // Gibt den Namen des Defines zurueck
105 	ByteString	   GetMacro()  const;  // Gibt das Macro zurueck
106 	sal_Bool	operator <	( const RscId& rRscId ) const;
107 	sal_Bool	operator >	( const RscId& rRscId ) const;
108 	sal_Bool	operator == ( const RscId& rRscId ) const;
operator <=(const RscId & rRscId) const109 	sal_Bool	operator <=  ( const RscId& rRscId ) const
110 			{ return !(operator > ( rRscId )); }
operator >=(const RscId & rRscId) const111 	sal_Bool	operator >= ( const RscId& rRscId ) const
112 			{ return !(operator < ( rRscId )); }
IsId() const113 	sal_Bool	IsId() const { return !aExp.IsNothing(); }
114 };
115 
116 /*********** R s c D e f i n e *******************************************/
117 class RscDefine : public StringNode
118 {
119 friend class RscFileTab;
120 friend class RscDefineList;
121 friend class RscDefTree;
122 friend class RscExpression;
123 friend class RscId;
124 	sal_uLong			lFileKey;	// zu welcher Datei gehoert das Define
125 	sal_uInt32			nRefCount;	// Wieviele Referenzen auf dieses Objekt
126 	sal_Int32			lId;		// Identifier
127 	RscExpression * pExp;		// Ausdruck
128 protected:
129 
130 			RscDefine( sal_uLong lFileKey, const ByteString & rDefName,
131 					   sal_Int32 lDefId );
132 			RscDefine( sal_uLong lFileKey, const ByteString & rDefName,
133 					   RscExpression * pExpression );
134 			~RscDefine();
IncRef()135 	void	IncRef(){ nRefCount++; }
GetRefCount() const136 	sal_uInt32	GetRefCount() const    { return nRefCount; }
137 	void	DecRef();
138 	void	DefineToNumber();
SetName(const ByteString & rNewName)139 	void	SetName( const ByteString & rNewName ){ aName = rNewName; }
140 	void	ChangeMacro( RscExpression * pExpression );
141 	void	ChangeMacro( sal_Int32 lIdentifier );
142 
143     using StringNode::Search;
144 public:
145 	RscDefine * Search( const char * );
GetFileKey() const146 	sal_uLong		GetFileKey() const { return lFileKey; }
147 	sal_Bool		Evaluate();
GetNumber() const148 	sal_Int32		GetNumber() const  { return lId;	  }
149 	ByteString	GetMacro();
150 };
151 
152 DECLARE_LIST( RscSubDefList, RscDefine * )
153 
154 class RscDefineList : public RscSubDefList {
155 friend class RscFile;
156 friend class RscFileTab;
157 private:
158 				// pExpression wird auf jedenfall Eigentum der Liste
159 	RscDefine * New( sal_uLong lFileKey, const ByteString & rDefName,
160 					 sal_Int32 lDefId, sal_uLong lPos );
161 	RscDefine * New( sal_uLong lFileKey, const ByteString & rDefName,
162 					 RscExpression * pExpression, sal_uLong lPos );
163 	sal_Bool		Befor( const RscDefine * pFree, const RscDefine * pDepend );
164 	sal_Bool		Remove( RscDefine * pDef );
165 	sal_Bool		Remove( sal_uLong nIndex );
166 	sal_Bool		Remove();
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 friend class RscFileTab;
174 	char		cOperation;
175 	RscExpType	aLeftExp;
176 	RscExpType	aRightExp;
177 public:
178 				RscExpression( RscExpType aLE, char cOp,
179 							   RscExpType aRE );
180 				~RscExpression();
181 	sal_Bool		Evaluate( sal_Int32 * pValue );
182 	ByteString	GetMacro();
183 };
184 
185 /********************** R S C F I L E ************************************/
186 class RscDepend {
187 	sal_uLong			 lKey;
188 public:
RscDepend(sal_uLong lIncKey)189 			RscDepend( sal_uLong lIncKey ){ lKey = lIncKey; };
GetFileKey()190 	sal_uLong	GetFileKey(){ return lKey; }
191 };
192 DECLARE_LIST( RscDependList, RscDepend * )
193 
194 // Tabelle die alle Dateinamen enthaelt
195 class RscFile : public RscDependList
196 {
197 friend class RscFileTab;
198 	sal_Bool			bIncFile;	// Ist es eine Include-Datei
199 public:
200 	sal_Bool			bLoaded;	// Ist die Datei geladen
201 	sal_Bool			bScanned;	// Wurde Datei nach Inclide abgesucht
202 	sal_Bool			bDirty; 	// Dirty-Flag
203 	ByteString		aFileName;	// Name der Datei
204 	ByteString		aPathName;	// Pfad und Name der Datei
205 	RscDefineList	aDefLst;	// Liste der Defines
206 
207 					RscFile();
208 					~RscFile();
209 	sal_Bool			InsertDependFile( sal_uLong lDepFile, sal_uLong lPos );
210 	void			RemoveDependFile( sal_uLong lDepFile );
211 	sal_Bool			Depend( sal_uLong lDepend, sal_uLong lFree );
SetIncFlag()212 	void			SetIncFlag(){ bIncFile = sal_True; };
IsIncFile()213 	sal_Bool			IsIncFile(){  return bIncFile; };
214 };
215 
216 DECLARE_UNIQUEINDEX( RscSubFileTab, RscFile * )
217 #define NOFILE_INDEX UNIQUEINDEX_ENTRY_NOTFOUND
218 
219 class RscDefTree {
220 	RscDefine * pDefRoot;
221 public:
222 	static sal_Bool Evaluate( RscDefine * pDef );
RscDefTree()223 				RscDefTree(){ pDefRoot = NULL; }
224 				~RscDefTree();
225 	void		Remove();
226 	sal_Bool		Evaluate();
227 	RscDefine * Search( const char * pName );
228 	void		Insert( RscDefine * pDef );
229 	void		Remove( RscDefine * pDef );
230 };
231 
232 class RscFileTab : public RscSubFileTab {
233 	RscDefTree aDefTree;
234 	sal_uLong		Find( const ByteString & rName );
235 public:
236 				RscFileTab();
237 				~RscFileTab();
238 
239 	RscDefine * FindDef( const char * );
FindDef(const ByteString & rStr)240 	RscDefine * FindDef( const ByteString& rStr ) { return FindDef( rStr.GetBuffer() ); }
241 	RscDefine * FindDef( sal_uLong lKey, const ByteString & );
242 
243 	sal_Bool		Depend( sal_uLong lDepend, sal_uLong lFree );
244 	sal_Bool		TestDef( sal_uLong lFileKey, sal_uLong lPos,
245 						 const RscDefine * pDefDec );
246 	sal_Bool		TestDef( sal_uLong lFileKey, sal_uLong lPos,
247 						 const RscExpression * pExpDec );
248 
249 	RscDefine * NewDef( sal_uLong lKey, const ByteString & rDefName,
250 						sal_Int32 lId, sal_uLong lPos );
251 	RscDefine * NewDef( sal_uLong lKey, const ByteString & rDefName,
252 						RscExpression *, sal_uLong lPos );
253 
254 	sal_Bool		ChangeDef( const ByteString & rDefName, sal_Int32 lId );
255 	sal_Bool		ChangeDef( const ByteString & rDefName, RscExpression * );
256 
257 	sal_Bool IsDefUsed( const ByteString & );
258 	void DeleteDef( const ByteString & );
259 	sal_Bool ChangeDefName( const ByteString & rDefName,
260 						const ByteString & rNewName );
261 
262 		   // Alle Defines die in dieser Datei Definiert sind loeschen
263 	void   DeleteFileContext( sal_uLong lKey );
264 	void   DeleteFile( sal_uLong lKey );
265 	sal_uLong  NewCodeFile( const ByteString & rName );
266 	sal_uLong  NewIncFile( const ByteString & rName, const ByteString & rPath );
GetFile(sal_uLong lFileKey)267 	RscFile * GetFile( sal_uLong lFileKey ){ return Get( lFileKey ); }
268 };
269 
270 #endif // _RSCDEF_HXX
271