Coin: SoFieldData Class Reference

| Coin3D is Free Software, published under the BSD 3-clause license. | https://coin3d.github.io https://www.kongsberg.com/en/kogt/

SoFieldData Class Reference
Field Classes

The SoFieldData class is a container for a prototype set of fields. More...

`#include <Inventor/fields/SoFieldData.h>`

## Public Member Functions
| SoFieldData (void)
| SoFieldData (const SoFieldData &fd)
| SoFieldData (const SoFieldData *fd)
| SoFieldData (int numfields)
| ~SoFieldData ()
void | addField (SoFieldContainer *base, const char *name, const SoField *field)
void | overlay (SoFieldContainer *to, const SoFieldContainer *from, SbBool copyconnections) const
int | getNumFields (void) const
const SbName & | getFieldName (int index) const
SoField * | getField (const SoFieldContainer *object, int index) const
int | getIndex (const SoFieldContainer *fc, const SoField *field) const
void | addEnumValue (const char *enumname, const char *valuename, int value)
void | getEnumData (const char *enumname, int &num, const int *&values, const SbName *&names)
SbBool | read (SoInput *input, SoFieldContainer *object, SbBool erroronunknownfield, SbBool &notbuiltin) const
SbBool | read (SoInput *input, SoFieldContainer *object, const SbName &fieldname, SbBool &foundname) const
void | write (SoOutput *out, const SoFieldContainer *object) const
void | copy (const SoFieldData *src)
SbBool | isSame (const SoFieldContainer *c1, const SoFieldContainer *c2) const
SbBool | readFieldDescriptions (SoInput *input, SoFieldContainer *object, int numdescriptionsexpected, const SbBool readfieldvalues=TRUE) const
void | writeFieldDescriptions (SoOutput *out, const SoFieldContainer *object) const

## Detailed Description

The SoFieldData class is a container for a prototype set of fields.

This class is instantiated once for each class of objects which use fields, and which need to be able to import and export them.

Each field of a class is stored with the name it has been given within its "owner" class and a pointer offset to the dynamic instance of the field itself.

Enumeration sets are stored with (name, value) pairs, to make it possible to address, read and save enum type fields by name.

It is unlikely that application programmers should need to use any of the methods of this class directly.

See also
  SoField, SoFieldContainer

## Constructor & Destructor Documentation

## ◆ SoFieldData() [1/4]

SoFieldData::SoFieldData | ( | void |  | ) |

Default constructor.

## ◆ SoFieldData() [2/4]

SoFieldData::SoFieldData | ( | const SoFieldData & | fd | ) |

Copy constructor.

## ◆ SoFieldData() [3/4]

SoFieldData::SoFieldData | ( | const SoFieldData * | fd | ) |

Copy constructor taking a pointer value as an argument. Handles `NULL` pointers by behaving like the default constructor.

## ◆ SoFieldData() [4/4]

SoFieldData::SoFieldData | ( | int | numfields | ) |

Constructor. Takes an indication on the number of fields which should be stored, to make sure the memory handling is efficient.

## ◆ ~SoFieldData()

SoFieldData::~SoFieldData | ( |  | ) |

Destructor.

## Member Function Documentation

## ◆ addField()

void SoFieldData::addField | ( | SoFieldContainer * | base,
|  | const char * | name,
|  | const SoField * | field )

Add a new field to our internal list.

The name will be stored along with an pointer offset between base and field, which will be valid for all instances of the class type of base.

## ◆ overlay()

void SoFieldData::overlay | ( | SoFieldContainer * | to,
|  | const SoFieldContainer * | from,
|  | SbBool | copyconnections ) const

Copy fields from container from to container to. If copyconnections is `TRUE`, we'll also copy the connections field from has made.

If you think the method signature is a bit strange, you're correct. This should really have been a static method (the owner `this` instance of the method isn't used at all, due to how the internal representation of field template list are stored), but for unknown reasons this is a dynamic method in Open Inventor. So also in Coin, to keep compatibility.

## ◆ getNumFields()

int SoFieldData::getNumFields | ( | void |  | ) | const

Returns number of fields contained within this instance.

## ◆ getFieldName()

const SbName & SoFieldData::getFieldName | ( | int | index | ) | const

Returns the name of the field at index.

## ◆ getField()

SoField * SoFieldData::getField | ( | const SoFieldContainer * | object,
|  | int | index ) const

Returns a pointer to the field at index within the object instance.

## ◆ getIndex()

int SoFieldData::getIndex | ( | const SoFieldContainer * | fc,
|  | const SoField * | field ) const

Returns the internal index value of field in fc. If field is not part of fc, returns -1.

## ◆ addEnumValue()

void SoFieldData::addEnumValue | ( | const char * | enumname,
|  | const char * | valuename,
|  | int | value )

Either adds a new enum set (with an initial member), or adds a new value member to an existing enum set.

## ◆ getEnumData()

void SoFieldData::getEnumData | ( | const char * | enumname,
|  | int & | num,
|  | const int *& | values,
|  | const SbName *& | names )

Returns the names and values of enumeration entry with the enumname. The number of (name, value) pairs available in the enumeration is returned in num.

## ◆ read() [1/2]

SbBool SoFieldData::read | ( | SoInput * | in,
|  | SoFieldContainer * | object,
|  | SbBool | erroronunknownfield,
|  | SbBool & | notbuiltin ) const

Read field data from the in stream for fields belonging to object. Returns `TRUE` if everything went OK, or `FALSE` if any error conditions occurs.

erroronunknownfield decides whether or not `FALSE` should be returned if a name identifier not recognized as a field name of object is encountered. Note that erroronunknownfield should be `FALSE` if object is a container with child objects, otherwise the code will fail upon the first child name specification.

If notbuiltin is `TRUE` on return, object is an unknown node or engine type. Unknown nodes are recognized by the `fields` keyword first in their file format definition, and unknown engines by the `inputs` keyword.

## ◆ read() [2/2]

SbBool SoFieldData::read | ( | SoInput * | in,
|  | SoFieldContainer * | object,
|  | const SbName & | fieldname,
|  | SbBool & | foundname ) const

Find field fieldname in object, and if it is available, set foundname to `TRUE` and try to read the field specification from in. If foundname is set to `TRUE`, the return value says whether or not the field specification could be read without any problems.

If fieldname is not part of object, returns `FALSE` with foundname also set to `FALSE`.

## ◆ write()

void SoFieldData::write | ( | SoOutput * | out,
|  | const SoFieldContainer * | object ) const

Write to out field names and field values for the fields of object.

## ◆ copy()

void SoFieldData::copy | ( | const SoFieldData * | src | ) |

Copy contents of src into this instance.

If there was any data set up in this instance before the method was called, the old data is removed first.

Note that this only copies the field set template specification from src, not actual field contents. For copying field contents, see the SoFieldData::overlay() method.

## ◆ isSame()

SbBool SoFieldData::isSame | ( | const SoFieldContainer * | c1,
|  | const SoFieldContainer * | c2 ) const

Compares c1 and c2 to see if they have the same field data set and if the fields of c1 have the same values as the fields of c2.

Field connections are not considered (i.e. we will return `TRUE` if the values of the fields of c1 are equal to the fields of c2, even if they differ in how they have made connections to other fields).

If you think the method signature is a bit strange, you're correct. This should really have been a static method (the owner `this` instance of the method isn't used at all, due to how the internal representations of field template lists are stored), but for unknown reasons this is a dynamic method in Open Inventor. So also in Coin, to keep compatibility.

## ◆ readFieldDescriptions()

SbBool SoFieldData::readFieldDescriptions | ( | SoInput * | in,
|  | SoFieldContainer * | object,
|  | int | numdescriptionsexpected,
|  | const SbBool | readfieldvalues = TRUE ) const

Reads a set of field specifications from in for an unknown node class type, in the form "[ FIELDCLASS FIELDNAME, FIELDCLASS FIELDNAME, ... ]".

numdescriptionsexpected is used for binary format import to know how many descriptions should be parsed.

If readfieldvalues is TRUE (the default), the field initial value is expected after the field name in the SoInput stream.

## ◆ writeFieldDescriptions()

void SoFieldData::writeFieldDescriptions | ( | SoOutput * | out,
|  | const SoFieldContainer * | object ) const

Write a set of field specifications to out for an unknown node class type, in the form "[ FIELDCLASS FIELDNAME, FIELDCLASS FIELDNAME, ... ]".

The documentation for this class was generated from the following files:

- SoFieldData.h
- SoFieldData.cpp