1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799
|
/*
*
* Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* Further, this software is distributed without any warranty that it is
* free of the rightful claim of any third person regarding infringement
* or the like. Any license provided herein, whether implied or
* otherwise, applies only to this software file. Patent licenses, if
* any, provided herein do not apply to combinations of this program with
* other software, or any other product whatsoever.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
* Mountain View, CA 94043, or:
*
* http://www.sgi.com
*
* For further information regarding this notice, see:
*
* http://oss.sgi.com/projects/GenInfo/NoticeExplan/
*
*/
// -*- C++ -*-
/*
* Copyright (C) 1990,91 Silicon Graphics, Inc.
*
_______________________________________________________________________
______________ S I L I C O N G R A P H I C S I N C . ____________
|
| $Revision: 1.1.1.1 $
|
| Description:
| This file defines some macros that implement things common to
| many subclasses of SoField (actually, subclasses of SoSField
| and SoMField). They may be used to make subclassing easier.
| In the macros, the following parameters are used consistently:
|
| className = name of new field subclass
|
| valueType = type of field value (e.g., float, SbVec3f)
|
| valueRef = type of field value that can be passed or
| returned. For simple types like float or
| int, it is the same as valueType. For
| aggregates such as SbVec3f, use a const
| reference, e.g.: const SbVec3f &
|
| Macros for single-value (SoSField) field subclasses:
|
| Within class header:
|
| SO_SFIELD_REQUIRED_HEADER()
| SO_SFIELD_CONSTRUCTOR_HEADER()
| SO_SFIELD_VALUE_HEADER()
| SO_SFIELD_DERIVED_VALUE_HEADER()
|
| SO_SFIELD_HEADER()
| [includes REQUIRED, CONSTRUCTOR, and VALUE]
| SO_SFIELD_DERIVED_HEADER()
| [includes REQUIRED, CONSTRUCTOR, and DERIVED_VALUE]
|
| Within class source:
|
| SO_SFIELD_INIT_CLASS()
| SO_SFIELD_REQUIRED_SOURCE()
| SO_SFIELD_CONSTRUCTOR_SOURCE()
| SO_SFIELD_VALUE_SOURCE()
|
| SO_SFIELD_SOURCE()
| [includes REQUIRED, CONSTRUCTOR, and VALUE]
| SO_SFIELD_DERIVED_SOURCE()
| [includes REQUIRED and CONSTRUCTOR]
|
| Macros for multiple-value (SoMField) field subclasses:
|
| Within class header:
|
| SO_MFIELD_REQUIRED_HEADER()
| SO_MFIELD_CONSTRUCTOR_HEADER()
| SO_MFIELD_VALUE_HEADER()
| SO_MFIELD_DERIVED_VALUE_HEADER()
|
| SO_MFIELD_HEADER()
| [includes REQUIRED, CONSTRUCTOR, and VALUE]
| SO_MFIELD_DERIVED_HEADER()
| [includes REQUIRED and DERIVED_VALUE ]
|
| Within class source:
|
| SO_MFIELD_INIT_CLASS()
| SO_MFIELD_REQUIRED_SOURCE()
| SO_MFIELD_CONSTRUCTOR_SOURCE()
| SO_MFIELD_DERIVED_CONSTRUCTOR_SOURCE()
| SO_MFIELD_VALUE_SOURCE()
| SO_MFIELD_ALLOC_SOURCE()
| SO_MFIELD_MALLOC_SOURCE()
|
| SO_MFIELD_SOURCE()
| [includes REQUIRED, CONSTRUCTOR, VALUE, and ALLOC]
| SO_MFIELD_SOURCE_MALLOC()
| [includes REQUIRED, CONSTRUCTOR, VALUE, and MALLOC]
| SO_MFIELD_DERIVED_SOURCE()
| [includes REQUIRED and DERIVED_CONSTRUCTOR]
|
| Author(s) : Paul S. Strauss
|
______________ S I L I C O N G R A P H I C S I N C . ____________
_______________________________________________________________________
*/
#ifndef _SO_SUB_FIELD_
#define _SO_SUB_FIELD_
#include <Inventor/fields/SoField.h>
#include <Inventor/SoInput.h>
#include <Inventor/SoOutput.h>
// C-api: end
//===========================================================================
//
// These are all internal macros used by some of the public ones.
//
//===========================================================================
#define SO__FIELD_HEADER(className) \
public: \
virtual SoType getTypeId() const; \
static SoType getClassTypeId() { return classTypeId; } \
\
/* Copy from another field of same type */ \
const className & operator =(const className &f); \
\
SoINTERNAL public: \
/* Copy from another field of unknown type (assumed to be same type) */ \
virtual void copyFrom(const SoField &f); \
\
static void * createInstance(); /* for SoType */ \
\
/* Returns TRUE if fields are same type and have same values */ \
virtual SbBool isSame(const SoField &f) const; \
\
private: \
static SoType classTypeId
#define SO__SFIELD_RW_HEADER(className) \
private: \
/* Reads value of field from file */ \
virtual SbBool readValue(SoInput *in); \
\
/* Writes value of field to file */ \
virtual void writeValue(SoOutput *out) const
#define SO__MFIELD_RW_HEADER(className) \
private: \
/* Reads indexed value of field from file */ \
virtual SbBool read1Value(SoInput *in, int index); \
\
/* Writes one (indexed) value to file */ \
virtual void write1Value(SoOutput *out, int index) const
#define SO__FIELD_INIT_CLASS(className,classPrintName,parentClass) \
classTypeId = SoType::createType(parentClass::getClassTypeId(), \
classPrintName, \
&className::createInstance)
#define SO__FIELD_ID_SOURCE(className) \
\
SoType className::classTypeId; \
\
SoType \
className::getTypeId() const \
{ \
return classTypeId; \
} \
void * \
className::createInstance() \
{ \
return (void *)(new className); \
}
#define SO__FIELD_EQ_SAME_SOURCE(className) \
\
void \
className::copyFrom(const SoField &f) \
{ \
*this = * (const className *) &f; \
} \
\
SbBool \
className::isSame(const SoField &f) const \
{ \
return (getTypeId() == f.getTypeId() && \
(*this) == (const className &) f); \
}
//===========================================================================
//
// Macros to be called within the class definition header for a
// single-value field subclass:
//
//===========================================================================
////////////////////////////////////////////////////////////////////////////
//
// This declares all header info required for a single-value field class.
//
////////////////////////////////////////////////////////////////////////////
#define SO_SFIELD_REQUIRED_HEADER(className) \
SO__FIELD_HEADER(className)
////////////////////////////////////////////////////////////////////////////
//
// This declares a constructor and destructor for a single-value field class.
//
////////////////////////////////////////////////////////////////////////////
#define SO_SFIELD_CONSTRUCTOR_HEADER(className) \
public: \
className(); \
virtual ~className()
////////////////////////////////////////////////////////////////////////////
//
// This declares value processing methods and variables for a
// single-value field class.
//
////////////////////////////////////////////////////////////////////////////
#define SO_SFIELD_VALUE_HEADER(className, valueType, valueRef) \
SO__SFIELD_RW_HEADER(className); \
public: \
/* Get the value */ \
valueRef getValue() const \
{ evaluate(); return value; } \
\
/* Set value from a value of the appropriate type */ \
void setValue(valueRef newValue); \
valueRef operator =(valueRef newValue) \
{ setValue(newValue); return value; } \
\
/* Equality/inequality test for fields of same type */ \
int operator ==(const className &f) const; \
int operator !=(const className &f) const \
{ return ! ((*this) == f); } \
\
protected: \
valueType value
////////////////////////////////////////////////////////////////////////////
//
// This is like the above macro, but can be used by a field class
// derived from another (non-abstract) field class. It will inherit
// most of the field processing stuff.
//
////////////////////////////////////////////////////////////////////////////
#define SO_SFIELD_DERIVED_VALUE_HEADER(className, valueType, valueRef) \
SO__SFIELD_RW_HEADER(className); \
public: \
/* Since = operator is not inherited, we redefine it here */ \
valueRef operator =(valueRef newValue) \
{ setValue(newValue); return value; }
////////////////////////////////////////////////////////////////////////////
//
// This macro is all that is needed for most single-value field
// classes. It includes the relevant macros.
//
////////////////////////////////////////////////////////////////////////////
#define SO_SFIELD_HEADER(className, valueType, valueRef) \
SO_SFIELD_REQUIRED_HEADER(className); \
SO_SFIELD_CONSTRUCTOR_HEADER(className); \
SO_SFIELD_VALUE_HEADER(className, valueType, valueRef)
////////////////////////////////////////////////////////////////////////////
//
// This macro is all that is needed for most single-value field
// classes that are derived from other field classes. It includes the
// relevant macros.
//
////////////////////////////////////////////////////////////////////////////
#define SO_SFIELD_DERIVED_HEADER(className, valueType, valueRef) \
SO_SFIELD_REQUIRED_HEADER(className); \
SO_SFIELD_CONSTRUCTOR_HEADER(className); \
SO_SFIELD_DERIVED_VALUE_HEADER(className, valueType, valueRef)
//===========================================================================
//
// Macros to be called within the class definition header for a
// multiple-value field subclass:
//
//===========================================================================
////////////////////////////////////////////////////////////////////////////
//
// This declares all header info required for a multiple-value field class.
//
////////////////////////////////////////////////////////////////////////////
#define SO_MFIELD_REQUIRED_HEADER(className) \
SO__FIELD_HEADER(className)
////////////////////////////////////////////////////////////////////////////
//
// This declares a constructor and destructor for a multiple-value field class.
//
////////////////////////////////////////////////////////////////////////////
#define SO_MFIELD_CONSTRUCTOR_HEADER(className) \
public: \
className(); \
virtual ~className()
////////////////////////////////////////////////////////////////////////////
//
// This declares value processing methods and variables for a
// multiple-value field class.
//
////////////////////////////////////////////////////////////////////////////
#define SO_MFIELD_VALUE_HEADER(className, valueType, valueRef) \
SO__MFIELD_RW_HEADER(className); \
public: \
/* Get indexed value */ \
valueRef operator [](int i) const \
{ evaluate(); return values[i]; } \
\
/* Get pointer into array of values */ \
const valueType * getValues(int start) const \
{ evaluate(); return (const valueType *)(values + start); } \
\
/* Finds index of value that is equal to given one, or -1 if not */ \
/* found. If not found and addIfNotFound is TRUE, the new value is */ \
/* appended to the field. */ \
int find(valueRef targetValue, \
SbBool addIfNotFound = FALSE); \
\
/* Set num values starting at index start from info in newValues */ \
void setValues(int start, int num, \
const valueType *newValues); \
\
/* Set 1 value at given index */ \
void set1Value(int index, valueRef newValue); \
\
/* Set field to have one value */ \
void setValue(valueRef newValue); \
valueRef operator =(valueRef newValue) \
{ setValue(newValue); return newValue; } \
\
/* Equality/inequality test for fields of same type */ \
int operator ==(const className &f) const; \
int operator !=(const className &f) const \
{ return ! ((*this) == f); } \
\
/* Get non-const pointer into array of values for batch edits */ \
valueType * startEditing() \
{ evaluate(); return values; } \
\
/* Indicate that batch edits have finished */ \
void finishEditing() { valueChanged(); } \
\
protected: \
/* Allocates room for num values. Copies old values (if any) into */ \
/* new area. Deletes old area, if any. Will reduce room if needed, */ \
/* so a value of newNum==0 will delete all values. */ \
virtual void allocValues(int newNum); \
\
/* Deletes all current values, resets number of values */ \
virtual void deleteAllValues(); \
\
/* Copies value indexed by "from" to value indexed by "to" */ \
virtual void copyValue(int to, int from); \
\
valueType *values
////////////////////////////////////////////////////////////////////////////
//
// This is like the above macro, but can be used by a field class
// derived from another (non-abstract) field class. It will inherit
// most of the field processing stuff.
//
////////////////////////////////////////////////////////////////////////////
#define SO_MFIELD_DERIVED_VALUE_HEADER(className, valueType, valueRef) \
SO__MFIELD_RW_HEADER(className); \
public: \
/* Since = operator is not inherited, we redefine it here */ \
valueRef operator =(valueRef newValue) \
{ setValue(newValue); return newValue; }
////////////////////////////////////////////////////////////////////////////
//
// This macro is all that is needed for most multiple-value field
// classes. It includes the relevant macros.
//
////////////////////////////////////////////////////////////////////////////
#define SO_MFIELD_HEADER(className, valueType, valueRef) \
SO_MFIELD_REQUIRED_HEADER(className); \
SO_MFIELD_CONSTRUCTOR_HEADER(className); \
SO_MFIELD_VALUE_HEADER(className, valueType, valueRef)
////////////////////////////////////////////////////////////////////////////
//
// This macro is all that is needed for most multiple-value field
// classes that are derived from other field classes. It includes the
// relevant macros.
//
////////////////////////////////////////////////////////////////////////////
#define SO_MFIELD_DERIVED_HEADER(className, valueType, valueRef) \
SO_MFIELD_REQUIRED_HEADER(className); \
SO_MFIELD_CONSTRUCTOR_HEADER(className); \
SO_MFIELD_DERIVED_VALUE_HEADER(className, valueType, valueRef)
//===========================================================================
//
// Macros to be called within the source file for a single-value field
// subclass:
//
//===========================================================================
////////////////////////////////////////////////////////////////////////////
//
// This initializes type identifer variables. It should be called from
// within initClass().
//
////////////////////////////////////////////////////////////////////////////
#define SO_SFIELD_INIT_CLASS(className,parentClass) \
SO__FIELD_INIT_CLASS(className, SO__QUOTE(className), parentClass)
////////////////////////////////////////////////////////////////////////////
//
// This defines the variables and methods declared in
// SO_SFIELD_REQUIRED_HEADER().
//
////////////////////////////////////////////////////////////////////////////
#define SO_SFIELD_REQUIRED_SOURCE(className) \
\
SO__FIELD_ID_SOURCE(className); \
SO__FIELD_EQ_SAME_SOURCE(className) \
\
const className & \
className::operator =(const className &f) \
{ \
setValue(f.getValue()); \
return *this; \
}
////////////////////////////////////////////////////////////////////////////
//
// This defines the constructor and destructor.
//
////////////////////////////////////////////////////////////////////////////
#define SO_SFIELD_CONSTRUCTOR_SOURCE(className) \
\
className::className() \
{ \
} \
className::~className() \
{ \
}
////////////////////////////////////////////////////////////////////////////
//
// This defines the variables and methods declared in
// SO_SFIELD_VALUE_HEADER().
//
////////////////////////////////////////////////////////////////////////////
#define SO_SFIELD_VALUE_SOURCE(className, valueType, valueRef) \
\
void \
className::setValue(valueRef newValue) \
{ \
value = newValue; \
valueChanged(); \
} \
\
int \
className::operator ==(const className &f) const \
{ \
return getValue() == f.getValue(); \
}
////////////////////////////////////////////////////////////////////////////
//
// This macro is all that is needed for most single-value field
// classes. It includes the relevant macros.
//
////////////////////////////////////////////////////////////////////////////
#define SO_SFIELD_SOURCE(className, valueType, valueRef) \
SO_SFIELD_REQUIRED_SOURCE(className); \
SO_SFIELD_CONSTRUCTOR_SOURCE(className); \
SO_SFIELD_VALUE_SOURCE(className, valueType, valueRef)
////////////////////////////////////////////////////////////////////////////
//
// This macro is all that is needed for most single-value field
// classes that are derived from other field classes. It includes the
// relevant macros.
//
////////////////////////////////////////////////////////////////////////////
#define SO_SFIELD_DERIVED_SOURCE(className, valueType, valueRef) \
SO_SFIELD_REQUIRED_SOURCE(className); \
SO_SFIELD_CONSTRUCTOR_SOURCE(className)
//===========================================================================
//
// Macros to be called within the source file for a multiple-value field
// subclass:
//
//===========================================================================
////////////////////////////////////////////////////////////////////////////
//
// This initializes type identifer variables. It should be called from
// within initClass().
//
////////////////////////////////////////////////////////////////////////////
#define SO_MFIELD_INIT_CLASS(className,parentClass) \
SO__FIELD_INIT_CLASS(className, SO__QUOTE(className), parentClass)
////////////////////////////////////////////////////////////////////////////
//
// This defines the variables and methods declared in
// SO_MFIELD_REQUIRED_HEADER().
//
////////////////////////////////////////////////////////////////////////////
#define SO_MFIELD_REQUIRED_SOURCE(className) \
\
SO__FIELD_ID_SOURCE(className); \
SO__FIELD_EQ_SAME_SOURCE(className) \
\
const className & \
className::operator =(const className &f) \
{ \
if (f.getNum() < getNum()) \
deleteAllValues(); \
setValues(0, f.getNum(), f.getValues(0)); \
return *this; \
}
////////////////////////////////////////////////////////////////////////////
//
// This defines a constructor and destructor that work with the
// variables and methods defined in SO_MFIELD_VALUE_HEADER(). If you
// define your own value processing differently, you may not be able
// to use these.
//
////////////////////////////////////////////////////////////////////////////
#define SO_MFIELD_CONSTRUCTOR_SOURCE(className) \
\
className::className() \
{ \
values = NULL; \
} \
\
className::~className() \
{ \
deleteAllValues(); \
}
////////////////////////////////////////////////////////////////////////////
//
// This defines an empty constructor and destructor for classes
// derived from other field classes, since they inherit value
// processing.
//
////////////////////////////////////////////////////////////////////////////
#define SO_MFIELD_DERIVED_CONSTRUCTOR_SOURCE(className) \
\
className::className() \
{ \
} \
\
className::~className() \
{ \
}
////////////////////////////////////////////////////////////////////////////
//
// This defines the variables and methods declared in
// SO_MFIELD_VALUE_HEADER().
//
////////////////////////////////////////////////////////////////////////////
#define SO_MFIELD_VALUE_SOURCE(className, valueType, valueRef) \
\
int \
className::find(valueRef targetValue, SbBool addIfNotFound) \
{ \
int i, num = getNum(); \
\
for (i = 0; i < num; i++) \
if (values[i] == targetValue) \
return i; \
\
if (addIfNotFound) \
set1Value(num, targetValue); \
\
return -1; \
} \
\
void \
className::setValues(int start, int num, const valueType *newValues) \
{ \
int newNum = start + num, i; \
\
if (newNum > getNum()) \
makeRoom(newNum); \
\
for (i = 0; i < num; i++) \
values[start + i] = newValues[i]; \
\
valueChanged(); \
} \
\
void \
className::set1Value(int index, valueRef newValue) \
{ \
if (index >= getNum()) \
makeRoom(index + 1); \
values[index] = newValue; \
valueChanged(); \
} \
\
void \
className::setValue(valueRef newValue) \
{ \
makeRoom(1); \
values[0] = newValue; \
valueChanged(); \
} \
\
int \
className::operator ==(const className &f) const \
{ \
int i, num = getNum(); \
const valueType *myVals, *itsVals; \
\
if (num != f.getNum()) \
return FALSE; \
\
myVals = getValues(0); \
itsVals = f.getValues(0); \
\
for (i = 0; i < num; i++) \
if (! (myVals[i] == itsVals[i])) \
return FALSE; \
\
return TRUE; \
} \
\
void \
className::deleteAllValues() \
{ \
allocValues(0); \
} \
\
void \
className::copyValue(int to, int from) \
{ \
values[to] = values[from]; \
}
////////////////////////////////////////////////////////////////////////////
//
// This allocates/reallocates room for values, using the "new" and
// "delete" operators, so the constructor and destructor are called
// for new and deleted values.
//
////////////////////////////////////////////////////////////////////////////
#define SO_MFIELD_ALLOC_SOURCE(className, valueType) \
void \
className::allocValues(int newNum) \
{ \
if (values == NULL) { \
if (newNum > 0) \
values = new valueType[newNum]; \
} \
else { \
valueType *oldValues = values; \
int i; \
\
if (newNum > 0) { \
values = new valueType[newNum]; \
for (i = 0; i < num && i < newNum; i++) \
values[i] = oldValues[i]; \
} \
else \
values = NULL; \
delete [] oldValues; \
} \
\
num = maxNum = newNum; \
}
////////////////////////////////////////////////////////////////////////////
//
// This allocates/reallocates room for values, using malloc() and
// realloc(). This means that constructors and destructors will NOT be
// called for values. Therefore, this macro should not be used for any
// value types that have constructors or destructors! (It is used for
// fields that have simple types, like shorts and floats.)
//
////////////////////////////////////////////////////////////////////////////
#define SO_MFIELD_MALLOC_SOURCE(className, valueType) \
void \
className::allocValues(int newNum) \
{ \
if (values == NULL) { \
if (newNum > 0) \
values = (valueType *) malloc(sizeof(valueType) * newNum); \
} \
else { \
if (newNum > 0) \
values = (valueType *) realloc(values, sizeof(valueType)*newNum); \
else { \
free((char *) values); \
values = NULL; \
} \
} \
\
num = maxNum = newNum; \
}
////////////////////////////////////////////////////////////////////////////
//
// This macro is all that is needed for most multiple-value field
// classes. It includes the relevant macros, including the allocation
// macro that uses new and delete.
//
////////////////////////////////////////////////////////////////////////////
#define SO_MFIELD_SOURCE(className, valueType, valueRef) \
SO_MFIELD_REQUIRED_SOURCE(className) \
SO_MFIELD_CONSTRUCTOR_SOURCE(className) \
SO_MFIELD_VALUE_SOURCE(className, valueType, valueRef) \
SO_MFIELD_ALLOC_SOURCE(className, valueType)
////////////////////////////////////////////////////////////////////////////
//
// This is like the above macro, but uses the allocation macro that
// uses malloc() and realloc().
//
////////////////////////////////////////////////////////////////////////////
#define SO_MFIELD_SOURCE_MALLOC(className, valueType, valueRef) \
SO_MFIELD_REQUIRED_SOURCE(className) \
SO_MFIELD_CONSTRUCTOR_SOURCE(className) \
SO_MFIELD_VALUE_SOURCE(className, valueType, valueRef) \
SO_MFIELD_MALLOC_SOURCE(className, valueType)
////////////////////////////////////////////////////////////////////////////
//
// This macro is all that is needed for most multiple-value field
// classes that are derived from other field classes. It includes the
// relevant macros.
//
////////////////////////////////////////////////////////////////////////////
#define SO_MFIELD_DERIVED_SOURCE(className, valueType, valueRef) \
SO_MFIELD_REQUIRED_SOURCE(className); \
SO_MFIELD_DERIVED_CONSTRUCTOR_SOURCE(className)
// C-api: begin
#endif /* _SO_SUB_FIELD_ */
|