OOF2: The Manual

Name

ElementData — Additional data that can be assigned to an Element

Synopses

C++ Synopsis

#include "engine/element.h" 
class ElementData {
  ElementData(const std::string& name);
  virtual const std::string& classname() = 0;
  const std::string& name() const;
}

Python Synopsis

from ooflib.SWIG.engine.element import ElementData
class ElementData:
  def name(self)

Source Files

  • SRC/engine/element.C: C++ source code
  • SRC/engine/element.h: C++ header file
  • SRC/engine/element.swg: swig source code.

Description

ElementData is an abstract base class for data that can be stored in an Element. A Property or other OOF2 extension can define a subclass of ElementData, and use it to store and retrieve arbitrary data from an Element. The data object is given a name in its constructor argument and can be retrieved by passing that name to Element::getDataByName. Names must be unique, but uniqueness is not checked.

Derived classes must redefine classname, which is used when converting a C++ pointer to a Python object. See PythonExportable.

ElementData::name() returns the name assigned to an ElementData object in its constructor.

Other than name and classname, all of the functionality of an ElementData must be provided by the derived class.

[Note] Note

This class is not quite complete in OOF2 2.4.0. In particular, if an instance of a subclass of ElementData is created in Python and stored in an Element, the Element does not do the proper reference counting, and Python may destroy the instance if a separate reference to it is not retained.

For more infomation on using ElementData, see

While the Element methods for handling ElementData objects are available in Python, and ElementData subclasses can be defined in Python, currently the OOF2 infrastructure does not handle reference counting correctly for them. It's safer to define, construct, use, and delete ElementData objects only in C++. If it's necessary to use a Python subclass of ElementData, make sure to retain a reference to all instances of it in Python.