#include <gtopt/element_traits.hpp>
ElementTraits struct
Defines default traits for element access and manipulation.
| Template parameters | |
|---|---|
| SystemContext | The context providing access to the system model. |
| Element | The type of element these traits are for. |
This traits struct provides a generic implementation for interacting with elements within a SystemContext. It forwards calls to the underlying SystemLP object.
Public static functions
- static auto get_element(SystemContext& sc, const Id<Element>& id) -> constexpr auto&&
- Gets a reference to an element by its ID.
- static auto get_element_index(SystemContext& sc, const Id<Element>& id) -> constexpr auto
- Gets the index of an element by its ID.
- static auto get_elements(SystemContext& sc) -> constexpr auto&& noexcept
- Gets a container of all elements of a specific type.
-
template<typename ElementType2 ElementType2>static auto push_back(SystemContext& sc, ElementType2&& e) -> constexpr auto
- Adds a new element to the system.
Function documentation
template<typename SystemContext SystemContext, typename Element Element>
template<template<typename> class Id>
static constexpr auto&& gtopt:: ElementTraits<SystemContext, Element>:: get_element(SystemContext& sc,
const Id<Element>& id)
Gets a reference to an element by its ID.
| Parameters | |
|---|---|
| sc | The system context. |
| id | The ID of the element. |
| Returns | A reference to the element. |
Routes through sc.get_element(id) — a fully-inline template in system_context.hpp using void* dispatch — so that call sites do NOT need to include system_lp.hpp to instantiate this template.
template<typename SystemContext SystemContext, typename Element Element>
template<template<typename> class Id>
static constexpr auto gtopt:: ElementTraits<SystemContext, Element>:: get_element_index(SystemContext& sc,
const Id<Element>& id)
Gets the index of an element by its ID.
| Parameters | |
|---|---|
| sc | The system context. |
| id | The ID of the element. |
| Returns | The ElementIndex for the given ID. |
static constexpr auto&& gtopt:: ElementTraits<SystemContext, Element>:: get_elements(SystemContext& sc) noexcept
Gets a container of all elements of a specific type.
| Parameters | |
|---|---|
| sc | The system context. |
| Returns | A reference to the container of elements. |
template<typename SystemContext SystemContext, typename Element Element>
template<typename ElementType2 ElementType2>
static constexpr auto gtopt:: ElementTraits<SystemContext, Element>:: push_back(SystemContext& sc,
ElementType2&& e)
Adds a new element to the system.
| Parameters | |
|---|---|
| sc | The system context. |
| e | The element to add. |
| Returns | The ElementIndex of the newly added element. |