2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
12 * The Original Code is the Sablotron XSLT Processor.
14 * The Initial Developer of the Original Code is Ginger Alliance Ltd.
15 * Portions created by Ginger Alliance are Copyright (C) 2000-2002
16 * Ginger Alliance Ltd. All Rights Reserved.
20 * Alternatively, the contents of this file may be used under the
21 * terms of the GNU General Public License Version 2 or later (the
22 * "GPL"), in which case the provisions of the GPL are applicable
23 * instead of those above. If you wish to allow use of your
24 * version of this file only under the terms of the GPL and not to
25 * allow others to use your version of this file under the MPL,
26 * indicate your decision by deleting the provisions above and
27 * replace them with the notice and other provisions required by
28 * the GPL. If you do not delete the provisions above, a recipient
29 * may use your version of this file under either the MPL or the
40 * macro definitions for guarded pointers
41 * (i.e. pointers that automatically get deallocated on exit from a function)
46 * DeclGuard(T) declares a class for use in place of T*
47 * [use DeclArrGuard for pointers to arrays!]
50 * keep() forgets about the allocation so the block is preserved
51 * del() deallocates the block explicitly
52 * delArray() deallocates the array explicitly
53 * operator() returns the pointer, for use in v() -> item
54 * cast to T* returns the pointer
55 * operator[] behaves as if used with the pointer
56 * operator* behaves as if used with the pointer
57 * operator= behaves as if used with the pointer
60 #define DeclGuard( TYPE ) \
64 TYPE##_G(TYPE *ptr_ = NULL): ptr(ptr_), kill(TRUE) {} \
65 TYPE* keep() {kill = FALSE; return ptr;} \
66 TYPE* unkeep() {kill = TRUE; return ptr;} \
67 void assign(TYPE* ptr_) {kill = FALSE; ptr = ptr_;} \
68 TYPE* operator= (TYPE *ptr_) {kill = ptr_? TRUE : FALSE; return ptr = ptr_;} \
69 operator TYPE*&() {return ptr;} \
70 TYPE& operator*(void) {assert(ptr); return *ptr;} \
71 TYPE* operator()(void) {return ptr;} \
72 void del(void) {if (ptr) delete ptr; ptr = NULL; kill = FALSE;} \
73 void delArray(void) {if (ptr) delete[] ptr; ptr = NULL; kill = FALSE;} \
74 ~TYPE##_G() {if (kill) del();} \
81 * DeclArrGuard(T) - as above, for pointers pointing to an array
84 #define DeclArrGuard( TYPE ) \
85 class TYPE##_ArrG: public TYPE##_G \
88 TYPE##_ArrG(TYPE *ptr_ = NULL): TYPE##_G(ptr_) {} \
89 ~TYPE##_ArrG() {if (kill) delArray();} \
90 TYPE& operator [](long nIndex_) { return ptr[nIndex_]; } \
94 * DeclDelGuard(T) - for autodeleting lists (automatic freeall(FALSE))
97 #define DeclDelGuard( TYPE ) \
98 class TYPE##_DelG: public TYPE##_G \
101 TYPE##_DelG(TYPE *ptr_ = NULL): TYPE##_G(ptr_), autoDel(FALSE) {} \
102 ~TYPE##_DelG() {if (kill) { if (autoDel && ptr) ptr -> freeall(FALSE); del();}} \
103 TYPE* keep() {autoDel = FALSE; return TYPE##_G::keep();} \
104 void autodelete() {autoDel = TRUE;}\
112 * GP() declares an actual guarded pointer,
119 #define GP( TYPE ) TYPE##_G
122 * GPA() declares a guarded pointer pointing to an array
125 #define GPA( TYPE ) TYPE##_ArrG
128 * GPD() declares a guarded pointer pointing to an autodeleting list
131 #define GPD( TYPE ) TYPE##_DelG
144 #include "encoding.h"
147 DeclGuard(Processor);
148 DeclGuard(Expression);
154 typedef const char* ConstCharP;
155 DeclGuard(ConstCharP);
156 typedef char GChar; //guarded character
158 DeclGuard(OutputHistoryItem);
163 DeclGuard(OutputterObj);
164 DeclGuard(OutputDefinition);
165 DeclGuard(OutputDocument);
166 DeclGuard(TreeConstructer);
167 DeclArrGuard(ConstCharP);
169 DeclDelGuard(ExprList);
172 #endif // ifndef GuardHIncl