Generic struct

Generic is used to capture type string and the following primitives: double, integer, bool. Once captured, it has methods to convert to the appropriate type. Currently only getDouble() and getString() are implemented. Generic is not instantiable and is used for polymorphic behaviors. Only sub-classes can be constructed.

Derived classes

struct Bool
Wrapper class for bool.
struct Double
Wrapper class for double.
struct Integer
Wrapper class for integer.
struct String
Wrapper class for string.

Public static functions

static auto wrapPrimitive(std::string data) -> Generic*
Parses string data and subsequently constructs a sub-class instance on the heap of the parsed type (string, double, integer, bool).

Public functions

auto type() const -> GenericType virtual
Returns the type the generic is storing.
auto getDouble() const -> double
Get double from Generic.
auto getString() const -> std::string
Get string from Generic.

Function documentation

static Generic* Generic::wrapPrimitive(std::string data)

Parses string data and subsequently constructs a sub-class instance on the heap of the parsed type (string, double, integer, bool).

Parameters
data data, as a string, to be parsed.
Returns Generic*

GenericType Generic::type() const virtual

Returns the type the generic is storing.

Returns enum STRING, DOUBLE, INTEGER, BOOL.

double Generic::getDouble() const

Get double from Generic.

Returns double the double stored.
Exceptions
invalid_argument if data cannot be converted to double.

std::string Generic::getString() const

Get string from Generic.

Returns string the string stored.
Exceptions
invalid_argument if data cannot be converted to string.