-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypedValue.h
106 lines (95 loc) · 2.18 KB
/
TypedValue.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#pragma once
#include <memory>
#include <iostream>
class FunctionPointer;
/// TypedValue lehetséges típusai
enum class ValueType
{
/// Egy valós szám
Number,
/// "igaz"/"hamis" érték
Bool,
/// Függvény
Function,
/// Nem meghatározott érték
Undefined,
/// Hibás érték
/// Típushibák esetén keletkezik kifejezések kiértékelésekor
Error
};
/// Típusos érték
class TypedValue
{
private:
/// Az érték típusa
ValueType type;
public:
/// @param type Az érték típusa
TypedValue(ValueType type);
/// Megmondja, hogy az érték egy bizonyos típusú-e
/// @param type Típus, amit vizsgálunk
bool is(ValueType type) const;
/// Az érték típusa
ValueType getType() const;
/// Kiírja magát az output streamre
/// @param os A stream, amire kiírunk
virtual void print(std::ostream& os) const = 0;
};
/// Kiír egy TypedValue-t az output streamre
/// @param os A stream, amire kiírunk
/// @param other A TypedValue, amit kiír
/// @see TypedValue::print
std::ostream& operator<<(std::ostream& os, const TypedValue& other);
/// Egy valós szám
class NumberValue : public TypedValue
{
private:
/// Érték
double value;
public:
/// @param value Érték
NumberValue(double value);
double getValue() const;
void print(std::ostream& os) const override;
};
/// "igaz"/"hamis" érték
class BoolValue : public TypedValue
{
private:
/// Érték
bool value;
public:
/// @param value Érték
BoolValue(bool value);
/// Érték
bool getValue() const;
void print(std::ostream& os) const override;
};
/// Függvény
class FunctionValue : public TypedValue
{
private:
/// Érték
std::shared_ptr<FunctionPointer> value;
public:
/// @param value Érték
FunctionValue(std::shared_ptr<FunctionPointer> value);
/// Érték
std::shared_ptr<FunctionPointer> getValue() const;
void print(std::ostream& os) const override;
};
/// Nem meghatározott érték
class UndefinedValue : public TypedValue
{
public:
UndefinedValue();
void print(std::ostream& os) const override;
};
/// Hibás érték
/// Típushibák esetén keletkezik kifejezések kiértékelésekor
class ErrorValue : public TypedValue
{
public:
ErrorValue();
void print(std::ostream& os) const override;
};