1 #ifndef COIN_SOSUBFIELD_H
2 #define COIN_SOSUBFIELD_H
36 #include <Inventor/SbBasic.h>
37 #include <Inventor/SbName.h>
43 #include <Inventor/fields/SoField.h>
44 #include <Inventor/SoInput.h>
46 #endif // !COIN_INTERNAL
54 #define SO_SFIELD_CONSTRUCTOR_HEADER(_class_) \
60 #define SO_SFIELD_REQUIRED_HEADER(_class_) \
62 static SoType classTypeId; \
63 static void atexit_cleanup(void) { SoType::removeType(_class_::classTypeId.getName()); _class_::classTypeId STATIC_SOTYPE_INIT; } \
65 static void * createInstance(void); \
66 static SoType getClassTypeId(void); \
67 virtual SoType getTypeId(void) const; \
69 virtual void copyFrom(const SoField & field); \
70 const _class_ & operator=(const _class_ & field); \
71 virtual SbBool isSame(const SoField & field) const
74 #define PRIVATE_SFIELD_IO_HEADER() \
76 virtual SbBool readValue(SoInput * in); \
77 virtual void writeValue(SoOutput * out) const
80 #define SO_SFIELD_VALUE_HEADER(_class_, _valtype_, _valref_) \
81 PRIVATE_SFIELD_IO_HEADER(); \
86 _valref_ getValue(void) const { this->evaluate(); return this->value; } \
87 void setValue(_valref_ newvalue); \
88 _valref_ operator=(_valref_ newvalue) { this->setValue(newvalue); return this->value; } \
90 int operator==(const _class_ & field) const; \
91 int operator!=(const _class_ & field) const { return ! operator==(field); }
96 #define SO_SFIELD_DERIVED_VALUE_HEADER(_class_, _valtype_, _valref_) \
97 PRIVATE_SFIELD_IO_HEADER(); \
99 _valref_ operator=(_valref_ newvalue) { this->setValue(newvalue); return this->value; }
103 #define SO_SFIELD_HEADER(_class_, _valtype_, _valref_) \
104 SO_SFIELD_CONSTRUCTOR_HEADER(_class_); \
105 SO_SFIELD_REQUIRED_HEADER(_class_); \
106 SO_SFIELD_VALUE_HEADER(_class_, _valtype_, _valref_)
109 #define SO_SFIELD_DERIVED_HEADER(_class_, _valtype_, _valref_) \
110 SO_SFIELD_CONSTRUCTOR_HEADER(_class_); \
111 SO_SFIELD_REQUIRED_HEADER(_class_); \
112 SO_SFIELD_DERIVED_VALUE_HEADER(_class_, _valtype_, _valref_)
122 #define PRIVATE_FIELD_INIT_CLASS(_class_, _classname_, _parent_, _createfunc_) \
125 assert(_parent_::getClassTypeId() != SoType::badType()); \
127 assert(_class_::classTypeId == SoType::badType()); \
128 _class_::classTypeId = \
129 SoType::createType(_parent_::getClassTypeId(), _classname_, _createfunc_); \
130 cc_coin_atexit_static_internal \
132 _class_::atexit_cleanup \
138 #define SO_SFIELD_INIT_CLASS(_class_, _parent_) \
140 const char * classname = SO__QUOTE(_class_); \
141 PRIVATE_FIELD_INIT_CLASS(_class_, classname, _parent_, &_class_::createInstance); \
144 #define SO_SFIELD_CONSTRUCTOR_SOURCE(_class_) \
145 _class_::_class_(void) { assert(_class_::classTypeId != SoType::badType()); } \
146 _class_::~_class_() { }
150 #define SO_SFIELD_VALUE_SOURCE(_class_, _valtype_, _valref_) \
152 _class_::setValue(_valref_ valuearg) { \
153 this->value = valuearg; \
154 this->valueChanged(); \
158 _class_::operator==(const _class_ & field) const \
160 return (this->getValue() == field.getValue()); \
164 #define PRIVATE_TYPEID_SOURCE(_class_) \
165 SoType _class_::getTypeId(void) const { return _class_::classTypeId; } \
166 SoType _class_::getClassTypeId(void) { return _class_::classTypeId; } \
167 void * _class_::createInstance(void) { return new _class_; } \
168 SoType _class_::classTypeId STATIC_SOTYPE_INIT
171 #define PRIVATE_EQUALITY_SOURCE(_class_) \
173 _class_::copyFrom(const SoField & field) \
175 this->operator=(static_cast<const _class_ &>(field)); \
179 _class_::isSame(const SoField & field) const \
181 if (field.getTypeId() != this->getTypeId()) return FALSE; \
182 return this->operator==(static_cast<const _class_ &>(field)); \
187 #define SO_SFIELD_REQUIRED_SOURCE(_class_) \
188 PRIVATE_TYPEID_SOURCE(_class_); \
189 PRIVATE_EQUALITY_SOURCE(_class_); \
192 _class_::operator=(const _class_ & field) \
194 this->setValue(field.getValue()); \
200 #define SO_SFIELD_SOURCE(_class_, _valtype_, _valref_) \
201 SO_SFIELD_CONSTRUCTOR_SOURCE(_class_); \
202 SO_SFIELD_VALUE_SOURCE(_class_, _valtype_, _valref_); \
203 SO_SFIELD_REQUIRED_SOURCE(_class_)
207 #define SO_SFIELD_DERIVED_SOURCE(_class_, _valtype_, _valref_) \
208 SO_SFIELD_CONSTRUCTOR_SOURCE(_class_); \
209 SO_SFIELD_REQUIRED_SOURCE(_class_)
218 #define PRIVATE_MFIELD_IO_HEADER() \
220 virtual SbBool read1Value(SoInput * in, int idx); \
221 virtual void write1Value(SoOutput * out, int idx) const
225 #define SO_MFIELD_VALUE_HEADER(_class_, _valtype_, _valref_) \
226 PRIVATE_MFIELD_IO_HEADER(); \
228 virtual void deleteAllValues(void); \
229 virtual void copyValue(int to, int from); \
230 virtual int fieldSizeof(void) const; \
231 virtual void * valuesPtr(void); \
232 virtual void setValuesPtr(void * ptr); \
233 virtual void allocValues(int num); \
235 _valtype_ * values; \
237 _valref_ operator[](const int idx) const \
238 { this->evaluate(); return this->values[idx]; } \
242 const _valtype_ * getValues(const int start) const \
243 { this->evaluate(); return const_cast<const _valtype_ *>(this->values + start); } \
244 int find(_valref_ value, SbBool addifnotfound = FALSE); \
245 void setValues(const int start, const int num, const _valtype_ * newvals); \
246 void set1Value(const int idx, _valref_ value); \
247 void setValue(_valref_ value); \
248 _valref_ operator=(_valref_ val) { this->setValue(val); return val; } \
249 SbBool operator==(const _class_ & field) const; \
250 SbBool operator!=(const _class_ & field) const { return !operator==(field); } \
251 _valtype_ * startEditing(void) { this->evaluate(); return this->values; } \
252 void finishEditing(void) { this->valueChanged(); }
254 #define SO_MFIELD_DERIVED_VALUE_HEADER(_class_, _valtype_, _valref_) \
255 PRIVATE_MFIELD_IO_HEADER(); \
257 _valref_ operator=(_valref_ val) { this->setValue(val); return val; }
261 #define SO_MFIELD_HEADER(_class_, _valtype_, _valref_) \
262 SO_SFIELD_CONSTRUCTOR_HEADER(_class_); \
263 SO_SFIELD_REQUIRED_HEADER(_class_); \
264 SO_MFIELD_VALUE_HEADER(_class_, _valtype_, _valref_)
268 #define SO_MFIELD_DERIVED_HEADER(_class_, _valtype_, _valref_) \
269 SO_SFIELD_CONSTRUCTOR_HEADER(_class_); \
270 SO_SFIELD_REQUIRED_HEADER(_class_); \
271 SO_MFIELD_DERIVED_VALUE_HEADER(_class_, _valtype_, _valref_)
273 #define SO_MFIELD_SETVALUESPOINTER_HEADER(_valtype_) \
274 void setValuesPointer(const int num, const _valtype_ * userdata); \
275 void setValuesPointer(const int num, _valtype_ * userdata)
285 #define SO_MFIELD_INIT_CLASS(_class_, _parent_) \
286 SO_SFIELD_INIT_CLASS(_class_, _parent_)
290 #define SO_MFIELD_CONSTRUCTOR_SOURCE(_class_) \
291 _class_::_class_(void) \
293 assert(_class_::classTypeId != SoType::badType()); \
294 this->values = NULL; \
297 _class_::~_class_(void) \
299 this->enableNotify(FALSE); \
300 this->deleteAllValues(); \
305 #define SO_MFIELD_DERIVED_CONSTRUCTOR_SOURCE(_class_) \
306 _class_::_class_(void) { } \
307 _class_::~_class_(void) { }
311 #define SO_MFIELD_REQUIRED_SOURCE(_class_) \
312 PRIVATE_TYPEID_SOURCE(_class_); \
313 PRIVATE_EQUALITY_SOURCE(_class_); \
315 _class_::operator=(const _class_ & field) \
320 this->allocValues(field.getNum()); \
322 this->setValues(0, field.getNum(), field.getValues(0)); \
328 #define SO_MFIELD_VALUE_SOURCE(_class_, _valtype_, _valref_) \
330 _class_::fieldSizeof(void) const \
332 return sizeof(_valtype_); \
336 _class_::valuesPtr(void) \
338 return static_cast<void *>(this->values); \
342 _class_::setValuesPtr(void * ptr) \
344 this->values = static_cast<_valtype_ *>(ptr); \
348 _class_::find(_valref_ value, SbBool addifnotfound) \
351 for (int i=0; i < this->num; i++) if (this->values[i] == value) return i; \
353 if (addifnotfound) this->set1Value(this->num, value); \
358 _class_::setValues(const int start, const int numarg, const _valtype_ * newvals) \
360 if (start+numarg > this->maxNum) this->allocValues(start+numarg); \
361 else if (start+numarg > this->num) this->num = start+numarg; \
363 for (int i=0; i < numarg; i++) \
364 this->values[i+start] = static_cast<const _valtype_>(newvals[i]); \
365 this->setChangedIndices(start, numarg); \
366 this->valueChanged(); \
367 this->setChangedIndices(); \
371 _class_::set1Value(const int idx, _valref_ value) \
373 if (idx+1 > this->maxNum) this->allocValues(idx+1); \
374 else if (idx+1 > this->num) this->num = idx+1; \
375 this->values[idx] = value; \
376 this->setChangedIndex(idx); \
377 this->valueChanged(); \
378 this->setChangedIndices(); \
382 _class_::setValue(_valref_ value) \
384 this->allocValues(1); \
385 this->values[0] = value; \
386 this->setChangedIndex(0); \
387 this->valueChanged(); \
388 this->setChangedIndices(); \
392 _class_::operator==(const _class_ & field) const \
394 if (this == &field) return TRUE; \
395 if (this->getNum() != field.getNum()) return FALSE; \
397 const _valtype_ * const lhs = this->getValues(0); \
398 const _valtype_ * const rhs = field.getValues(0); \
399 for (int i = 0; i < this->num; i++) if (lhs[i] != rhs[i]) return FALSE; \
405 _class_::deleteAllValues(void) \
412 _class_::copyValue(int to, int from) \
414 this->values[to] = this->values[from]; \
418 #define SO_MFIELD_ALLOC_SOURCE(_class_, _valtype_) \
420 _class_::allocValues(int newnum) \
430 _valtype_ * newblock; \
431 assert(newnum >= 0); \
433 this->setChangedIndices(); \
435 if (!this->userDataIsUsed) delete[] this->values; \
436 this->setValuesPtr(NULL); \
438 this->userDataIsUsed = FALSE; \
440 else if (newnum > this->maxNum || newnum < this->num) { \
441 if (this->valuesPtr()) { \
450 oldmaxnum = this->maxNum; \
451 while (newnum > this->maxNum) this->maxNum *= 2; \
452 while ((this->maxNum / 2) >= newnum) this->maxNum /= 2; \
454 if (oldmaxnum != this->maxNum) { \
455 newblock = new _valtype_[this->maxNum]; \
457 for (i=0; i < SbMin(this->num, newnum); i++) \
458 newblock[i] = this->values[i]; \
460 delete[] this->values; \
461 this->setValuesPtr(newblock); \
462 this->userDataIsUsed = FALSE; \
466 this->setValuesPtr(new _valtype_[newnum]); \
467 this->userDataIsUsed = FALSE; \
468 this->maxNum = newnum; \
472 this->num = newnum; \
477 #define SO_MFIELD_MALLOC_SOURCE(_class_, _valtype_) \
479 _class_::allocValues(int number) \
481 SoMField::allocValues(number); \
486 #define SO_MFIELD_SOURCE_MALLOC(_class_, _valtype_, _valref_) \
487 SO_MFIELD_REQUIRED_SOURCE(_class_); \
488 SO_MFIELD_CONSTRUCTOR_SOURCE(_class_); \
489 SO_MFIELD_MALLOC_SOURCE(_class_, _valtype_); \
490 SO_MFIELD_VALUE_SOURCE(_class_, _valtype_, _valref_)
494 #define SO_MFIELD_SOURCE(_class_, _valtype_, _valref_) \
495 SO_MFIELD_REQUIRED_SOURCE(_class_); \
496 SO_MFIELD_CONSTRUCTOR_SOURCE(_class_); \
497 SO_MFIELD_ALLOC_SOURCE(_class_, _valtype_); \
498 SO_MFIELD_VALUE_SOURCE(_class_, _valtype_, _valref_)
501 #define SO_MFIELD_DERIVED_SOURCE(_class_, _valtype_, _valref_) \
502 SO_MFIELD_REQUIRED_SOURCE(_class_); \
503 SO_MFIELD_DERIVED_CONSTRUCTOR_SOURCE(_class_)
505 #define SO_MFIELD_SETVALUESPOINTER_SOURCE(_class_, _valtype_, _usertype_) \
507 _class_::setValuesPointer(const int numarg, _usertype_ * userdata) \
510 if (numarg > 0 && userdata) { \
511 this->values = reinterpret_cast<_valtype_*>(userdata); \
512 this->userDataIsUsed = TRUE; \
513 this->num = this->maxNum = numarg; \
514 this->valueChanged(); \
518 _class_::setValuesPointer(const int numarg, const _usertype_ * userdata) \
520 this->setValuesPointer(numarg, const_cast<_usertype_*>(userdata)); \
523 #endif // !COIN_SOSUBFIELD_H
Copyright © by Kongsberg Oil & Gas Technologies. All rights reserved.
Generated for Coin by Doxygen