bump product version to 4.2.0.1
[LibreOffice.git] / rsc / inc / rscdef.hxx
blobf279ddb2f18fcdd500c58b071783933860bffa0c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 _RSCDEF_HXX
20 #define _RSCDEF_HXX
22 #include <tools/unqidx.hxx>
23 #include <rsctree.hxx>
24 #include <rtl/strbuf.hxx>
25 #include <vector>
27 /****************** C L A S S E S ****************************************/
28 class RscExpression;
29 class RscFileTab;
30 class RscDefine;
32 /*********** R s c E x p r e s s i o n ***********************************/
33 #define RSCEXP_LONG 0
34 #define RSCEXP_EXP 1
35 #define RSCEXP_DEF 2
36 #define RSCEXP_NOTHING 3
38 class RscExpType
40 public:
41 union
43 RscExpression * pExp;
44 RscDefine * pDef;
45 struct
47 short nHi;
48 unsigned short nLo;
49 } aLong;
50 } aExp;
51 char cType;
52 char cUnused;
53 bool IsNumber() const { return( RSCEXP_LONG == cType ); }
54 bool IsExpression()const { return( RSCEXP_EXP == cType ); }
55 bool IsDefinition()const { return( RSCEXP_DEF == cType ); }
56 bool IsNothing() const { return( RSCEXP_NOTHING == cType ); }
57 void SetLong( sal_Int32 lValue )
59 aExp.aLong.nHi = (short)(lValue >> 16);
60 aExp.aLong.nLo = (unsigned short)lValue;
61 cType = RSCEXP_LONG;
63 sal_Int32 GetLong() const
65 return aExp.aLong.nLo |
66 ((sal_Int32)aExp.aLong.nHi << 16);
68 bool Evaluate( sal_Int32 * pValue ) const;
69 void AppendMacro( OStringBuffer & ) const;
72 /*********** R s c I d ***************************************************/
73 class RscId
75 static bool bNames;// 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 );
80 void Create(){ aExp.cType = RSCEXP_NOTHING; }
82 RscId() { Create(); }
84 RscId( RscDefine * pEle );
85 RscId( sal_Int32 lNumber )
86 { aExp.SetLong( lNumber ); }
88 RscId( const RscExpType & rExpType )
89 { Create( rExpType ); }
91 void Destroy();
93 ~RscId() { Destroy(); }
95 RscId( const RscId& rRscId );
97 RscId& operator = ( const RscId& rRscId );
99 static void SetNames( bool bSet = true );
100 operator sal_Int32() const; // Gibt Nummer zurueck
101 OString GetName() const; // Gibt den Namen des Defines zurueck
102 bool operator < ( const RscId& rRscId ) const;
103 bool operator > ( const RscId& rRscId ) const;
104 bool operator == ( const RscId& rRscId ) const;
105 bool operator <= ( const RscId& rRscId ) const
106 { return !(operator > ( rRscId )); }
107 bool operator >= ( const RscId& rRscId ) const
108 { return !(operator < ( rRscId )); }
109 bool IsId() const { return !aExp.IsNothing(); }
112 /*********** R s c D e f i n e *******************************************/
113 class RscDefine : public StringNode
115 friend class RscFileTab;
116 friend class RscDefineList;
117 friend class RscDefTree;
118 friend class RscExpression;
119 friend class RscId;
120 sal_uLong lFileKey; // zu welcher Datei gehoert das Define
121 sal_uInt32 nRefCount; // Wieviele Referenzen auf dieses Objekt
122 sal_Int32 lId; // Identifier
123 RscExpression * pExp; // Ausdruck
124 protected:
126 RscDefine( sal_uLong lFileKey, const OString& rDefName,
127 sal_Int32 lDefId );
128 RscDefine( sal_uLong lFileKey, const OString& rDefName,
129 RscExpression * pExpression );
130 ~RscDefine();
131 void IncRef(){ nRefCount++; }
132 sal_uInt32 GetRefCount() const { return nRefCount; }
133 void DecRef();
134 void DefineToNumber();
135 void SetName(const OString& rNewName) { m_aName = rNewName; }
137 using StringNode::Search;
138 public:
139 RscDefine * Search( const char * );
140 sal_uLong GetFileKey() const { return lFileKey; }
141 bool Evaluate();
142 sal_Int32 GetNumber() const { return lId; }
143 OString GetMacro();
146 typedef ::std::vector< RscDefine* > RscSubDefList;
148 class RscDefineList
150 friend class RscFile;
151 friend class RscFileTab;
152 private:
153 RscSubDefList maList;
154 // pExpression wird auf jedenfall Eigentum der Liste
155 RscDefine * New( sal_uLong lFileKey, const OString& rDefName,
156 sal_Int32 lDefId, size_t lPos );
157 RscDefine * New( sal_uLong lFileKey, const OString& rDefName,
158 RscExpression * pExpression, size_t lPos );
159 bool Remove();
160 size_t GetPos( RscDefine* item )
162 for ( size_t i = 0, n = maList.size(); i < n; ++i )
163 if ( maList[ i ] == item )
164 return i;
165 return size_t(-1);
167 public:
168 void WriteAll( FILE * fOutput );
171 /*********** R s c E x p r e s s i o n ***********************************/
172 class RscExpression
174 friend class RscFileTab;
175 char cOperation;
176 RscExpType aLeftExp;
177 RscExpType aRightExp;
178 public:
179 RscExpression( RscExpType aLE, char cOp,
180 RscExpType aRE );
181 ~RscExpression();
182 bool Evaluate( sal_Int32 * pValue );
183 OString GetMacro();
186 /********************** R S C F I L E ************************************/
187 class RscDepend
189 sal_uLong lKey;
190 public:
191 RscDepend( sal_uLong lIncKey ){ lKey = lIncKey; };
192 sal_uLong GetFileKey(){ return lKey; }
195 typedef ::std::vector< RscDepend* > RscDependList;
197 // Tabelle die alle Dateinamen enthaelt
198 class RscFile
200 friend class RscFileTab;
201 bool bIncFile; // Ist es eine Include-Datei
202 public:
203 bool bLoaded; // Ist die Datei geladen
204 bool bScanned; // Wurde Datei nach Inclide abgesucht
205 bool bDirty; // Dirty-Flag
206 OString aFileName; // Name der Datei
207 OString aPathName; // Pfad und Name der Datei
208 RscDefineList aDefLst; // Liste der Defines
209 RscDependList aDepLst; // List of Depend
211 RscFile();
212 ~RscFile();
213 bool InsertDependFile( sal_uLong lDepFile, size_t lPos );
214 bool Depend( sal_uLong lDepend, sal_uLong lFree );
215 void SetIncFlag(){ bIncFile = true; };
216 bool IsIncFile(){ return bIncFile; };
219 typedef UniqueIndex<RscFile> RscSubFileTab;
220 #define NOFILE_INDEX UNIQUEINDEX_ENTRY_NOTFOUND
222 class RscDefTree
224 RscDefine * pDefRoot;
225 public:
226 static bool Evaluate( RscDefine * pDef );
227 RscDefTree(){ pDefRoot = NULL; }
228 ~RscDefTree();
229 void Remove();
230 RscDefine * Search( const char * pName );
231 void Insert( RscDefine * pDef );
232 void Remove( RscDefine * pDef );
235 class RscFileTab : public RscSubFileTab
237 RscDefTree aDefTree;
238 sal_uLong Find(const OString& rName);
239 public:
240 RscFileTab();
241 ~RscFileTab();
243 RscDefine * FindDef( const char * );
244 RscDefine * FindDef(const OString& rStr)
246 return FindDef(rStr.getStr());
249 bool Depend( sal_uLong lDepend, sal_uLong lFree );
250 bool TestDef( sal_uLong lFileKey, size_t lPos,
251 const RscDefine * pDefDec );
252 bool TestDef( sal_uLong lFileKey, size_t lPos,
253 const RscExpression * pExpDec );
255 RscDefine * NewDef( sal_uLong lKey, const OString& rDefName,
256 sal_Int32 lId, sal_uLong lPos );
257 RscDefine * NewDef( sal_uLong lKey, const OString& rDefName,
258 RscExpression *, sal_uLong lPos );
260 // Alle Defines die in dieser Datei Definiert sind loeschen
261 void DeleteFileContext( sal_uLong lKey );
262 sal_uLong NewCodeFile(const OString& rName);
263 sal_uLong NewIncFile(const OString& rName, const OString& rPath);
264 RscFile * GetFile( sal_uLong lFileKey ){ return Get( lFileKey ); }
267 #endif // _RSCDEF_HXX
269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */