1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <tools/unqidx.hxx>
23 #include <rsctree.hxx>
24 #include <rtl/strbuf.hxx>
27 /****************** C L A S S E S ****************************************/
32 /*********** R s c E x p r e s s i o n ***********************************/
36 #define RSCEXP_NOTHING 3
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
;
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 ***************************************************/
75 static bool bNames
;// false, bei den Namenoperation nur Zahlen
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
; }
84 RscId( RscDefine
* pEle
);
85 RscId( sal_Int32 lNumber
)
86 { aExp
.SetLong( lNumber
); }
88 RscId( const RscExpType
& rExpType
)
89 { Create( rExpType
); }
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
;
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
126 RscDefine( sal_uLong lFileKey
, const OString
& rDefName
,
128 RscDefine( sal_uLong lFileKey
, const OString
& rDefName
,
129 RscExpression
* pExpression
);
131 void IncRef(){ nRefCount
++; }
132 sal_uInt32
GetRefCount() const { return nRefCount
; }
134 void DefineToNumber();
135 void SetName(const OString
& rNewName
) { m_aName
= rNewName
; }
137 using StringNode::Search
;
139 RscDefine
* Search( const char * );
140 sal_uLong
GetFileKey() const { return lFileKey
; }
142 sal_Int32
GetNumber() const { return lId
; }
146 typedef ::std::vector
< RscDefine
* > RscSubDefList
;
150 friend class RscFile
;
151 friend class RscFileTab
;
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
);
160 size_t GetPos( RscDefine
* item
)
162 for ( size_t i
= 0, n
= maList
.size(); i
< n
; ++i
)
163 if ( maList
[ i
] == item
)
168 void WriteAll( FILE * fOutput
);
171 /*********** R s c E x p r e s s i o n ***********************************/
174 friend class RscFileTab
;
177 RscExpType aRightExp
;
179 RscExpression( RscExpType aLE
, char cOp
,
182 bool Evaluate( sal_Int32
* pValue
);
186 /********************** R S C F I L E ************************************/
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
200 friend class RscFileTab
;
201 bool bIncFile
; // Ist es eine Include-Datei
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
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
224 RscDefine
* pDefRoot
;
226 static bool Evaluate( RscDefine
* pDef
);
227 RscDefTree(){ pDefRoot
= NULL
; }
230 RscDefine
* Search( const char * pName
);
231 void Insert( RscDefine
* pDef
);
232 void Remove( RscDefine
* pDef
);
235 class RscFileTab
: public RscSubFileTab
238 sal_uLong
Find(const OString
& rName
);
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: */