SoMField(3)

πŸ“¦
version 4.0.10 Β· 4 versions
, in fedora 43, fedora 44

πŸ’– SoMField(3) β€” Coin's multi-value field base class πŸ’–

okay so bestie, this is the manual page for SoMField from Coin. It's part 1 of 3, so we're not even done yet. SoMField is the base class for fields that can hold multiple values. It's giving "the mother of all MF fields" energy. πŸ‘‘βœ¨


✨ NAME ✨

SoMField β€” the base class for fields which can contain multiple values.


🌸 SYNOPSIS 🌸

#include <Inventor/fields/SoMField.h>

Inherits SoField.

Inherited by SoMFBool, SoMFColor, SoMFColorRGBA, SoMFDouble, SoMFEngine, SoMFEnum, SoMFFloat, SoMFInt32, SoMFMatrix, SoMFName, SoMFNode, SoMFPath, SoMFPlane, SoMFRotation, SoMFShort, SoMFString, SoMFTime, SoMFUInt32, SoMFUShort, SoMFVec2b, SoMFVec2d, SoMFVec2f, SoMFVec2i32, SoMFVec2s, SoMFVec3b, SoMFVec3d, SoMFVec3f, SoMFVec3i32, SoMFVec3s, SoMFVec4b, SoMFVec4d, SoMFVec4f, SoMFVec4i32, SoMFVec4s, SoMFVec4ub, SoMFVec4ui32, and SoMFVec4us.

πŸ’… Public Member Functions πŸ’…

Here's the whole roster, no skips:

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)
virtual void enableDeleteValues (void)
virtual SbBool isDeleteValuesEnabled (void) const

🫢 Public Member Functions inherited from SoField 🫢

These are the ones you get from SoField, bestie:

virtual ~SoField ()
void setIgnored (SbBool ignore)
SbBool isIgnored (void) const
void setDefault (SbBool defaultVal)
SbBool isDefault (void) const
virtual SoType getTypeId (void) const =0
SbBool isOfType (const SoType type) const
void enableConnection (SbBool flag)
SbBool isConnectionEnabled (void) const
SbBool connectFrom (SoEngineOutput *master, SbBool notnotify=FALSE,
    SbBool append=FALSE)
SbBool appendConnection (SoEngineOutput *master, SbBool notnotify=FALSE)
void disconnect (SoEngineOutput *engineoutput)
SbBool isConnectedFromEngine (void) const
SbBool getConnectedEngine (SoEngineOutput *&master) const
SbBool connectFrom (SoField *master, SbBool notnotify=FALSE, SbBool
    append=FALSE)
SbBool appendConnection (SoField *master, SbBool notnotify=FALSE)
void disconnect (SoField *field)
SbBool isConnectedFromField (void) const
SbBool getConnectedField (SoField *&master) const
int getNumConnections (void) const
int getForwardConnections (SoFieldList &slavelist) const
int getConnections (SoFieldList &masterlist) const
void disconnect (void)
SbBool isConnected (void) const
void setContainer (SoFieldContainer *cont)
SoFieldContainer * getContainer (void) const
SbBool set (const char *valuestring)
void get (SbString &valuestring)
SbBool shouldWrite (void) const
virtual void touch (void)
virtual void startNotify (void)
virtual void notify (SoNotList *nlist)
SbBool enableNotify (SbBool on)
SbBool isNotifyEnabled (void) const
void addAuditor (void *f, SoNotRec::Type type)
void removeAuditor (void *f, SoNotRec::Type type)
int operator== (const SoField &f) const
int operator!= (const SoField &f) const
virtual void connectionStatusChanged (int numconnections)
SbBool isReadOnly (void) const
virtual SbBool isSame (const SoField &f) const =0
virtual void copyFrom (const SoField &f)=0
virtual void fixCopy (SbBool copyconnections)
virtual SbBool referencesCopy (void) const
void copyConnection (const SoField *fromfield)
virtual SbBool read (SoInput *input, const SbName &name)
virtual void write (SoOutput *out, const SbName &name) const
virtual void countWriteRefs (SoOutput *out) const
void setFieldType (int type)
int getFieldType (void) const
SbBool getDirty (void) const
void setDirty (SbBool dirty)
void evaluate (void) const

✨ Static Public Member Functions ✨

static SoType getClassTypeId (void)
static void atexit_cleanup (void)
static void initClass (void)

πŸ’– Static Public Member Functions inherited from SoField πŸ’–

static void initClass (void)
static void initClasses (void)
static void cleanupClass (void)
static SoType getClassTypeId (void)

πŸŽ€ Protected Member Functions πŸŽ€

SoMField (void)
virtual void makeRoom (int newnum)
virtual SoNotRec createNotRec (SoBase *container)
void setChangedIndex (const int chgidx)
void setChangedIndices (const int chgidx=-1, const int numchgind=0)

πŸ¦‹ Protected Member Functions inherited from SoField πŸ¦‹

SoField (void)
void valueChanged (SbBool resetdefault=TRUE)
virtual void evaluateConnection (void) const
virtual SbBool readConnection (SoInput *in)
virtual void writeConnection (SoOutput *out) const
SbBool isDestructing (void) const

🌈 Protected Attributes 🌈

int num
int maxNum
SbBool userDataIsUsed

πŸ‘‘ Additional Inherited Members πŸ‘‘

⭐ Public Types inherited from SoField ⭐

enum FieldType { NORMAL_FIELD = 0, EVENTIN_FIELD, EVENTOUT_FIELD,
    EXPOSED_FIELD }

✨ Detailed Description ✨

okay bestie, so like, the SoMField class is the base class for fields that can hold multiple values. πŸ’–

Every field type that can have more than one member value inherits from this class. And just so you know, SoMField is an abstract class β€” you can't just instantiate it, it's like the blueprint for all the multi-value fields. πŸ—οΈ

To set the values of fields that inherit SoMField, you use setValue(), setValues(), or set1Value(). And to read values, you use getValues() or the index operator []. Here's some example code to make it click:

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) / sizeof(s[0]), s);
// Full contents of the SoMFString is now:
//     [ "Peder", <undefined>, "Lars", <undefined>, <undefined>,
//       "Eriksen", "Blekken", "Aas" ]

// Note also that the setValues() call will *not* truncate a field
// container if you use it to change a subset at the start:
SbString n[4] = { "Dixon", "Adams", "Bould", "Winterburn" };
textnode->string.setValues(0, sizeof(n) / sizeof(n[0]), n);
// Full contents of the SoMFString is now:
//     [ "Dixon", "Adams", "Bould", "Winterburn", <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();

Now, the reason it's way more effective to wrap a bunch of modifications inside startEditing() / finishEditing() is because you avoid the flood of notification messages that would otherwise be sent for every single little change. Instead, you get just one notification about all the changes, triggered when you call finishEditing(). It's giving efficient. πŸ’…

The correct way to pre-allocate a specific number of field values in one go is to use the SoMField::setNum() method β€” like, do it before you start using startEditing() and finishEditing(). Just so you know, the field values will be uninitialized after you expand the field with setNum(). No cap. 🫠

Be aware, bestie: your application code has to be careful not to do silly things during a setValues()-triggered notification. If you have code that looks like this, for example:
// update set of coordinate indices at the start of e.g.
// an SoIndexedFaceSet's coordIndex field..
ifs->coordIndex.setValues(0, runner->numIndices, runner->indices);
// ..then truncate to make sure it's the correct size.
ifs->coordIndex.setNum(runner->numIndices);

Since setValues() might leave some elements at the end of the array that can typically be invalid indices after the first statement runs, something can go wrong during notification if you have application code monitoring changes. Like, the application code might trigger an action or something that tries to use the coordIndex field before it's updated to the correct size with the setNum() call. 😭

Notification can, in this case, as always, be temporarily disabled to be on the safe side:

somefield.enableNotify(FALSE);
somefield.setValues(...);
somefield.setNum(...);
somefield.enableNotify(TRUE);
somefield.touch();

This will guarantee that the setValues() and setNum() pair will be executed as an atomic operation. Slay. ✨

When nodes, engines, or other types of field containers are written to file, their multiple-value fields are written 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,
   ]
}

Some fields support application data sharing through a setValuesPointer() method. setValuesPointer() makes it possible to set the data pointer directly in the field. Normally (when using setValues()), Coin makes a copy of your data, so this method can be super useful if your application needs the data internally and you're just using Coin for the visualization. Example code:

myapp->calculateCoordinates(SOME_LARGE_VALUE);
SbVec3f * mycoords = myapp->getCoordinates();

SoCoordinate3 * mynode = myapp->getCoordinateNode();
mynode->point.setValuesPointer(SOME_LARGE_VALUE, mycoords);

Be aware that your field should be a read-only field when you set the data like this. If you write to the field, the values in your application array will be overwritten. If you append values to the field, a new array will be allocated, and the data will be copied into it before appending the new values. The array pointer will then be discarded. πŸ™ˆ

Also note that whenever you change some value(s) in the array, you must manually notify Coin about this by calling SoField::touch(). For our example:

SbVec3f * mycoords = myapp->getCoordinate();
myapp->updateCoordinate(mycoords);
SoCoordinate3 * mynode = myapp->getCoordinateNode();
mynode->point.touch(); // this will notify Coin that field has changed

You can use SoMField::enableDeleteValues() to make Coin delete the array for you when the field is destructed or the array pointer is discarded because it isn't needed anymore (e.g. when the array size is changed). The array will be deleted using the C++ delete[] operator, so if you use it, your array must be allocated using the C++ new[] operator. 🧚

SoMField::enableDeleteValues() is supported only to be compatible with later versions of TGS Inventor, and we don't recommend using it. It can have undefined results on the Microsoft Windows platform. Allocating memory in the application and destructing it in a DLL can be a bad thing, causing mysterious crashes, if you're not very careful about how your application and DLLs are linked to the underlying C library. πŸ’€

🌸 See also 🌸

  • SoSField

✨ Constructor & Destructor Documentation ✨

SoMField::~SoMField () [virtual]

Destructor in SoMField does nothing. Resource deallocation needs to be done from subclasses. Like, it's not gonna clean up after you, bestie. πŸ™…β€β™€οΈ

SoMField::SoMField (void ) [protected]

Constructor. Initializes number of values in field to zero. So it starts empty, ready for you to fill it up. πŸ’–


✨ Member Function Documentation ✨

SoType SoMField::getClassTypeId (void ) [static]

Returns a unique type identifier for this field class. πŸ”‘

See also: getTypeId(), SoType

int SoMField::getNum (void ) const [inline]

Returns number of values in this field. Like, how many you got? πŸ”’

void SoMField::setNum (const int numarg)

Set number of values to num.

If the current number of values is larger than num, the array of values will be truncated from the end. But if num is larger, the array will automatically be expanded (and random values will be set for the new array items). So it's giving unpredictable, but that's on you. 🎲

void SoMField::deleteValues (int start, int numarg = -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. Bye bye, values. πŸ‘‹

Reimplemented in SoMFEngine, SoMFNode, and SoMFPath.

void SoMField::insertSpace (int start, int numarg) [virtual]

Insert num "slots" for new value elements from start. The elements already present from start will be moved "upward" in the extended array. It's like making room for new besties. 🫢

Reimplemented in SoMFEngine, SoMFNode, and SoMFPath.

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. πŸ’―

If index is larger than the current number of elements in the field, this method will automatically expand the field to accommodate the new value. It's got your back. ✨

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

Return the value at index in the valuestring string. Got it? πŸ“

void SoMField::initClass (void ) [static]

Internal method called upon initialization of the library (from SoDB::init()) to set up the type system. Not for you to call, it's backend stuff. 🀫

void SoMField::enableDeleteValues (void ) [virtual]

Can be used to make Coin delete the array pointer set through a setValuesPointer() call. See SoMField documentation for information about the setValuesPointer() function.

This method is a TGS extension (introduced in TGS OIV v3.0) and is supported only for compatibility. We suggest that you don't use it since it can lead to hard-to-find bugs. πŸ›

Since: Coin 2.0, TGS Inventor 3.0

SbBool SoMField::isDeleteValuesEnabled (void ) const [virtual]

Returns whether SoMField::enableDeleteValues() has been called on a field. The result is only valid if setValuesPointer() has been called on the field first. πŸ”

This method is a TGS extension (introduced in TGS OIV v3.0) and is supported only for compatibility. We suggest that you don't use it since it can lead to hard-to-find bugs. πŸ›

Since: Coin 2.0, TGS Inventor 3.0

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

Make room in the field to store newnum values. Like, clear some space. 🧹

SoNotRec SoMField::createNotRec (SoBase * container) [protected], [virtual]

Reimplemented from SoField.

✨ MEMBER DATA DOCUMENTATION ✨

ok so now we're at the protected data members and honestly bestie these are the little backstage gremlins that make everything work πŸ’– they're protected, which means you can only touch them from inside the class (or a subclass) β€” no reaching in from outside, that's not the vibe 🫢


  • int SoMField::num [protected] β€” the number of available values, like literally how many values are actually chillin' in this field right now πŸ”₯
  • int SoMField::maxNum [protected] β€” the number of array "slots" allocated for this field. so num is how many you're using and maxNum is how many seats exist in the arena, periodt πŸ‘‘ allocated β‰  filled, iykyk
  • SbBool SoMField::userDataIsUsed [protected] β€” is TRUE if data have been set through a setValuesPointer() call, and set to FALSE through a enableDeleteValues() call 🌸 so it's basically the little flag that remembers whether you handed over that pointer or whether the field is owning its own data. keep an eye on this one, it's the difference between "you manage this memory" and "we manage this memory" πŸ’…
fr fr don't go poking at these directly from the outside β€” they're protected for a reason, and the vibes will not be immaculate if you try πŸ™ˆ

🌈 AUTHOR 🌈

Generated automatically by Doxygen for Coin from the source code. πŸ€–βœ¨


and that's a wrap on SoMField(3) bestie!! πŸŽ€ thank you for staying through all three parts, you ate that πŸ’… this beauty came from Coin version 4.0.10, dated Thu Jun 25 2026 00:00:00 ⭐ go forth and field responsibly, mwah πŸ’–πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from