TT Client Library 1.0.0
C++ library for Tandem Tales clients.
Loading...
Searching...
No Matches
tt::Constant Class Reference

A constant is a logical value that always exists in all story worlds, such as the boolean concepts of True and False, numbers, and so on. More...

#include <tt/world/Constant.h>

Inheritance diagram for tt::Constant:
Collaboration diagram for tt::Constant:

Public Member Functions

 Constant (std::monostate value)
 Constructs a new constant equivalent to NULL_CONSTANT.
 Constant (bool value)
 Constructs a new constant that represents a Boolean value.
 Constant (std::int64_t value)
 Constructs a new constant that represents an integer.
 Constant (float value)
 Constructs a new constant that represents a decimal number.
std::string toString () const override
 Returns a string representation of this object.
bool toBool () const override
 If this value represents a Boolean, this method converts it into a bool; all other values are converted to false.
double toNumber () const override
 If this value represents a number, this method convert it into a double; all other values are converted to NaN.
virtual std::string_view getType () const override
 Returns the type of value (either "Entity" or "Constant").
Public Member Functions inherited from tt::Value
virtual ~Value ()=default
 Virtual destructor so Entity and Value can have their own.
virtual const Entity * toEntity () const
 If this value represents an tt::Entity, this method returns a pointer to that entity; all other values return nullptr.

Public Attributes

std::variant< std::monostate, bool, std::int64_t, double > value
 The value object associated with this constant.

Static Public Attributes

static constexpr std::string_view TYPE = "Constant"
 Type identifier used for deserialization.
static const Constant NULL_CONSTANT = Constant(std::monostate())
 A constant representing nothing or the absence of a value.
static const Constant TRUE = Constant(true)
 A constant representing Boolean true.
static const Constant FALSE = Constant(false)
 A constant representing Boolean false.

Protected Member Functions

virtual bool equals (const Value &other) const override
 Used for polymorphic ==.

Detailed Description

A constant is a logical value that always exists in all story worlds, such as the boolean concepts of True and False, numbers, and so on.

Author
Gage Birchmeier

Constructor & Destructor Documentation

◆ Constant() [1/4]

tt::Constant::Constant ( std::monostate value)
inline

Constructs a new constant equivalent to NULL_CONSTANT.

Parameters
valuea monostate, representing null

◆ Constant() [2/4]

tt::Constant::Constant ( bool value)
inline

Constructs a new constant that represents a Boolean value.

Parameters
valuethe boolean value

◆ Constant() [3/4]

tt::Constant::Constant ( std::int64_t value)
inline

Constructs a new constant that represents an integer.

Parameters
valuethe integer value

◆ Constant() [4/4]

tt::Constant::Constant ( float value)
inline

Constructs a new constant that represents a decimal number.

Parameters
valuethe decimal value

Member Function Documentation

◆ equals()

bool tt::Constant::equals ( const Value & other) const
overrideprotectedvirtual

Used for polymorphic ==.

Parameters
otheranother value object
Returns
whether the two values are equivalent

Implements tt::Value.

◆ getType()

std::string_view tt::Constant::getType ( ) const
overridevirtual

Returns the type of value (either "Entity" or "Constant").

Used in JSON deserialization

Returns
a string describing the type of value

Reimplemented from tt::Value.

◆ toBool()

bool tt::Constant::toBool ( ) const
overridevirtual

If this value represents a Boolean, this method converts it into a bool; all other values are converted to false.

Returns
a bool, or false if this value does not represent a Boolean value

Reimplemented from tt::Value.

◆ toNumber()

double tt::Constant::toNumber ( ) const
overridevirtual

If this value represents a number, this method convert it into a double; all other values are converted to NaN.

Returns
a double, or NaN if this value represents NaN or is not a number

Reimplemented from tt::Value.

◆ toString()

std::string tt::Constant::toString ( ) const
overridevirtual

Returns a string representation of this object.

Returns
a string describing this object

Reimplemented from tt::Value.


The documentation for this class was generated from the following files: