Skip to content

scram::mef::Element

The MEF Element with attributes and a label. More...

#include <element.h>

Inherits from scram::mef::ContainerElement, boost::noncopyable

Inherited by scram::mef::Alignment, scram::mef::Component, scram::mef::EventTree, scram::mef::ExternFunction< void >, scram::mef::ExternLibrary, scram::mef::FunctionalEvent, scram::mef::Id, scram::mef::InitiatingEvent, scram::mef::Model, scram::mef::NamedBranch, scram::mef::Phase, scram::mef::Rule, scram::mef::Sequence, scram::mef::Substitution

Public Types

Name
using ext::linear_set< Attribute, AttributeKey >AttributeMap <br>Unique attribute map keyed with the attribute names.

Public Functions

Name
Element(std::string name)<br>Constructs an element with an original name.
const std::string &name() const
std::string_viewname_view() const
const std::string &label() const
voidlabel(std::string label)<br>Sets the element label.
const AttributeMap &attributes() const
voidAddAttribute(Attribute attr)<br>Adds an attribute to the attribute map of this element.
voidSetAttribute(Attribute attr)<br>Sets an attribute to the attribute map.
const Attribute *GetAttribute(std::string_view name) const
std::optional< Attribute >RemoveAttribute(std::string_view name)<br>Removes an attribute of this element.

Protected Functions

Name
~Element() =default
voidname(std::string name)<br>Resets the element name.

Additional inherited members

Protected Functions inherited from scram::mef::ContainerElement

Name
const Element *container() const

Friends inherited from scram::mef::ContainerElement

Name
classContainer

Detailed Description

cpp
class scram::mef::Element;

The MEF Element with attributes and a label.

Note: The class is not polymorphic.

This is a base/mixin class for most of the MEF constructs.

Public Types Documentation

using AttributeMap

cpp
using scram::mef::Element::AttributeMap =  ext::linear_set<Attribute, AttributeKey>;

Unique attribute map keyed with the attribute names.

Note:

  • Elements are expected to have very few attributes, complex containers may be overkill.
  • Using a multi-index or other tables incurs a huge memory overhead in common usage (up to 400B / attribute).

Public Functions Documentation

function Element

cpp
explicit Element(
    std::string name
)

Constructs an element with an original name.

Parameters:

  • name The local identifier name.

Exceptions:

The name is expected to conform to identifier requirements described in the MEF documentation and additions.

function name

cpp
inline const std::string & name() const

Return: The original name.

function name_view

cpp
inline std::string_view name_view() const

Return: The string view to the name for table keys.

function label

cpp
inline const std::string & label() const

Return:

  • The empty or preset label.
  • Empty string if the label has not been set.

function label

cpp
inline void label(
    std::string label
)

Sets the element label.

Parameters:

  • label The extra description for the element.

function attributes

cpp
inline const AttributeMap & attributes() const

Return: The current set of element attributes (non-inherited!).

Note: The element attributes override its inherited attributes. However, the inherited attributes are not copied into the map. The precedence is followed upon lookup.

function AddAttribute

cpp
void AddAttribute(
    Attribute attr
)

Adds an attribute to the attribute map of this element.

Parameters:

  • attr An attribute of this element.

Exceptions:

Warning: Pointers or references to existing attributes may get invalidated.

function SetAttribute

cpp
void SetAttribute(
    Attribute attr
)

Sets an attribute to the attribute map.

Parameters:

  • attr An attribute of this element.

Warning: Pointers or references to existing attributes may get invalidated.

If an attribute with the same name exits, it gets overwritten.

function GetAttribute

cpp
const Attribute * GetAttribute(
    std::string_view name
) const

Parameters:

  • name The name of the attribute.

Return: The attribute with the given name. nullptr if no attribute is found.

Note: Attributes can be inherited from parent containers.

Warning: Attribute addresses are not stable. Do not store the returned pointer.

function RemoveAttribute

cpp
std::optional< Attribute > RemoveAttribute(
    std::string_view name
)

Removes an attribute of this element.

Parameters:

  • name The identifying name of the attribute.

Return: The removed attribute if any.

Postcondition: No inherited attributes are affected.

Protected Functions Documentation

function ~Element

cpp
~Element() =default

function name

cpp
void name(
    std::string name
)

Resets the element name.

Parameters:

  • name The local identifier name.

Exceptions:


Updated on 2025-11-11 at 16:51:08 +0000