BasicVariant¶
-
template <bool OWNING>
classBasicVariant
¶ Template class which implements a variant object, with or without ownership semantics.
The object can represent a string or a double number, and maps directly to the underlying AMPL type system. It is not intended to be used directly, please use Variant (with ownership semantics, each object stores the values that it represents) or VariantRef (without ownership semantics, each object is only a reference to values stored elsewhere).
Public Functions
-
BasicVariant
(internal::Variant var)¶ Constructor from POD data type.
If the BasicVariant has ownership semantics, it owns the POD data (deleting it when the BasicVariant is deleted and copying it when it is copied).
-
BasicVariant
()¶ Default constructor, creates an empty variant.
-
BasicVariant
(int value)¶ Creates a numeric variant with the specified value.
-
BasicVariant
(unsigned value)¶ Creates a numeric variant with the specified value.
-
BasicVariant
(long value)¶ Creates a numeric variant with the specified value.
-
BasicVariant
(unsigned long value)¶ Creates a numeric variant with the specified value.
-
BasicVariant
(double value)¶ Creates a numeric variant with the specified value.
-
BasicVariant
(const std::string &value)¶ Creates a string variant which references or owns a copy of the specified string.
-
BasicVariant
(const char *value)¶ Creates a string variant which references or owns a copy of the specified string literal.
-
BasicVariant
(const BasicVariant &other)¶ Copy constructor.
If
OWNING
copy the resources
-
template <bool U>
BasicVariant
(BasicVariant<U> const &other)¶ Coercing copy constructor.
-
~BasicVariant
()¶ Destructor.
If
OWNING
frees the resources.
-
template <bool U>
BasicVariant &operator=
(const BasicVariant<U> &other)¶ Coercing assignment operator.
-
BasicVariant &
operator=
(const BasicVariant &other)¶ Assignment operator.
-
const char *
c_str
() const¶ Returns the pointer to a C string.
-
double
dbl
() const¶ Returns the numerical value.
-
std::string
str
() const¶ Converts an AMPL variant element to an
std::string
object.
-
internal::Variant
impl
() const¶ Get the inner POD struct.
-
std::string
toString
() const¶ Return an AMPL like representation of this variant.
String variants are single-quoted, numeric are not.
-
Variant¶
-
typedef BasicVariant<true>
ampl
::
Variant
¶ Public typedef of BasicVariant with ownership semantics.
VariantRef¶
-
typedef BasicVariant<false>
ampl
::
VariantRef
¶ Public typedef of BasicVariant without ownership semantics.
It can be used both as a return type when the ownership semantics is not needed (e.g. returning a reference to a value stored in a container) and as an argument type to provide implicit conversions and reduce the number of required overloads.