1#ifndef COIN_SOSUBFIELD_H
2#define COIN_SOSUBFIELD_H
27#include <Inventor/SbBasic.h>
28#include <Inventor/SbName.h>
33#include <Inventor/fields/SoField.h>
34#include <Inventor/SoInput.h>
35#include <Inventor/SoOutput.h>
44#define SO_FIELD_EXIT_CLASS(_class_) \
45 _class_::atexit_cleanup()
53#define SO_SFIELD_CONSTRUCTOR_HEADER(_class_) \
59#define SO_SFIELD_REQUIRED_HEADER(_class_) \
61 static SoType classTypeId; \
62 static void atexit_cleanup(void) { _class_::classTypeId STATIC_SOTYPE_INIT; } \
64 static void * createInstance(void); \
65 static SoType getClassTypeId(void); \
66 virtual SoType getTypeId(void) const; \
68 virtual void copyFrom(const SoField & field); \
69 const _class_ & operator=(const _class_ & field); \
70 virtual SbBool isSame(const SoField & field) const
73#define PRIVATE_SFIELD_IO_HEADER() \
75 virtual SbBool readValue(SoInput * in); \
76 virtual void writeValue(SoOutput * out) const
79#define SO_SFIELD_VALUE_HEADER(_class_, _valtype_, _valref_) \
80 PRIVATE_SFIELD_IO_HEADER(); \
85 _valref_ getValue(void) const { this->evaluate(); return this->value; } \
86 void setValue(_valref_ newvalue); \
87 _valref_ operator=(_valref_ newvalue) { this->setValue(newvalue); return this->value; } \
89 int operator==(const _class_ & field) const; \
90 int operator!=(const _class_ & field) const { return ! operator==(field); }
95#define SO_SFIELD_DERIVED_VALUE_HEADER(_class_, _valtype_, _valref_) \
96 PRIVATE_SFIELD_IO_HEADER(); \
98 _valref_ operator=(_valref_ newvalue) { this->setValue(newvalue); return this->value; }
102#define SO_SFIELD_HEADER(_class_, _valtype_, _valref_) \
103 SO_SFIELD_CONSTRUCTOR_HEADER(_class_); \
104 SO_SFIELD_REQUIRED_HEADER(_class_); \
105 SO_SFIELD_VALUE_HEADER(_class_, _valtype_, _valref_)
108#define SO_SFIELD_DERIVED_HEADER(_class_, _valtype_, _valref_) \
109 SO_SFIELD_CONSTRUCTOR_HEADER(_class_); \
110 SO_SFIELD_REQUIRED_HEADER(_class_); \
111 SO_SFIELD_DERIVED_VALUE_HEADER(_class_, _valtype_, _valref_)
121#define PRIVATE_FIELD_INIT_CLASS(_class_, _classname_, _parent_, _createfunc_) \
124 assert(_parent_::getClassTypeId() != SoType::badType()); \
126 assert(_class_::classTypeId == SoType::badType()); \
127 _class_::classTypeId = \
128 SoType::createType(_parent_::getClassTypeId(), _classname_, _createfunc_); \
133#define SO_SFIELD_INIT_CLASS(_class_, _parent_) \
135 const char * classname = SO__QUOTE(_class_); \
136 PRIVATE_FIELD_INIT_CLASS(_class_, classname, _parent_, &_class_::createInstance); \
139#define SO_SFIELD_CONSTRUCTOR_SOURCE(_class_) \
140_class_::_class_(void) { assert(_class_::classTypeId != SoType::badType()); } \
141_class_::~_class_() { }
145#define SO_SFIELD_VALUE_SOURCE(_class_, _valtype_, _valref_) \
147_class_::setValue(_valref_ valuearg) { \
148 this->value = valuearg; \
149 this->valueChanged(); \
153_class_::operator==(const _class_ & field) const \
155 return (this->getValue() == field.getValue()); \
159#define PRIVATE_TYPEID_SOURCE(_class_) \
160SoType _class_::getTypeId(void) const { return _class_::classTypeId; } \
161SoType _class_::getClassTypeId(void) { return _class_::classTypeId; } \
162void * _class_::createInstance(void) { return new _class_; } \
163SoType _class_::classTypeId STATIC_SOTYPE_INIT
166#define PRIVATE_EQUALITY_SOURCE(_class_) \
168_class_::copyFrom(const SoField & field) \
170 this->operator=((const _class_ &)field); \
174_class_::isSame(const SoField & field) const \
176 if (field.getTypeId() != this->getTypeId()) return FALSE; \
177 return this->operator==((const _class_ &) field); \
182#define SO_SFIELD_REQUIRED_SOURCE(_class_) \
183PRIVATE_TYPEID_SOURCE(_class_); \
184PRIVATE_EQUALITY_SOURCE(_class_); \
187_class_::operator=(const _class_ & field) \
189 this->setValue(field.getValue()); \
195#define SO_SFIELD_SOURCE(_class_, _valtype_, _valref_) \
196 SO_SFIELD_CONSTRUCTOR_SOURCE(_class_); \
197 SO_SFIELD_VALUE_SOURCE(_class_, _valtype_, _valref_); \
198 SO_SFIELD_REQUIRED_SOURCE(_class_)
202#define SO_SFIELD_DERIVED_SOURCE(_class_, _valtype_, _valref_) \
203 SO_SFIELD_CONSTRUCTOR_SOURCE(_class_); \
204 SO_SFIELD_REQUIRED_SOURCE(_class_)
213#define PRIVATE_MFIELD_IO_HEADER() \
215 virtual SbBool read1Value(SoInput * in, int idx); \
216 virtual void write1Value(SoOutput * out, int idx) const
220#define SO_MFIELD_VALUE_HEADER(_class_, _valtype_, _valref_) \
221 PRIVATE_MFIELD_IO_HEADER(); \
223 virtual void deleteAllValues(void); \
224 virtual void copyValue(int to, int from); \
225 virtual int fieldSizeof(void) const; \
226 virtual void * valuesPtr(void); \
227 virtual void setValuesPtr(void * ptr); \
228 virtual void allocValues(int num); \
230 _valtype_ * values; \
232 _valref_ operator[](const int idx) const \
233 { this->evaluate(); return this->values[idx]; } \
237 const _valtype_ * getValues(const int start) const \
238 { this->evaluate(); return (const _valtype_ *)(this->values + start); } \
239 int find(_valref_ value, SbBool addifnotfound = FALSE); \
240 void setValues(const int start, const int num, const _valtype_ * newvals); \
241 void set1Value(const int idx, _valref_ value); \
242 void setValue(_valref_ value); \
243 _valref_ operator=(_valref_ val) { this->setValue(val); return val; } \
244 SbBool operator==(const _class_ & field) const; \
245 SbBool operator!=(const _class_ & field) const { return !operator==(field); } \
246 _valtype_ * startEditing(void) { this->evaluate(); return this->values; } \
247 void finishEditing(void) { this->valueChanged(); }
249#define SO_MFIELD_DERIVED_VALUE_HEADER(_class_, _valtype_, _valref_) \
250 PRIVATE_MFIELD_IO_HEADER(); \
252 _valref_ operator=(_valref_ val) { this->setValue(val); return val; }
256#define SO_MFIELD_HEADER(_class_, _valtype_, _valref_) \
257 SO_SFIELD_CONSTRUCTOR_HEADER(_class_); \
258 SO_SFIELD_REQUIRED_HEADER(_class_); \
259 SO_MFIELD_VALUE_HEADER(_class_, _valtype_, _valref_)
263#define SO_MFIELD_DERIVED_HEADER(_class_, _valtype_, _valref_) \
264 SO_SFIELD_CONSTRUCTOR_HEADER(_class_); \
265 SO_SFIELD_REQUIRED_HEADER(_class_); \
266 SO_MFIELD_DERIVED_VALUE_HEADER(_class_, _valtype_, _valref_)
268#define SO_MFIELD_SETVALUESPOINTER_HEADER(_valtype_) \
269 void setValuesPointer(const int num, const _valtype_ * userdata); \
270 void setValuesPointer(const int num, _valtype_ * userdata)
280#define SO_MFIELD_INIT_CLASS(_class_, _parent_) \
281 SO_SFIELD_INIT_CLASS(_class_, _parent_)
285#define SO_MFIELD_CONSTRUCTOR_SOURCE(_class_) \
286_class_::_class_(void) \
288 assert(_class_::classTypeId != SoType::badType()); \
289 this->values = NULL; \
292_class_::~_class_(void) \
294 this->enableNotify(FALSE); \
295 this->deleteAllValues(); \
300#define SO_MFIELD_DERIVED_CONSTRUCTOR_SOURCE(_class_) \
301_class_::_class_(void) { } \
302_class_::~_class_(void) { }
306#define SO_MFIELD_REQUIRED_SOURCE(_class_) \
307PRIVATE_TYPEID_SOURCE(_class_); \
308PRIVATE_EQUALITY_SOURCE(_class_); \
310_class_::operator=(const _class_ & field) \
315 this->allocValues(field.getNum()); \
317 this->setValues(0, field.getNum(), field.getValues(0)); \
323#define SO_MFIELD_VALUE_SOURCE(_class_, _valtype_, _valref_) \
325_class_::fieldSizeof(void) const \
327 return sizeof(_valtype_); \
331_class_::valuesPtr(void) \
333 return (void *)this->values; \
337_class_::setValuesPtr(void * ptr) \
339 this->values = (_valtype_ *)ptr; \
343_class_::find(_valref_ value, SbBool addifnotfound) \
346 for (int i=0; i < this->num; i++) if (this->values[i] == value) return i; \
348 if (addifnotfound) this->set1Value(this->num, value); \
353_class_::setValues(const int start, const int numarg, const _valtype_ * newvals) \
355 if (start+numarg > this->maxNum) this->allocValues(start+numarg); \
356 else if (start+numarg > this->num) this->num = start+numarg; \
358 for (int i=0; i < numarg; i++) \
359 this->values[i+start] = (_valtype_) newvals[i]; \
360 this->valueChanged(); \
364_class_::set1Value(const int idx, _valref_ value) \
366 if (idx+1 > this->maxNum) this->allocValues(idx+1); \
367 else if (idx+1 > this->num) this->num = idx+1; \
368 this->values[idx] = value; \
369 this->valueChanged(); \
373_class_::setValue(_valref_ value) \
375 this->allocValues(1); \
376 this->values[0] = value; \
377 this->valueChanged(); \
381_class_::operator==(const _class_ & field) const \
383 if (this == &field) return TRUE; \
384 if (this->getNum() != field.getNum()) return FALSE; \
386 const _valtype_ * const lhs = this->getValues(0); \
387 const _valtype_ * const rhs = field.getValues(0); \
388 for (int i = 0; i < this->num; i++) if (lhs[i] != rhs[i]) return FALSE; \
394_class_::deleteAllValues(void) \
401_class_::copyValue(int to, int from) \
403 this->values[to] = this->values[from]; \
407#define SO_MFIELD_ALLOC_SOURCE(_class_, _valtype_) \
409_class_::allocValues(int newnum) \
419 _valtype_ * newblock; \
420 assert(newnum >= 0); \
423 if (!this->userDataIsUsed) delete[] this->values; \
424 this->setValuesPtr(NULL); \
426 this->userDataIsUsed = FALSE; \
428 else if (newnum > this->maxNum || newnum < this->num) { \
429 if (this->valuesPtr()) { \
438 oldmaxnum = this->maxNum; \
439 while (newnum > this->maxNum) this->maxNum *= 2; \
440 while ((this->maxNum / 2) >= newnum) this->maxNum /= 2; \
442 if (oldmaxnum != this->maxNum) { \
443 newblock = new _valtype_[this->maxNum]; \
444 this->userDataIsUsed = FALSE; \
446 for (i=0; i < SbMin(this->num, newnum); i++) \
447 newblock[i] = this->values[i]; \
449 delete[] this->values; \
450 this->setValuesPtr(newblock); \
454 this->setValuesPtr(new _valtype_[newnum]); \
455 this->userDataIsUsed = FALSE; \
456 this->maxNum = newnum; \
460 this->num = newnum; \
465#define SO_MFIELD_MALLOC_SOURCE(_class_, _valtype_) \
467_class_::allocValues(int number) \
469 SoMField::allocValues(number); \
474#define SO_MFIELD_SOURCE_MALLOC(_class_, _valtype_, _valref_) \
475 SO_MFIELD_REQUIRED_SOURCE(_class_); \
476 SO_MFIELD_CONSTRUCTOR_SOURCE(_class_); \
477 SO_MFIELD_MALLOC_SOURCE(_class_, _valtype_); \
478 SO_MFIELD_VALUE_SOURCE(_class_, _valtype_, _valref_)
482#define SO_MFIELD_SOURCE(_class_, _valtype_, _valref_) \
483 SO_MFIELD_REQUIRED_SOURCE(_class_); \
484 SO_MFIELD_CONSTRUCTOR_SOURCE(_class_); \
485 SO_MFIELD_ALLOC_SOURCE(_class_, _valtype_); \
486 SO_MFIELD_VALUE_SOURCE(_class_, _valtype_, _valref_)
489#define SO_MFIELD_DERIVED_SOURCE(_class_, _valtype_, _valref_) \
490 SO_MFIELD_REQUIRED_SOURCE(_class_); \
491 SO_MFIELD_DERIVED_CONSTRUCTOR_SOURCE(_class_)
493#define SO_MFIELD_SETVALUESPOINTER_SOURCE(_class_, _valtype_, _usertype_) \
495_class_::setValuesPointer(const int numarg, _usertype_ * userdata) \
498 if (numarg > 0 && userdata) { \
499 this->values = (_valtype_*) userdata; \
500 this->userDataIsUsed = TRUE; \
501 this->num = this->maxNum = numarg; \
502 this->valueChanged(); \
506_class_::setValuesPointer(const int numarg, const _usertype_ * userdata) \
508 this->setValuesPointer(numarg, (_usertype_*) userdata); \
Copyright © 1998-2007 by Systems in Motion AS. All rights reserved.
Generated on Thu Jan 16 2025 for Coin by Doxygen. 1.13.2