TT Client Library 1.0.0
C++ library for Tandem Tales clients.
Loading...
Searching...
No Matches
Constant.h
1#pragma once
2
3#include <variant>
4#include <cstdint>
5#include <string>
6#include <nlohmann/json.hpp>
7#include <tt/world/Value.h>
8
9#ifndef CONSTANT_H
10#define CONSTANT_H
11
12
13namespace tt {
21 class Constant : public Value {
22 public:
24 static constexpr std::string_view TYPE = "Constant";
25
27 static const Constant NULL_CONSTANT;
29 static const Constant TRUE;
31 static const Constant FALSE;
32
34 std::variant<std::monostate, bool, std::int64_t, double> value;
35
41 Constant(std::monostate value): value(value) {};
42
49
55 Constant(std::int64_t value): value(value) {};
56
63
64 // default constructor necessary for deserialization
65 Constant(): value(std::monostate()) {};
66
67 std::string toString() const override;
68 bool toBool() const override;
69 double toNumber() const override;
70 virtual std::string_view getType() const override;
71
72 protected:
73 virtual bool equals(const Value& other) const override;
74 };
75
76 void from_json(const nlohmann::json& j, Constant& obj);
77 void to_json(nlohmann::json& j, const Constant& obj);
78}
79
80#endif
A constant is a logical value that always exists in all story worlds, such as the boolean concepts of...
Definition Constant.h:21
Constant(float value)
Constructs a new constant that represents a decimal number.
Definition Constant.h:62
static constexpr std::string_view TYPE
Type identifier used for deserialization.
Definition Constant.h:24
virtual bool equals(const Value &other) const override
Used for polymorphic ==.
Definition Constant.cpp:35
double toNumber() const override
If this value represents a number, this method convert it into a double; all other values are convert...
Definition Constant.cpp:22
Constant(std::int64_t value)
Constructs a new constant that represents an integer.
Definition Constant.h:55
Constant(std::monostate value)
Constructs a new constant equivalent to NULL_CONSTANT.
Definition Constant.h:41
std::variant< std::monostate, bool, std::int64_t, double > value
The value object associated with this constant.
Definition Constant.h:34
static const Constant NULL_CONSTANT
A constant representing nothing or the absence of a value.
Definition Constant.h:27
virtual std::string_view getType() const override
Returns the type of value (either "Entity" or "Constant").
Definition Constant.cpp:30
static const Constant TRUE
A constant representing Boolean true.
Definition Constant.h:29
Constant(bool value)
Constructs a new constant that represents a Boolean value.
Definition Constant.h:48
static const Constant FALSE
A constant representing Boolean false.
Definition Constant.h:31
bool toBool() const override
If this value represents a Boolean, this method converts it into a bool; all other values are convert...
Definition Constant.cpp:17
std::string toString() const override
Returns a string representation of this object.
Definition Constant.cpp:9
A value is a logical expression which evaluates to itself.
Definition Value.h:17
Tandem Tales is a platform that enables short, paired storytelling exercises between two agents over ...
Definition Client.h:22