luco::value class

holds a luco value such as <std::string, double, int64_t, bool, null_type, monostate>

Constructors, destructors, conversion operators

template <is_allowed_value_type val_type>
value(const val_type& val) noexcept
constructor for luco::value
value(const value& other)
copy constructor for luco::value
value(const value&& other)
move constructor for luco::value
value() noexcept
constructor which sets an empty luco::value

Public functions

auto as_boolean() →  bool
cast luco::value into a boolean if it is holding a luco boolean (bool)
auto as_double() →  double
cast luco::value into a number if it is holding a luco number (double)
auto as_integer() →  int64_t
cast luco::value into a number if it is holding a luco number (int64_t)
auto as_null() →  null_type
cast luco::value into a null if it is holding a luco null (luco::null_type)
auto as_number() →  double
cast luco::value into a number if it is holding a luco number (double or int64_t)
auto as_string() →  std::string
cast luco::value into a string if it is holding a luco string (std::string)
auto is_boolean() const →  bool noexcept
checks if luco::value is holding luco boolean (bool)
auto is_double() const →  bool noexcept
checks if luco::value is holding luco number (double)
auto is_empty() const →  bool noexcept
checks if luco::value is not holding luco value (luco::monostate)
auto is_integer() const →  bool noexcept
checks if luco::value is holding luco number (int64_t)
auto is_null() const →  bool noexcept
checks if luco::value is holding luco null (luco::null_type)
auto is_number() const →  bool noexcept
checks if luco::value is holding luco number (double or int64_t)
auto is_string() const →  bool noexcept
checks if luco::value is holding luco string (std::string)
auto operator=(const value& other) →  value&
copy assignment for luco::value
auto operator=(const value&& other) →  value&
move assignment for luco::value
template <is_allowed_value_type val_type>
void set_value_type(const val_type& val) noexcept
sets the value and type of luco::value
auto set_value_type(const std::string& val, value_type type) →  expected<monostate, error>
sets the value and type of luco::value
auto stringify() const →  std::string noexcept
cast the luco value into a std::string
auto try_as_boolean() →  expected<bool, error> noexcept
cast luco::value into a bool if it is holding a luco boolean (bool)
auto try_as_double() →  expected<double, error> noexcept
cast luco::value into a double if it is holding a luco number (double)
auto try_as_integer() →  expected<int64_t, error> noexcept
cast luco::value into a int64_t if it is holding a luco number (int64_t)
auto try_as_null() →  expected<null_type, error> noexcept
cast luco::value into a luco::null_type if it is holding a luco null (luco::null_type)
auto try_as_number() →  expected<double, error> noexcept
cast luco::value into a double if it is holding a luco number (double or int64_t)
auto try_as_string() →  expected<std::string, error> noexcept
cast luco::value into a std::string if it is holding a luco string (std::string)
auto type() const →  luco::value_type noexcept
gets the type of the stored luco value
auto type_name() const →  std::string noexcept
gets string representation of luco::value_type of the internal value

Function documentation

template <is_allowed_value_type val_type>
luco::value::value(const val_type& val) noexcept

constructor for luco::value

Parameters
val luco value to be set

luco::value::value(const value& other)

copy constructor for luco::value

Parameters
other luco::value to be copied

luco::value::value(const value&& other)

move constructor for luco::value

Parameters
other luco::value to be moved

bool luco::value::as_boolean()

cast luco::value into a boolean if it is holding a luco boolean (bool)

Returns luco boolean
Exceptions
luco::error if it doesn't hold luco boolean

double luco::value::as_double()

cast luco::value into a number if it is holding a luco number (double)

Returns luco number
Exceptions
luco::error if it doesn't hold luco number

int64_t luco::value::as_integer()

cast luco::value into a number if it is holding a luco number (int64_t)

Returns luco number
Exceptions
luco::error if it doesn't hold luco number

null_type luco::value::as_null()

cast luco::value into a null if it is holding a luco null (luco::null_type)

Returns luco null
Exceptions
luco::error if it doesn't hold luco null

double luco::value::as_number()

cast luco::value into a number if it is holding a luco number (double or int64_t)

Returns luco number
Exceptions
luco::error if it doesn't hold luco number

std::string luco::value::as_string()

cast luco::value into a string if it is holding a luco string (std::string)

Returns luco string
Exceptions
luco::error if it doesn't luco string

bool luco::value::is_boolean() const noexcept

checks if luco::value is holding luco boolean (bool)

Returns true if it does

bool luco::value::is_double() const noexcept

checks if luco::value is holding luco number (double)

Returns true if it does

bool luco::value::is_empty() const noexcept

checks if luco::value is not holding luco value (luco::monostate)

Returns true if it does

bool luco::value::is_integer() const noexcept

checks if luco::value is holding luco number (int64_t)

Returns true if it does

bool luco::value::is_null() const noexcept

checks if luco::value is holding luco null (luco::null_type)

Returns true if it does

bool luco::value::is_number() const noexcept

checks if luco::value is holding luco number (double or int64_t)

Returns true if it does

bool luco::value::is_string() const noexcept

checks if luco::value is holding luco string (std::string)

Returns true if it does

value& luco::value::operator=(const value& other)

copy assignment for luco::value

Parameters
other luco::value to be copied
Returns the address of the modified luco::value

value& luco::value::operator=(const value&& other)

move assignment for luco::value

Parameters
other luco::value to be moved
Returns the address of the modified luco::value

template <is_allowed_value_type val_type>
void luco::value::set_value_type(const val_type& val) noexcept

sets the value and type of luco::value

Parameters
val luco value to be set

expected<monostate, error> luco::value::set_value_type(const std::string& val, value_type type)

sets the value and type of luco::value

Parameters
val luco value to be set
type luco type (luco::value_type) to be set
Returns luco::monostate or luco::error if the value wasn't set (wrong type was provided)

std::string luco::value::stringify() const noexcept

cast the luco value into a std::string

Returns string representation of the value

expected<bool, error> luco::value::try_as_boolean() noexcept

cast luco::value into a bool if it is holding a luco boolean (bool)

Returns bool or luco::error if it doesn't hold a boolean

expected<double, error> luco::value::try_as_double() noexcept

cast luco::value into a double if it is holding a luco number (double)

Returns double or luco::error if it doesn't hold a number

expected<int64_t, error> luco::value::try_as_integer() noexcept

cast luco::value into a int64_t if it is holding a luco number (int64_t)

Returns int64_t or luco::error if it doesn't hold a number

expected<null_type, error> luco::value::try_as_null() noexcept

cast luco::value into a luco::null_type if it is holding a luco null (luco::null_type)

Returns luco::null_type or luco::error if it doesn't hold a null

expected<double, error> luco::value::try_as_number() noexcept

cast luco::value into a double if it is holding a luco number (double or int64_t)

Returns double or luco::error if it doesn't hold a number

expected<std::string, error> luco::value::try_as_string() noexcept

cast luco::value into a std::string if it is holding a luco string (std::string)

Returns std::string or luco::error if it doesn't hold a string
luco::expected<std::string, error> string = value.try_as_string();
if (not string)
{
 // handle error
 std::println("{}", string.error().message());
}
else
{
 // success
 std::string string_value = string.value();
}

luco::value_type luco::value::type() const noexcept

gets the type of the stored luco value

Returns luco::value_type of the stored luco value

std::string luco::value::type_name() const noexcept

gets string representation of luco::value_type of the internal value

Returns string name of the value_type