Class ParameterView¶
Defined in File parameter.hpp
Class Documentation¶
-
class ParameterView¶
A view over an unowned parameter.
This lifetime of this view is tied to the
Parameter
from which it was derived. It is the caller’s responsibility to ensure the validity of this lifetime when accessing the view.Public Functions
-
std::string_view name() const noexcept¶
Returns the parameter name.
ParameterView implementation
-
ParameterType type() const noexcept¶
Returns the parameter type, used for disambiguation.
-
std::optional<ParameterValueView> value() const noexcept¶
Returns the parameter value.
-
inline bool hasValue() const noexcept¶
Returns true if the parameter has a value.
-
template<typename T>
inline bool is() const noexcept¶ Checks whether the parameter value matches the specified type.
Returns false if the parameter does not have a value.
- Template Parameters:
T – The expected type of the parameter value.
-
template<typename T>
inline bool isArray() const noexcept¶ Checks whether the parameter value is an array whose elements match the specified type.
Returns false if the parameter does not have a value. Returns true for empty arrays.
- Template Parameters:
T – The expected type of the array’s elements.
-
template<>
inline bool isArray() const noexcept¶ Checks whether the paramter value is an array of generic elements.
-
template<typename T>
inline bool isDict() const noexcept¶ Checks whether the parameter value is a dictionary whose values match the specified type.
Returns false if the parameter does not have a value. Returns true for an empty dictionary.
- Template Parameters:
T – The expected type of the dictionary’s values.
-
template<>
inline bool isDict() const noexcept¶ Checks whether the paramter value is an dictionary of generic values.
-
inline bool isByteArray() const noexcept¶
Checks whether the parameter value is a byte array.
-
template<typename T>
inline T get() const¶ Extracts a value from the parameter.
This method will throw an exception if the value is unset or the type does not match. You can use
ParameterView::is<T>()
to check that the type matches before calling this method.- Template Parameters:
T – The type of the value to extract.
-
template<>
inline std::vector<std::byte> get() const¶ Extracts the value as a byte array.
This method will throw an exception if the value is unset or is not a byte array. You can use
ParameterView::is<std::vector<std::byte>>()
to check that the type matches before calling this method.
-
template<>
inline std::vector<double> get() const¶ Extracts the value as an array of floating point values.
This method will throw an exception if the value is unset or is not an array of floating point values. You can use
ParameterView::is<std::vector<double>>()
to check that the type matches before calling this method.
-
template<>
inline std::vector<ParameterValueView> get() const¶ Extracts the value as an array of generic values.
This method will throw an exception if the value is unset or is not an array.
-
template<>
inline std::map<std::string, ParameterValueView> get() const¶ Extracts the value as a dictionary of generic values.
This method will throw an exception if the value is unset or is not an dictionary.
-
template<typename T>
inline std::vector<T> getArray() const¶ Extracts an array value from the parameter.
This method will throw an exception if the value is unset, the value is not an array or the element type does not match. You can use
ParameterView::isArray<T>()
to check that the element type matches before calling this method.- Template Parameters:
T – The type of the array’s elements.
-
template<typename T>
inline std::map<std::string, T> getDict() const¶ Extracts a dictionary value from the parameter.
This method will throw an exception if the value is unset, the value is not a dictionary or the value type does not match. You can use
ParameterView::isDict<T>()
to check that the value type matches before calling this method.- Template Parameters:
T – The type of the dictionary’s values.
-
FoxgloveResult<std::vector<std::byte>> getByteArray() const¶
Extracts a dictionary value from the parameter.
This method will return
ValueError
if the value is unset or the value is not a byte array. It will returnBase64DecodeError
if the value is not a valid base64-encoding.
-
std::string_view name() const noexcept¶