BasicVariant

template<bool OWNING>
class ampl::BasicVariant

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

inline explicit 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).

inline explicit BasicVariant(internal::Variant *var)
inline BasicVariant()

Default constructor, creates an empty variant.

inline BasicVariant(int value)

Creates a numeric variant with the specified value.

inline BasicVariant(unsigned value)

Creates a numeric variant with the specified value.

inline BasicVariant(long value)

Creates a numeric variant with the specified value.

inline BasicVariant(unsigned long value)

Creates a numeric variant with the specified value.

inline BasicVariant(double value)

Creates a numeric variant with the specified value.

inline BasicVariant(const std::string &value)

Creates a string variant which references or owns a copy of the specified string.

inline BasicVariant(const char *value)

Creates a string variant which references or owns a copy of the specified string literal.

inline BasicVariant(const BasicVariant &other)

Copy constructor.

If OWNING copy the resources

template<bool U>
inline BasicVariant(BasicVariant<U> const &other)

Coercing copy constructor.

inline ~BasicVariant()

Destructor.

If OWNING frees the resources.

template<bool U>
inline BasicVariant &operator=(const BasicVariant<U> &other)

Coercing assignment operator.

inline BasicVariant &operator=(const BasicVariant &other)

Assignment operator.

inline const char *c_str() const

Returns the pointer to a C string.

inline double dbl() const

Returns the numerical value.

inline std::string str() const

Converts an AMPL variant element to an std::string object.

inline Type type() const

Returns the type of this variant object.

inline internal::Variant impl() const

Get the inner POD struct.

inline internal::Variant *impl_ptr()
inline 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.

Type

enum ampl::Type

Represents the type of a value in the AMPL type system, used in the Variant and VariantRef classes.

Values:

enumerator EMPTY

Empty variant, i.e.

one that does not hold a value

enumerator NUMERIC

Numeric (floating point) value.

enumerator STRING

String value.