Debian Codegraph @

src/bin/geomutil/vrml2oogl/lib/QvSubField.h

raw
1 /* Copyright (C) 1992-1998 The Geometry Center
2 * Copyright (C) 1998-2000 Stuart Levy, Tamara Munzner, Mark Phillips
3 *
4 * This file is part of Geomview.
5 *
6 * Geomview is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * Geomview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Geomview; see the file COPYING. If not, write
18 * to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
19 * USA, or visit http://www.gnu.org.
20 */
21 #ifndef _QV_SUB_FIELD_
22 #define _QV_SUB_FIELD_
23
24 #include <stdlib.h>
25 #include <QvField.h>
26 #include <QvInput.h>
27
28 /////////////////////////////////////////////////////////////////////////////
29
30 #define QV_SFIELD_HEADER(className) \
31 public: \
32 className(); \
33 virtual ~className(); \
34 virtual QvBool readValue(QvInput *in)
35
36 /////////////////////////////////////////////////////////////////////////////
37
38 #define QV_MFIELD_HEADER(className) \
39 public: \
40 className(); \
41 virtual ~className(); \
42 virtual QvBool read1Value(QvInput *in, int index); \
43 void allocValues(int newNum); \
44 protected: \
45 static QvBool canUseMalloc
46
47 /////////////////////////////////////////////////////////////////////////////
48
49 #define QV_SFIELD_SOURCE(className) \
50 \
51 className::className() \
52 { \
53 } \
54 className::~className() \
55 { \
56 }
57
58 /////////////////////////////////////////////////////////////////////////////
59
60 // Note: field types whose values require constructors to be called
61 // should pass TRUE for valueHasConstructor. Otherwise, pass FALSE.
62
63 #ifdef __SUNPRO_CC
64 #define QV_MFIELD_SOURCE(className, valueType, numValues, valueHasConstructor)\
65 \
66 QvBool className::canUseMalloc; \
67 \
68 className::className() \
69 { \
70 canUseMalloc = ! valueHasConstructor; \
71 values = NULL; \
72 /* Make room for 1 value to start */ \
73 allocValues(1); \
74 } \
75 \
76 className::~className() \
77 { \
78 if (values != NULL) { \
79 if (canUseMalloc) \
80 free((char *) values); \
81 else \
82 delete [] values; \
83 } \
84 } \
85 \
86 void \
87 className::allocValues(int newNum) \
88 { \
89 if (values == NULL) { \
90 if (newNum > 0) { \
91 if (canUseMalloc) \
92 values = (valueType *) \
93 malloc(numValues * sizeof(valueType) * newNum); \
94 else \
95 values = new valueType[numValues * newNum]; \
96 } \
97 } \
98 else { \
99 if (newNum > 0) { \
100 if (canUseMalloc) \
101 values = (valueType *) \
102 realloc((malloc_t)values, numValues * sizeof(valueType) * newNum); \
103 else { \
104 valueType *oldValues = values; \
105 values = new valueType[numValues * newNum]; \
106 for (int i = 0; i < num && i < newNum; i++) \
107 values[i] = oldValues[i]; \
108 delete [] oldValues; \
109 } \
110 } \
111 else { \
112 if (canUseMalloc) \
113 free((char *) values); \
114 else \
115 delete [] values; \
116 values = NULL; \
117 } \
118 } \
119 num = maxNum = newNum; \
120 }
121 #else
122
123 #define QV_MFIELD_SOURCE(className, valueType, numValues, valueHasConstructor)\
124 \
125 QvBool className::canUseMalloc; \
126 \
127 className::className() \
128 { \
129 canUseMalloc = ! valueHasConstructor; \
130 values = NULL; \
131 /* Make room for 1 value to start */ \
132 allocValues(1); \
133 } \
134 \
135 className::~className() \
136 { \
137 if (values != NULL) { \
138 if (canUseMalloc) \
139 free((char *) values); \
140 else \
141 delete [] values; \
142 } \
143 } \
144 \
145 void \
146 className::allocValues(int newNum) \
147 { \
148 if (values == NULL) { \
149 if (newNum > 0) { \
150 if (canUseMalloc) \
151 values = (valueType *) \
152 malloc(numValues * sizeof(valueType) * newNum); \
153 else \
154 values = new valueType[numValues * newNum]; \
155 } \
156 } \
157 else { \
158 if (newNum > 0) { \
159 if (canUseMalloc) \
160 values = (valueType *) \
161 realloc(values, numValues * sizeof(valueType) * newNum); \
162 else { \
163 valueType *oldValues = values; \
164 values = new valueType[numValues * newNum]; \
165 for (int i = 0; i < num && i < newNum; i++) \
166 values[i] = oldValues[i]; \
167 delete [] oldValues; \
168 } \
169 } \
170 else { \
171 if (canUseMalloc) \
172 free((char *) values); \
173 else \
174 delete [] values; \
175 values = NULL; \
176 } \
177 } \
178 num = maxNum = newNum; \
179 }
180
181 #endif
182
183 #endif /* _QV_SUB_FIELD_ */