SGPropertyNode#

class SGPropertyNode : public SGReferenced#

A node in a property tree.

Public Types

enum Attribute#

Access mode attributes.

The ARCHIVE attribute is strictly advisory, and controls whether the property should normally be saved and restored.

Values:

enumerator NO_ATTR#
enumerator READ#
enumerator WRITE#
enumerator ARCHIVE#
enumerator REMOVED#
enumerator TRACE_READ#
enumerator TRACE_WRITE#
enumerator USERARCHIVE#
enumerator PRESERVE#
enumerator PROTECTED#
enumerator LISTENER_SAFE#
enumerator VALUE_CHANGED_UP#
enumerator VALUE_CHANGED_DOWN#
enumerator TRANSLATE#

advisory: treat string value as a translation key. This is not handled by the property code, but exists to allow syntactically convenient marking of some properties in XMLs as ‘to be translated.

Public Functions

SGPropertyNode()#

Default constructor.

Default constructor: always creates a root node.

SGPropertyNode(const SGPropertyNode &node)#

Copy constructor.

virtual ~SGPropertyNode()#

Destructor.

bool hasValue() const#

Test whether this node contains a primitive leaf value.

const std::string &getNameString() const#

Get the node’s simple name as a string. Return value is not thread-safe.

std::string getDisplayName(bool simplify = false) const#

Get the node’s pretty display name, with subscript when needed.

int getIndex() const#

Get the node’s integer index.

unsigned int getPosition() const#

Get node’s position (contiguous values) in parent (NOT index)

SGPropertyNode *getParent()#

Get a pointer to the node’s parent.

int nChildren() const#

Get the number of child nodes.

SGPropertyNode *getChild(int position)#

Get a child node by position (NOT index).

bool hasChild(const char *name, int index = 0) const#

Test whether a named child exists.

SGPropertyNode *addChild(const char *name, int min_index = 0, bool append = true)#

Create a new child node with the given name and an unused index

Parameters:
  • min_index – Minimal index for new node (skips lower indices)

  • append – Whether to simply use the index after the last used index or use a lower, unused index if it exists

simgear::PropertyList addChildren(const std::string &name, size_t count, int min_index = 0, bool append = true)#

Create multiple child nodes with the given name an unused indices

Parameters:
  • count – The number of nodes create

  • min_index – Minimal index for new nodes (skips lower indices)

  • append – Whether to simply use the index after the last used index or use a lower, unused index if it exists

SGPropertyNode *getChild(const char *name, int index = 0, bool create = false)#

Get a child node by name and index.

simgear::PropertyList getChildren(const char *name) const#

Get a vector of all children with the specified name.

bool removeChild(SGPropertyNode *node)#

If <node> is child of this node, remove it and return true. Otherwise return false.

SGPropertyNode_ptr removeChild(int pos)#

Remove child by position and name.

simgear::PropertyList removeChildren(const std::string &name)#

Remove all children with the specified name.

void removeAllChildren()#

Remove all children (does not change the value of the node)

bool alias(SGPropertyNode *target, bool withListener)#

Alias this node’s leaf value to another’s.

bool alias(const char *path, bool withListener)#

Alias this node’s leaf value to another one’s by relative path.

bool alias(const std::string &path, bool withListener)#

Alias this node’s leaf value to another one’s by relative path.

bool unalias()#

Remove any alias for this node.

bool isAlias() const#

Test whether the node’s leaf value is aliased to another’s.

SGPropertyNode *getAliasTarget()#

Get a pointer to the current alias target, if any.

std::string getPath(bool simplify = false) const#

Get the path to this node from the root.

SGSourceLocation getLocation() const#

Get the original location of the node.

void setLocation(const SGSourceLocation &location)#

Set the original location of the node.

SGPropertyNode *getRootNode()#

Get a pointer to the root node.

void copy(SGPropertyNode *to) const#

deep copy one node to another.

SGPropertyNode *getNode(const char *relative_path, bool create = false)#

Get a pointer to another node by relative path.

SGPropertyNode *getNode(const char *relative_path, int index, bool create = false)#

Get a pointer to another node by relative path.

This method leaves the index off the last member of the path, so that the user can specify it separately (and save some string building). For example, getNode(“/bar[1]/foo”, 3) is exactly equivalent to getNode(“bar[1]/foo[3]”). The index provided overrides any given in the path itself for the last component.

bool getAttribute(Attribute attr) const#

Get or set a single mode attribute for the property node.

int getAttributes() const#

Get or set all of the mode attributes for the property node.

simgear::props::Type getType() const#

Get the type of leaf value, if any, for this node.

bool getBoolValue(bool defaultValue = false) const#

Get a value of this node. We return <defaultValue> if node is not readable or not the requested (or compatible) type and its string value is not convertible to the requested type.

bool setBoolValue(bool value)#

Set value of this node.

bool setUnspecifiedValue(const std::string &value)#

Set a value of unspecified type for this node.

template<typename T>
T getValue(typename std::enable_if<simgear::props::PropertyTraits<T>::Internal>::type *dummy = 0) const#

Get a value from a node. If the actual type of the node doesn’t match the desired type, a conversion isn’t guaranteed.

template<typename T, typename T_get>
std::vector<T> getChildValues(const std::string &name) const#

Get a list of values from all children with the given name.

template<typename T>
inline std::vector<T> getChildValues(const std::string &name) const#

Get a list of values from all children with the given name.

template<typename T>
inline bool setValueReadOnly(const std::string &relative_path, const T &value)#

Set relative node to given value and afterwards make read only.

Parameters:
  • relative_path – Path to node

  • value – Value to set

Returns:

whether value could be set

bool interpolate(const std::string &type, const SGPropertyNode &target, double duration = 0.6, const std::string &easing = "swing")#

Interpolate current value to target value within given time.

Parameters:
  • type – Type of interpolation (“numeric”, “color”, etc.)

  • target – Node containing target value

  • duration – Duration of interpolation (in seconds)

  • easing – Easing function (http://easings.net/)

bool interpolate(const std::string &type, const simgear::PropertyList &values, const std::vector<double> &deltas, const std::string &easing = "swing")#

Interpolate current value to a series of values within given durations.

Parameters:
  • type – Type of interpolation (“numeric”, “color”, etc.)

  • values – Nodes containing intermediate and target values

  • deltas – Durations for each interpolation step (in seconds)

  • easing – Easing function (http://easings.net/)

std::ostream &printOn(std::ostream &stream) const#

Print the value of the property to a stream.

bool isTied() const#

Test whether this node is bound to an external data source.

template<typename T>
bool tie(const SGRawValue<T> &rawValue, bool useDefault = true)#

Bind this node to an external source.

bool untie()#

Unbind this node from any external data source.

simgear::props::Type getType(const char *relative_path) const#

Get another node’s type.

bool hasValue(const char *relative_path) const#

Test whether another node has a leaf value.

bool getBoolValue(const char *relative_path, bool defaultValue = false) const#

Get another node’s value.

bool setBoolValue(const char *relative_path, bool value)#

Set another node’s value.

bool setUnspecifiedValue(const char *relative_path, const char *value)#

Set another node’s value with no specified type.

bool isTied(const char *relative_path) const#

Test whether another node is bound to an external data source.

bool tie(const char *relative_path, const SGRawValue<bool> &rawValue, bool useDefault = true)#

Bind another node to an external source.

bool untie(const char *relative_path)#

Unbind another node from any external data source.

void addChangeListener(SGPropertyChangeListener *listener, bool initial = false)#

Add a change listener to the property. If “initial” is set call the listener initially.

void removeChangeListener(SGPropertyChangeListener *listener)#

Remove a change listener from the property.

int nListeners() const#

Get the number of listeners.

void fireValueChanged()#

Fire a value change event to all listeners.

void fireChildAdded(SGPropertyNode *child)#

Fire a child-added event to all listeners.

void fireCreatedRecursive(bool fire_self = false)#

Trigger a child-added and value-changed event for every child (Unlimited depth).

It can be used to simulating the creation of a property tree, eg. for (re)initializing a subsystem which is controlled through the property tree.

Parameters:

fire_self – Whether to trigger the events also for the node itself.

void fireChildRemoved(SGPropertyNode *child)#

Fire a child-removed event to all listeners.

void fireChildrenRemovedRecursive()#

Fire a child-removed event for every child of this node (Unlimited depth)

Upon removal of a child node only for this single node a child-removed event is triggered. If eg. resource cleanup relies on receiving a child-removed event for every child this method can be used.

void clearValue()#

Clear any existing value and set the type to NONE.

Public Static Functions

static void setInterpolationMgr(simgear::PropertyInterpolationMgr *mgr)#

Set the interpolation manager used by the interpolate methods.

static simgear::PropertyInterpolationMgr *getInterpolationMgr()#

Get the interpolation manager.

static bool compare(const SGPropertyNode &lhs, const SGPropertyNode &rhs)#

Compare two property trees. The property trees are equal if: 1) They have no children, and have the same type and the values are equal, or 2) have the same number of children, and the corresponding children in each tree are equal. “corresponding” means have the same name and index.

Attributes, removed children, and aliases aren’t considered.

Public Static Attributes

static const int LAST_USED_ATTRIBUTE = TRANSLATE#

Last used attribute.

Last used attribute Update as needed when enum Attribute is changed