-
Notifications
You must be signed in to change notification settings - Fork 15
/
boilerplate.h
104 lines (96 loc) · 3.14 KB
/
boilerplate.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
/*
* ===============================================================
* Description: Boilerplate declarations and definitions for
* node programs
*
* Author: Ayush Dubey, dubey@cs.cornell.edu
*
* Copyright (C) 2015, Cornell University, see the LICENSE file
* for licensing agreement
* ===============================================================
*/
#ifndef weaver_node_prog_boilerplate_h_
#define weaver_node_prog_boilerplate_h_
#include <memory>
#include <vector>
#include <deque>
#include "common/message.h"
#include "node_prog/base_classes.h"
#include "node_prog/node.h"
#include "db/remote_node.h"
#define PROG_FUNC_DECLARE \
std::shared_ptr<Node_Parameters_Base> param_ctor(); \
std::shared_ptr<Node_State_Base> state_ctor(); \
\
uint64_t param_size(const Node_Parameters_Base&, void*); \
void param_pack(const Node_Parameters_Base&, e::packer&, void*); \
void param_unpack(Node_Parameters_Base&, e::unpacker&, void*); \
\
uint64_t state_size(const Node_State_Base&, void*); \
void state_pack(const Node_State_Base&, e::packer&, void*); \
void state_unpack(Node_State_Base&, e::unpacker&, void*); \
\
std::pair<search_type, std::vector<std::pair<db::remote_node, std::shared_ptr<Node_Parameters_Base>>>> \
node_program(node &n, \
db::remote_node &rn, \
std::shared_ptr<Node_Parameters_Base> param_ptr, \
std::function<Node_State_Base&()> state_getter);
#define CAST_ARG_REF(type, arg) \
type &tp = dynamic_cast<type&>(p);
#define PROG_FUNC_DEFINE(PREFIX) \
std::shared_ptr<Node_Parameters_Base> \
param_ctor() \
{ \
auto new_params = std::make_shared<PREFIX##_params>(); \
return std::dynamic_pointer_cast<Node_Parameters_Base>(new_params); \
} \
\
std::shared_ptr<Node_State_Base> \
state_ctor() \
{ \
auto new_state = std::make_shared<PREFIX##_state>(); \
return std::dynamic_pointer_cast<Node_State_Base>(new_state); \
} \
\
uint64_t \
param_size(const Node_Parameters_Base &p, void *aux_args) \
{ \
CAST_ARG_REF(const PREFIX##_params, p); \
return tp.size(aux_args); \
} \
\
void \
param_pack(const Node_Parameters_Base &p, e::packer &packer, void *aux_args) \
{ \
CAST_ARG_REF(const PREFIX##_params, p); \
tp.pack(packer, aux_args); \
} \
\
void \
param_unpack(Node_Parameters_Base &p, e::unpacker &unpacker, void *aux_args) \
{ \
CAST_ARG_REF(PREFIX##_params, p); \
tp.unpack(unpacker, aux_args); \
} \
\
uint64_t \
state_size(const Node_State_Base &p, void *aux_args) \
{ \
CAST_ARG_REF(const PREFIX##_state, p); \
return tp.size(aux_args); \
} \
\
void \
state_pack(const Node_State_Base &p, e::packer &packer, void *aux_args) \
{ \
CAST_ARG_REF(const PREFIX##_state, p); \
tp.pack(packer, aux_args); \
} \
\
void \
state_unpack(Node_State_Base &p, e::unpacker &unpacker, void *aux_args) \
{ \
CAST_ARG_REF(PREFIX##_state, p); \
tp.unpack(unpacker, aux_args); \
}
#endif