-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_conversion.h
More file actions
92 lines (61 loc) · 1.93 KB
/
json_conversion.h
File metadata and controls
92 lines (61 loc) · 1.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
#ifndef JSON_CONVERSION_H
#define JSON_CONVERSION_H 1
#include <utility>
#include <functional>
#include <nlohmann/json.hpp>
#include "Agent/Agent.h"
#include "Market.h"
using json = nlohmann::json;
/*
Type used to interpret Agent configuration sent to add_agents
*/
struct agent_config_item {
std::string type;
int count;
// interpreted manually depending on the type
json config;
};
struct subscriber_config_item {
json config;
json parameter;
};
struct info_item {
json type;
json data;
};
void to_json(json& j, const timepoint_t tp);
namespace Market {
void to_json(json& j, const agentid_t id);
void to_json(json& j, const agentrecord_desc_t id);
void from_json(const json& j, agentid_t& id);
void from_json(const json& j, Config& c);
};
//namespace Subscriber {};
// converters for the Subscriber namespace are in Subscriber.h/Subscriber.cpp
namespace Agent {
void to_json(json& j, const AgentAction act);
};
void to_json(json& j, const numeric_id<market_numeric_id_tag> id);
void to_json(json& j, const numeric_id<subscriber_numeric_id_tag> id);
void from_json(const json& j, numeric_id<market_numeric_id_tag>& id);
void from_json(const json& j, numeric_id<subscriber_numeric_id_tag>& id);
void from_json(const json& j, agent_config_item& c);
void from_json(const json& j, subscriber_config_item& c);
namespace Info {
void from_json(const json& j, std::shared_ptr<Abstract>& t);
};
namespace nlohmann {
// for now, treat the high-precision price_t as a double for JSON purposes
// alternative would be to store it in a separate JSON object using boost's
// internal representation, or as a string
template<>
struct adl_serializer<price_t> {
static void to_json(json& j, const price_t& x) {
j = static_cast<double>(x);
}
static void from_json(const json& j, price_t& x) {
x = j.get<double>();
}
};
};
#endif