This repository has been archived on 2023-09-09. You can view files and clone it, but cannot push or open issues/pull-requests.
skemla/lib/Value.hpp

43 lines
977 B
C++

#ifndef sk_VALUE_HPP
#define sk_VALUE_HPP
#include "commons.hpp"
namespace sk
{
class Type;
class Value
{
public:
static std::shared_ptr<Value> make_int(int value);
static std::shared_ptr<Value> make_float(float value);
static std::shared_ptr<Value> make_bool(bool value);
static std::shared_ptr<Value> make_string(std::string const& value);
explicit Value(std::shared_ptr<Type> type);
virtual ~Value();
bool equals(Value const& rhs) const;
std::string string() const;
std::weak_ptr<Type> type() const;
int as_int() const { return *m_int_val; }
float as_float() const { return *m_float_val; }
bool as_bool() const { return *m_bool_val; }
std::string as_string() const { return *m_string_val; }
private:
std::shared_ptr<Type> m_type;
std::optional<int> m_int_val;
std::optional<float> m_float_val;
std::optional<std::string> m_string_val;
std::optional<bool> m_bool_val;
};
}
#endif