1 #ifndef COIN_SOSUBFIELD_H 2 #define COIN_SOSUBFIELD_H 27 #include <Inventor/SbBasic.h> 28 #include <Inventor/SbName.h> 29 #include <Inventor/C/tidbits.h> 34 #include <Inventor/fields/SoField.h> 35 #include <Inventor/SoInput.h> 36 #include <Inventor/SoOutput.h> 37 #endif // !COIN_INTERNAL 45 #define SO_SFIELD_CONSTRUCTOR_HEADER(_class_) \ 51 #define SO_SFIELD_REQUIRED_HEADER(_class_) \ 53 static SoType classTypeId; \ 54 static void atexit_cleanup(void) { SoType::removeType(_class_::classTypeId.getName()); _class_::classTypeId STATIC_SOTYPE_INIT; } \ 56 static void * createInstance(void); \ 57 static SoType getClassTypeId(void); \ 58 virtual SoType getTypeId(void) const; \ 60 virtual void copyFrom(const SoField & field); \ 61 const _class_ & operator=(const _class_ & field); \ 62 virtual SbBool isSame(const SoField & field) const 65 #define PRIVATE_SFIELD_IO_HEADER() \ 67 virtual SbBool readValue(SoInput * in); \ 68 virtual void writeValue(SoOutput * out) const 71 #define SO_SFIELD_VALUE_HEADER(_class_, _valtype_, _valref_) \ 72 PRIVATE_SFIELD_IO_HEADER(); \ 77 _valref_ getValue(void) const { this->evaluate(); return this->value; } \ 78 void setValue(_valref_ newvalue); \ 79 _valref_ operator=(_valref_ newvalue) { this->setValue(newvalue); return this->value; } \ 81 int operator==(const _class_ & field) const; \ 82 int operator!=(const _class_ & field) const { return ! operator==(field); } 87 #define SO_SFIELD_DERIVED_VALUE_HEADER(_class_, _valtype_, _valref_) \ 88 PRIVATE_SFIELD_IO_HEADER(); \ 90 _valref_ operator=(_valref_ newvalue) { this->setValue(newvalue); return this->value; } 94 #define SO_SFIELD_HEADER(_class_, _valtype_, _valref_) \ 95 SO_SFIELD_CONSTRUCTOR_HEADER(_class_); \ 96 SO_SFIELD_REQUIRED_HEADER(_class_); \ 97 SO_SFIELD_VALUE_HEADER(_class_, _valtype_, _valref_) 100 #define SO_SFIELD_DERIVED_HEADER(_class_, _valtype_, _valref_) \ 101 SO_SFIELD_CONSTRUCTOR_HEADER(_class_); \ 102 SO_SFIELD_REQUIRED_HEADER(_class_); \ 103 SO_SFIELD_DERIVED_VALUE_HEADER(_class_, _valtype_, _valref_) 113 #define PRIVATE_FIELD_INIT_CLASS(_class_, _classname_, _parent_, _createfunc_) \ 116 assert(_parent_::getClassTypeId() != SoType::badType()); \ 118 assert(_class_::classTypeId == SoType::badType()); \ 119 _class_::classTypeId = \ 120 SoType::createType(_parent_::getClassTypeId(), _classname_, _createfunc_); \ 121 cc_coin_atexit_static_internal \ 123 _class_::atexit_cleanup \ 129 #define SO_SFIELD_INIT_CLASS(_class_, _parent_) \ 131 const char * classname = SO__QUOTE(_class_); \ 132 PRIVATE_FIELD_INIT_CLASS(_class_, classname, _parent_, &_class_::createInstance); \ 135 #define SO_SFIELD_CONSTRUCTOR_SOURCE(_class_) \ 136 _class_::_class_(void) { assert(_class_::classTypeId != SoType::badType()); } \ 137 _class_::~_class_() { } 141 #define SO_SFIELD_VALUE_SOURCE(_class_, _valtype_, _valref_) \ 143 _class_::setValue(_valref_ valuearg) { \ 144 this->value = valuearg; \ 145 this->valueChanged(); \ 149 _class_::operator==(const _class_ & field) const \ 151 return (this->getValue() == field.getValue()); \ 155 #define PRIVATE_TYPEID_SOURCE(_class_) \ 156 SoType _class_::getTypeId(void) const { return _class_::classTypeId; } \ 157 SoType _class_::getClassTypeId(void) { return _class_::classTypeId; } \ 158 void * _class_::createInstance(void) { return new _class_; } \ 159 SoType _class_::classTypeId STATIC_SOTYPE_INIT 162 #define PRIVATE_EQUALITY_SOURCE(_class_) \ 164 _class_::copyFrom(const SoField & field) \ 166 this->operator=(static_cast<const _class_ &>(field)); \ 170 _class_::isSame(const SoField & field) const \ 172 if (field.getTypeId() != this->getTypeId()) return FALSE; \ 173 return this->operator==(static_cast<const _class_ &>(field)); \ 178 #define SO_SFIELD_REQUIRED_SOURCE(_class_) \ 179 PRIVATE_TYPEID_SOURCE(_class_); \ 180 PRIVATE_EQUALITY_SOURCE(_class_); \ 183 _class_::operator=(const _class_ & field) \ 185 this->setValue(field.getValue()); \ 191 #define SO_SFIELD_SOURCE(_class_, _valtype_, _valref_) \ 192 SO_SFIELD_CONSTRUCTOR_SOURCE(_class_); \ 193 SO_SFIELD_VALUE_SOURCE(_class_, _valtype_, _valref_); \ 194 SO_SFIELD_REQUIRED_SOURCE(_class_) 198 #define SO_SFIELD_DERIVED_SOURCE(_class_, _valtype_, _valref_) \ 199 SO_SFIELD_CONSTRUCTOR_SOURCE(_class_); \ 200 SO_SFIELD_REQUIRED_SOURCE(_class_) 209 #define PRIVATE_MFIELD_IO_HEADER() \ 211 virtual SbBool read1Value(SoInput * in, int idx); \ 212 virtual void write1Value(SoOutput * out, int idx) const 216 #define SO_MFIELD_VALUE_HEADER(_class_, _valtype_, _valref_) \ 217 PRIVATE_MFIELD_IO_HEADER(); \ 219 virtual void deleteAllValues(void); \ 220 virtual void copyValue(int to, int from); \ 221 virtual int fieldSizeof(void) const; \ 222 virtual void * valuesPtr(void); \ 223 virtual void setValuesPtr(void * ptr); \ 224 virtual void allocValues(int num); \ 226 _valtype_ * values; \ 228 _valref_ operator[](const int idx) const \ 229 { this->evaluate(); return this->values[idx]; } \ 233 const _valtype_ * getValues(const int start) const \ 234 { this->evaluate(); return const_cast<const _valtype_ *>(this->values + start); } \ 235 int find(_valref_ value, SbBool addifnotfound = FALSE); \ 236 void setValues(const int start, const int num, const _valtype_ * newvals); \ 237 void set1Value(const int idx, _valref_ value); \ 238 void setValue(_valref_ value); \ 239 _valref_ operator=(_valref_ val) { this->setValue(val); return val; } \ 240 SbBool operator==(const _class_ & field) const; \ 241 SbBool operator!=(const _class_ & field) const { return !operator==(field); } \ 242 _valtype_ * startEditing(void) { this->evaluate(); return this->values; } \ 243 void finishEditing(void) { this->valueChanged(); } 245 #define SO_MFIELD_DERIVED_VALUE_HEADER(_class_, _valtype_, _valref_) \ 246 PRIVATE_MFIELD_IO_HEADER(); \ 248 _valref_ operator=(_valref_ val) { this->setValue(val); return val; } 252 #define SO_MFIELD_HEADER(_class_, _valtype_, _valref_) \ 253 SO_SFIELD_CONSTRUCTOR_HEADER(_class_); \ 254 SO_SFIELD_REQUIRED_HEADER(_class_); \ 255 SO_MFIELD_VALUE_HEADER(_class_, _valtype_, _valref_) 259 #define SO_MFIELD_DERIVED_HEADER(_class_, _valtype_, _valref_) \ 260 SO_SFIELD_CONSTRUCTOR_HEADER(_class_); \ 261 SO_SFIELD_REQUIRED_HEADER(_class_); \ 262 SO_MFIELD_DERIVED_VALUE_HEADER(_class_, _valtype_, _valref_) 264 #define SO_MFIELD_SETVALUESPOINTER_HEADER(_valtype_) \ 265 void setValuesPointer(const int num, const _valtype_ * userdata); \ 266 void setValuesPointer(const int num, _valtype_ * userdata) 276 #define SO_MFIELD_INIT_CLASS(_class_, _parent_) \ 277 SO_SFIELD_INIT_CLASS(_class_, _parent_) 281 #define SO_MFIELD_CONSTRUCTOR_SOURCE(_class_) \ 282 _class_::_class_(void) \ 284 assert(_class_::classTypeId != SoType::badType()); \ 285 this->values = NULL; \ 288 _class_::~_class_(void) \ 290 this->enableNotify(FALSE); \ 291 this->deleteAllValues(); \ 296 #define SO_MFIELD_DERIVED_CONSTRUCTOR_SOURCE(_class_) \ 297 _class_::_class_(void) { } \ 298 _class_::~_class_(void) { } 302 #define SO_MFIELD_REQUIRED_SOURCE(_class_) \ 303 PRIVATE_TYPEID_SOURCE(_class_); \ 304 PRIVATE_EQUALITY_SOURCE(_class_); \ 306 _class_::operator=(const _class_ & field) \ 311 this->allocValues(field.getNum()); \ 313 this->setValues(0, field.getNum(), field.getValues(0)); \ 319 #define SO_MFIELD_VALUE_SOURCE(_class_, _valtype_, _valref_) \ 321 _class_::fieldSizeof(void) const \ 323 return sizeof(_valtype_); \ 327 _class_::valuesPtr(void) \ 329 return static_cast<void *>(this->values); \ 333 _class_::setValuesPtr(void * ptr) \ 335 this->values = static_cast<_valtype_ *>(ptr); \ 339 _class_::find(_valref_ value, SbBool addifnotfound) \ 342 for (int i=0; i < this->num; i++) if (this->values[i] == value) return i; \ 344 if (addifnotfound) this->set1Value(this->num, value); \ 349 _class_::setValues(const int start, const int numarg, const _valtype_ * newvals) \ 351 if (start+numarg > this->maxNum) this->allocValues(start+numarg); \ 352 else if (start+numarg > this->num) this->num = start+numarg; \ 354 for (int i=0; i < numarg; i++) \ 355 this->values[i+start] = static_cast<_valtype_>(newvals[i]); \ 356 this->valueChanged(); \ 360 _class_::set1Value(const int idx, _valref_ value) \ 362 if (idx+1 > this->maxNum) this->allocValues(idx+1); \ 363 else if (idx+1 > this->num) this->num = idx+1; \ 364 this->values[idx] = value; \ 365 this->valueChanged(); \ 369 _class_::setValue(_valref_ value) \ 371 this->allocValues(1); \ 372 this->values[0] = value; \ 373 this->valueChanged(); \ 377 _class_::operator==(const _class_ & field) const \ 379 if (this == &field) return TRUE; \ 380 if (this->getNum() != field.getNum()) return FALSE; \ 382 const _valtype_ * const lhs = this->getValues(0); \ 383 const _valtype_ * const rhs = field.getValues(0); \ 384 for (int i = 0; i < this->num; i++) if (lhs[i] != rhs[i]) return FALSE; \ 390 _class_::deleteAllValues(void) \ 397 _class_::copyValue(int to, int from) \ 399 this->values[to] = this->values[from]; \ 403 #define SO_MFIELD_ALLOC_SOURCE(_class_, _valtype_) \ 405 _class_::allocValues(int newnum) \ 415 _valtype_ * newblock; \ 416 assert(newnum >= 0); \ 419 if (!this->userDataIsUsed) delete[] this->values; \ 420 this->setValuesPtr(NULL); \ 422 this->userDataIsUsed = FALSE; \ 424 else if (newnum > this->maxNum || newnum < this->num) { \ 425 if (this->valuesPtr()) { \ 434 oldmaxnum = this->maxNum; \ 435 while (newnum > this->maxNum) this->maxNum *= 2; \ 436 while ((this->maxNum / 2) >= newnum) this->maxNum /= 2; \ 438 if (oldmaxnum != this->maxNum) { \ 439 newblock = new _valtype_[this->maxNum]; \ 441 for (i=0; i < SbMin(this->num, newnum); i++) \ 442 newblock[i] = this->values[i]; \ 444 delete[] this->values; \ 445 this->setValuesPtr(newblock); \ 446 this->userDataIsUsed = FALSE; \ 450 this->setValuesPtr(new _valtype_[newnum]); \ 451 this->userDataIsUsed = FALSE; \ 452 this->maxNum = newnum; \ 456 this->num = newnum; \ 461 #define SO_MFIELD_MALLOC_SOURCE(_class_, _valtype_) \ 463 _class_::allocValues(int number) \ 465 SoMField::allocValues(number); \ 470 #define SO_MFIELD_SOURCE_MALLOC(_class_, _valtype_, _valref_) \ 471 SO_MFIELD_REQUIRED_SOURCE(_class_); \ 472 SO_MFIELD_CONSTRUCTOR_SOURCE(_class_); \ 473 SO_MFIELD_MALLOC_SOURCE(_class_, _valtype_); \ 474 SO_MFIELD_VALUE_SOURCE(_class_, _valtype_, _valref_) 478 #define SO_MFIELD_SOURCE(_class_, _valtype_, _valref_) \ 479 SO_MFIELD_REQUIRED_SOURCE(_class_); \ 480 SO_MFIELD_CONSTRUCTOR_SOURCE(_class_); \ 481 SO_MFIELD_ALLOC_SOURCE(_class_, _valtype_); \ 482 SO_MFIELD_VALUE_SOURCE(_class_, _valtype_, _valref_) 485 #define SO_MFIELD_DERIVED_SOURCE(_class_, _valtype_, _valref_) \ 486 SO_MFIELD_REQUIRED_SOURCE(_class_); \ 487 SO_MFIELD_DERIVED_CONSTRUCTOR_SOURCE(_class_) 489 #define SO_MFIELD_SETVALUESPOINTER_SOURCE(_class_, _valtype_, _usertype_) \ 491 _class_::setValuesPointer(const int numarg, _usertype_ * userdata) \ 494 if (numarg > 0 && userdata) { \ 495 this->values = reinterpret_cast<_valtype_*>(userdata); \ 496 this->userDataIsUsed = TRUE; \ 497 this->num = this->maxNum = numarg; \ 498 this->valueChanged(); \ 502 _class_::setValuesPointer(const int numarg, const _usertype_ * userdata) \ 504 this->setValuesPointer(numarg, const_cast<_usertype_*>(userdata)); \ 507 #endif // !COIN_SOSUBFIELD_H
Copyright © 1998-2010 by Kongsberg Oil & Gas Technologies. All rights reserved.
Generated on Wed Feb 7 2018 for Coin by Doxygen 1.8.14.