bump product version to 5.0.4.1
[LibreOffice.git] / rsc / inc / rscdef.hxx
blobf6d378d14db602ea27606bddfb798027621b8b91
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 INCLUDED_RSC_INC_RSCDEF_HXX
20 #define INCLUDED_RSC_INC_RSCDEF_HXX
22 #include <sal/config.h>
24 #include <tools/solar.h>
25 #include <tools/unqidx.hxx>
26 #include <rsctree.hxx>
27 #include <rtl/strbuf.hxx>
28 #include <vector>
30 /****************** C L A S S E S ****************************************/
31 class RscExpression;
32 class RscFileTab;
33 class RscDefine;
35 /*********** R s c E x p r e s s i o n ***********************************/
36 #define RSCEXP_LONG 0
37 #define RSCEXP_EXP 1
38 #define RSCEXP_DEF 2
39 #define RSCEXP_NOTHING 3
41 class RscExpType
43 public:
44 union
46 RscExpression * pExp;
47 RscDefine * pDef;
48 struct
50 short nHi;
51 unsigned short nLo;
52 } aLong;
53 } aExp;
54 char cType;
55 bool cUnused;
56 bool IsNumber() const { return( RSCEXP_LONG == cType ); }
57 bool IsExpression()const { return( RSCEXP_EXP == cType ); }
58 bool IsDefinition()const { return( RSCEXP_DEF == cType ); }
59 bool IsNothing() const { return( RSCEXP_NOTHING == cType ); }
60 void SetLong( sal_Int32 lValue )
62 aExp.aLong.nHi = (short)(lValue >> 16);
63 aExp.aLong.nLo = (unsigned short)lValue;
64 cType = RSCEXP_LONG;
66 sal_Int32 GetLong() const
68 return aExp.aLong.nLo |
69 ((sal_uInt32)aExp.aLong.nHi << 16);
71 bool Evaluate( sal_Int32 * pValue ) const;
72 void AppendMacro( OStringBuffer & ) const;
75 /*********** R s c I d ***************************************************/
76 class RscId
78 static bool bNames;// false, bei den Namenoperation nur Zahlen
79 public:
80 RscExpType aExp; // Zahl, Define oder Ausdruck
81 sal_Int32 GetNumber() const;
82 void Create( const RscExpType & rExpType );
83 void Create(){ aExp.cType = RSCEXP_NOTHING; }
85 RscId() { Create(); }
87 RscId( RscDefine * pEle );
88 RscId( sal_Int32 lNumber )
90 aExp.cUnused = false;
91 aExp.SetLong( lNumber );
94 RscId( const RscExpType & rExpType )
95 { Create( rExpType ); }
97 void Destroy();
99 ~RscId() { Destroy(); }
101 RscId( const RscId& rRscId );
103 RscId& operator = ( const RscId& rRscId );
105 static void SetNames( bool bSet = true );
106 operator sal_Int32() const; // Gibt Nummer zurueck
107 OString GetName() const; // Gibt den Namen des Defines zurueck
108 bool operator < ( const RscId& rRscId ) const;
109 bool operator > ( const RscId& rRscId ) const;
110 bool operator == ( const RscId& rRscId ) const;
111 bool operator <= ( const RscId& rRscId ) const
112 { return !(operator > ( rRscId )); }
113 bool operator >= ( const RscId& rRscId ) const
114 { return !(operator < ( rRscId )); }
115 bool IsId() const { return !aExp.IsNothing(); }
118 /*********** R s c D e f i n e *******************************************/
119 class RscDefine : public StringNode
121 friend class RscFileTab;
122 friend class RscDefineList;
123 friend class RscDefTree;
124 friend class RscExpression;
125 friend class RscId;
126 sal_uLong lFileKey; // zu welcher Datei gehoert das Define
127 sal_uInt32 nRefCount; // Wieviele Referenzen auf dieses Objekt
128 sal_Int32 lId; // Identifier
129 RscExpression * pExp; // Ausdruck
130 protected:
132 RscDefine( sal_uLong lFileKey, const OString& rDefName,
133 sal_Int32 lDefId );
134 RscDefine( sal_uLong lFileKey, const OString& rDefName,
135 RscExpression * pExpression );
136 virtual ~RscDefine();
137 void IncRef(){ nRefCount++; }
138 sal_uInt32 GetRefCount() const { return nRefCount; }
139 void DecRef();
140 void DefineToNumber();
141 void SetName(const OString& rNewName) { m_aName = rNewName; }
143 using StringNode::Search;
144 public:
145 RscDefine * Search( const char * );
146 sal_uLong GetFileKey() const { return lFileKey; }
147 bool Evaluate();
148 sal_Int32 GetNumber() const { return lId; }
149 OString GetMacro();
152 typedef ::std::vector< RscDefine* > RscSubDefList;
154 class RscDefineList
156 friend class RscFile;
157 friend class RscFileTab;
158 private:
159 RscSubDefList maList;
160 // pExpression wird auf jedenfall Eigentum der Liste
161 RscDefine * New( sal_uLong lFileKey, const OString& rDefName,
162 sal_Int32 lDefId, size_t lPos );
163 RscDefine * New( sal_uLong lFileKey, const OString& rDefName,
164 RscExpression * pExpression, size_t lPos );
165 bool Remove();
166 size_t GetPos( RscDefine* item )
168 for ( size_t i = 0, n = maList.size(); i < n; ++i )
169 if ( maList[ i ] == item )
170 return i;
171 return size_t(-1);
173 public:
174 void WriteAll( FILE * fOutput );
177 /*********** R s c E x p r e s s i o n ***********************************/
178 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( sal_Int32 * pValue );
189 OString GetMacro();
192 /********************** R S C F I L E ************************************/
193 class RscDepend
195 sal_uLong lKey;
196 public:
197 RscDepend( sal_uLong lIncKey ){ lKey = lIncKey; };
198 sal_uLong GetFileKey(){ return lKey; }
201 typedef ::std::vector< RscDepend* > RscDependList;
203 // Tabelle die alle Dateinamen enthaelt
204 class RscFile
206 friend class RscFileTab;
207 bool bIncFile; // Ist es eine Include-Datei
208 public:
209 bool bLoaded; // Ist die Datei geladen
210 bool bScanned; // Wurde Datei nach Inclide abgesucht
211 bool bDirty; // Dirty-Flag
212 OString aFileName; // Name der Datei
213 OString aPathName; // Pfad und Name der Datei
214 RscDefineList aDefLst; // Liste der Defines
215 RscDependList aDepLst; // List of Depend
217 RscFile();
218 ~RscFile();
219 bool InsertDependFile( sal_uLong lDepFile, size_t lPos );
220 bool Depend( sal_uLong lDepend, sal_uLong lFree );
221 void SetIncFlag(){ bIncFile = true; };
222 bool IsIncFile(){ return bIncFile; };
225 typedef UniqueIndex<RscFile> RscSubFileTab;
226 #define NOFILE_INDEX UNIQUEINDEX_ENTRY_NOTFOUND
228 class RscDefTree
230 RscDefine * pDefRoot;
231 public:
232 static bool Evaluate( RscDefine * pDef );
233 RscDefTree(){ pDefRoot = NULL; }
234 ~RscDefTree();
235 void Remove();
236 RscDefine * Search( const char * pName );
237 void Insert( RscDefine * pDef );
238 void Remove( RscDefine * pDef );
241 class RscFileTab : public RscSubFileTab
243 RscDefTree aDefTree;
244 sal_uLong Find(const OString& rName);
245 public:
246 RscFileTab();
247 ~RscFileTab();
249 RscDefine * FindDef( const char * );
250 RscDefine * FindDef(const OString& rStr)
252 return FindDef(rStr.getStr());
255 bool Depend( sal_uLong lDepend, sal_uLong lFree );
256 bool TestDef( sal_uLong lFileKey, size_t lPos,
257 const RscDefine * pDefDec );
258 bool TestDef( sal_uLong lFileKey, size_t lPos,
259 const RscExpression * pExpDec );
261 RscDefine * NewDef( sal_uLong lKey, const OString& rDefName,
262 sal_Int32 lId, sal_uLong lPos );
263 RscDefine * NewDef( sal_uLong lKey, const OString& rDefName,
264 RscExpression *, sal_uLong lPos );
266 // Alle Defines die in dieser Datei Definiert sind loeschen
267 void DeleteFileContext( sal_uLong lKey );
268 sal_uLong NewCodeFile(const OString& rName);
269 sal_uLong NewIncFile(const OString& rName, const OString& rPath);
270 RscFile * GetFile( sal_uLong lFileKey ){ return Get( lFileKey ); }
273 #endif // INCLUDED_RSC_INC_RSCDEF_HXX
275 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */