Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

SoMField Class Reference

The SoMField class is the base class for fields which can contain multiple values. More...

#include <Inventor/fields/SoMField.h>

Inheritance diagram for SoMField::

SoField SoMFBool SoMFColor SoMFEngine SoMFEnum SoMFFloat SoMFInt32 SoMFMatrix SoMFName SoMFNode SoMFPath SoMFPlane SoMFRotation SoMFShort SoMFString SoMFTime SoMFUInt32 SoMFUShort SoMFVec2f SoMFVec3f SoMFVec4f List of all members.

Public Methods

virtual ~SoMField ()
int getNum (void) const
void setNum (const int num)
virtual void deleteValues (int start, int num=-1)
virtual void insertSpace (int start, int num)
SbBool set1 (const int index, const char *const valuestring)
void get1 (const int index, SbString &valuestring)

Static Public Methods

SoType getClassTypeId (void)
void initClass (void)

Protected Methods

 SoMField (void)
virtual void makeRoom (int newnum)

Protected Attributes

int num
int maxNum

Detailed Description

The SoMField class is the base class for fields which can contain multiple values.

All field types which may contain more than one member value inherits this class. SoMField is an abstract class.

Use setValue(), setValues() or set1Value() to set the values of fields inheriting SoMField, and use getValues() or the index operator[] to read values. Example code:

    SoText2 * textnode = new SoText2;
    textnode->ref();

    // Setting multi-field values. /////////////////////////////

    // Set the first value of the SoMFString field of the SoText2 node.
    // The field array will be truncated to only contain this single value.
    textnode->string.setValue("Morten");
    // Full contents of the SoMFString is: [ "Morten" ]

    // The setValue() method and the = operator is interchangeable,
    // so this code line does the same as the previous line.
    textnode->string = "Peder";
    // Full contents of the SoMFString is now: [ "Peder" ]

    // Set the value at index 2. If the field value array contained
    // less than 3 elements before this call, first expand it to contain
    // 3 elements.
    textnode->string.set1Value(2, "Lars");
    // Full contents of the SoMFString is: [ "Peder", <undefined>, "Lars" ]

    // This sets 3 values of the array, starting at index 5. If the
    // array container had less than 8 elements before the setValues()
    // call, the array will first be expanded.
    SbString s[3] = { "Eriksen", "Blekken", "Aas" };
    textnode->string.setValues(5, sizeof(s), s);
    // Full contents of the SoMFString is now:
    //     [ "Peder", <undefined>, "Lars", <undefined>, <undefined>,
    //       "Eriksen", "Blekken", "Aas" ]


    // Inspecting multi-field values. //////////////////////////

    // This will read the second element (counting from zero) if the
    // multivalue field and place it in "val".
    SbString val = textnode->string[2];

    // Gives us a pointer to the array which the multiple-value field
    // is using to store the values. Note that the return value is
    // "const", so you can only read from the array, not write to
    // it.
    const SbString * vals = textnode->string.getValues(0);


    // Modifying multi-field values. ///////////////////////////

    // You can of course modify multifield-values by using the set-
    // and get-methods shown above, but when you're working with
    // big sets of data, this will be ineffective. Then use this
    // technique instead:
    SbString * modvals = textnode->string.startEditing();

    // ... lots of modifications to the "modvals" array here ...

    // Calling the finishEditing() method is necessary for the
    // scene graph to be updated (and re-rendered).
    textnode->string.finishEditing();

The reason it is more effective to wrap many modifications within startEditing() / finishEditing() is because we avoid the stream of notification messages which would otherwise be sent for each and every modification done. Instead there will just be a single notification about the changes, triggered by the finishEditing() call.

When nodes, engines or other types of field containers are written to file, their multiple-value fields are written to file in this format:

    containerclass {
      fieldname [ value0, value1, value2, ...]
      ...
    }

..like this, for instance, a Coordinate3 node providing 6 vertex coordinates in the form of SbVec3f values in its "point" field for e.g. a faceset, lineset or pointset:

     Coordinate3 {
        point [
           -1 1 0, -1 -1 0, 1 -1 0,
           0 2 -1, -2 0 -1, 0 -2 -1,
        ]
     }

See also:
SoSField


Constructor & Destructor Documentation

SoMField::~SoMField [virtual]
 

Destructor in SoMField does nothing. Resource deallocation needs to be done from subclasses.

SoMField::SoMField void [protected]
 

Constructor. Initializes number of values in field to zero.


Member Function Documentation

SoType SoMField::getClassTypeId void [static]
 

Returns a unique type identifier for this field class.

See also:
getTypeId(), SoType

Reimplemented from SoField.

int SoMField::getNum void const [inline]
 

Returns number of values in this field.

void SoMField::setNum const int num
 

Set number of values to num.

If the current number of values is less than num, the array of values will be truncated from the end, if num is larger than the current number of values, random values will be appended.

void SoMField::deleteValues int start,
int num = -1
[virtual]
 

Remove value elements from index start up to and including index start + num - 1.

Elements with indices larger than the last deleted element will be moved downwards in the value array.

If num equals -1, delete from index start and to the end of the array.

void SoMField::insertSpace int start,
int num
[virtual]
 

Insert num "slots" for new value elements from start. The elements already present from start will be moved "upward" in the extended array.

SbBool SoMField::set1 const int index,
const char *const valuestring
 

Set the value at index to the value contained in valuestring. Returns TRUE if a valid value for this field can be extracted from valuestring, otherwise FALSE.

void SoMField::get1 const int index,
SbString & valuestring
 

Return the value at index in the valuestring string.

void SoMField::initClass void [static]
 

Internal method called upon initialization of the library (from SoDB::init()) to set up the type system.

Reimplemented from SoField.

Reimplemented in SoMFBool, SoMFColor, SoMFFloat, SoMFInt32, SoMFMatrix, SoMFName, SoMFPlane, SoMFRotation, SoMFShort, SoMFString, SoMFTime, SoMFUInt32, SoMFUShort, SoMFVec2f, SoMFVec3f, SoMFVec4f, SoMFEnum, SoMFBitMask, SoMFNode, SoMFEngine, and SoMFPath.

void SoMField::makeRoom int newnum [protected, virtual]
 

Make room in the field to store newnum values.


Member Data Documentation

int SoMField::num [protected]
 

Number of available values.

int SoMField::maxNum [protected]
 

Number of array "slots" allocated for this field.


The documentation for this class was generated from the following files:
Generated at Tue Mar 5 03:31:27 2002 for Coin by doxygen1.2.9 written by Dimitri van Heesch, © 1997-2001