template<typename SystemLP_Type SystemLP_Type>
gtopt::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.

Public functions

template<typename Element Element>
auto add_element(Element&& element) -> auto
Adds a new element to the system.
template<typename Element Element, template<typename> class Id>
auto element(const Id<Element>& id) const -> constexpr auto&&
Gets a reference to an element by its ID.
template<typename Element Element, template<typename> class Id>
auto element_index(const Id<Element>& id) const -> constexpr auto
Gets the index of an element by its ID.
auto ElementContext(SystemLP_Type& system_lp) -> constexpr explicit noexcept
Constructs an ElementContext.
template<typename Element Element>
auto elements() const -> constexpr auto&& noexcept
Gets a container of all elements of a specific type.
template<typename Element Element, typename Self Self, typename Object Object, typename Attrs Attrs>
auto make_element_index(this Self&& self, const Object& objori, const std::variant<Uid, Name, Attrs>& element_var) -> ElementIndex< Element > -> auto
Finds an existing element's index or creates a new one.
auto system_lp(this auto& self) -> constexpr SystemLP_Type& noexcept
Gets the underlying SystemLP object.
auto system_lp(this const auto& self) -> constexpr const SystemLP_Type& noexcept

Function documentation

template<typename SystemLP_Type SystemLP_Type> template<typename Element 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 SystemLP_Type> template<typename Element Element, template<typename> class Id>
constexpr 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 SystemLP_Type> template<typename Element Element, template<typename> class Id>
constexpr 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 SystemLP_Type>
constexpr gtopt::ElementContext<SystemLP_Type>::ElementContext(SystemLP_Type& system_lp) explicit noexcept

Constructs an ElementContext.

Parameters
system_lp A reference to the system LP object.

template<typename SystemLP_Type SystemLP_Type> template<typename Element Element>
constexpr auto&& gtopt::ElementContext<SystemLP_Type>::elements() const noexcept

Gets a container of all elements of a specific type.

Returns A const reference to the container of elements.

template<typename SystemLP_Type SystemLP_Type> template<typename Element Element, typename Self Self, typename Object Object, typename Attrs Attrs>
auto gtopt::ElementContext<SystemLP_Type>::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.

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>
constexpr 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.