-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInfo.h
More file actions
112 lines (86 loc) · 2.93 KB
/
Info.h
File metadata and controls
112 lines (86 loc) · 2.93 KB
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
107
108
109
110
111
112
#ifndef INFO_H
#define INFO_H 1
#include <map>
#include <string>
#include <memory>
#include <deque>
#include <optional>
#include <set>
#include "types.h"
namespace Info {
enum class Types {
Test1,
Objective,
Subjective
};
struct Abstract {
public:
virtual Types t() = 0;
};
typedef std::set<std::shared_ptr<Abstract>> infoset_t;
template<enum Types T>
struct Base : public Abstract {
private:
static const Types type = T;
public:
Types t() final { return this->type; }
virtual bool is_valid() = 0;
};
/* the derived classes */
template<enum Types> struct Info {};
template<>
struct Info<Types::Test1> : public Base<Types::Test1> {
float item1;
virtual bool is_valid() { return true; }
};
template<>
struct Info<Types::Subjective> : public Base<Types::Subjective> {
// subjectivity_extent must be in [0, 100]
// A value of 0 means "completely objective", 100 means "completely subjective"
float subjectivity_extent;
// the "true" price that can be inferred from some model or process that interprets
// the content of the information (which is unspecified)
price_t price_indication;
// Whether the price indication is a "premium", i.e. should be taken
// as an offset/premium relative to other non-relative indications
// For example, we can emit an Info struct that gives an absolute
// (non-relative) price indication as a base, and then supplement the indication
// given in that struct with additional relative indications such as risk
// premia, which might have different values for subjectivity_extent.
bool is_relative;
virtual bool is_valid() {
return (
(this->subjectivity_extent >= 0 && this->subjectivity_extent <= 100) &&
(this->is_relative == true ? true : (this->price_indication >= 0))
);
}
};
// Assuming all Info types correctly inherit from the corresponding Base,
// specifically that Info<T> always inherits from Base<T>,
// get_cast is guaranteed to return a subtyped object (i.e. perform the cast)
// only when the underlying object is in fact of that subtype
template<enum Types T>
std::optional<std::shared_ptr< Info<T> >>
get_cast(std::shared_ptr<Abstract> ptr) {
if (ptr->t() == T) {
return dynamic_pointer_cast<Info<T>>(ptr);
}
return std::nullopt;
}
template<enum Types T>
std::shared_ptr< Info<T> >
get_cast_throws(std::shared_ptr<Abstract> ptr) {
return *(get_cast<T>(ptr));
}
/*
TODO not going with this design
typedef std::variant<
Info<Types::Subjective>,
Info<Types::Test1>
> var_t;
var_t as_variant(std::shared_ptr<Abstract> ptr) {
switch
}
*/
};
#endif