#include <gtopt/element_context.hpp>
template<typename SystemLP_Type>
ElementContext class
Provides a context for interacting with elements within a SystemLP.
| Template parameters | |
|---|---|
| SystemLP_Type | The type of the system linear programming model. |
This class acts as a facade over a SystemLP-like object, providing a simplified interface for element management. It forwards calls for element access, indexing, and creation to the underlying system model.
Constructors, destructors, conversion operators
- ElementContext(SystemLP_Type& system_lp) explicit constexpr noexcept
- Constructs an ElementContext.
Public functions
-
template<typename Element>auto add_element(Element&& element) -> auto
- Adds a new element to the system.
-
template<typename Element, template<typename> class Id>auto element(const Id<Element>& id) const -> auto&&
- Gets a reference to an element by its ID.
-
template<typename Element, template<typename> class Id>auto element_index(const Id<Element>& id) const -> auto
- Gets the index of an element by its ID.
-
template<typename Element>auto elements() const -> auto&&
- Gets a container of all elements of a specific type.
-
template<typename Element, typename Self, typename Object Object, typename Attrs>auto make_element_index(this Self&& self, const Object& objori, const std::variant<Uid, Name, Attrs>& element_var) -> ElementIndex<Element>
- Finds an existing element's index or creates a new one.
- auto system_lp(this auto& self) -> SystemLP_Type& noexcept
- Gets the underlying SystemLP object.
- auto system_lp(this const auto& self) -> const SystemLP_Type& noexcept
Function documentation
template<typename SystemLP_Type>
gtopt:: ElementContext<SystemLP_Type>:: ElementContext(SystemLP_Type& system_lp) explicit constexpr noexcept
Constructs an ElementContext.
| Parameters | |
|---|---|
| system_lp | A reference to the system LP object. |
template<typename SystemLP_Type>
template<typename Element>
auto gtopt:: ElementContext<SystemLP_Type>:: add_element(Element&& element)
Adds a new element to the system.
| Parameters | |
|---|---|
| element | The element to add (rvalue reference). |
| Returns | The ElementIndex of the newly added element. |
template<typename SystemLP_Type>
template<typename Element, template<typename> class Id>
auto&& gtopt:: ElementContext<SystemLP_Type>:: element(const Id<Element>& id) const
Gets a reference to an element by its ID.
| Parameters | |
|---|---|
| id | The ID of the element. |
| Returns | A reference to the element. |
| Exceptions | |
| std::out_of_range | if the element is not found. |
template<typename SystemLP_Type>
template<typename Element, template<typename> class Id>
auto gtopt:: ElementContext<SystemLP_Type>:: element_index(const Id<Element>& id) const
Gets the index of an element by its ID.
| Parameters | |
|---|---|
| id | The ID of the element. |
| Returns | The ElementIndex for the given ID. |
| Exceptions | |
| std::out_of_range | if the element is not found. |
template<typename SystemLP_Type>
template<typename Element>
auto&& gtopt:: ElementContext<SystemLP_Type>:: elements() const
Gets a container of all elements of a specific type.
| Returns | A const reference to the container of elements. |
|---|---|
| Exceptions | |
| std::runtime_error | — propagates from SystemLP::elements<X>() if the per-cell collections are empty (post-release_backend() under non-off low_memory without a preceding rebuild_collections_if_needed()). No longer declared noexcept so the runtime error reaches outer frames. |
template<typename SystemLP_Type>
template<typename Element, typename Self, typename Object Object, typename Attrs>
ElementIndex<Element> gtopt:: ElementContext<SystemLP_Type>:: make_element_index(this Self&& self,
const Object& objori,
const std::variant<Uid, Name, Attrs>& element_var)
Finds an existing element's index or creates a new one.
| Parameters | |
|---|---|
| self | The ElementContext instance. |
| objori | The original object with base data. |
| element_var | A variant holding either a Uid, a Name, or Attrs. |
| Returns | ElementIndex of the found or created element. |
This function attempts to find an element by Uid or Name. If not found, it creates a new element using the provided attributes and original object data.
template<typename SystemLP_Type>
SystemLP_Type& gtopt:: ElementContext<SystemLP_Type>:: system_lp(this auto& self) noexcept
Gets the underlying SystemLP object.
| Returns | A reference to the SystemLP object, preserving const and value category. |
|---|