-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathids.h
77 lines (67 loc) · 1.99 KB
/
ids.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
/*
* ===============================================================
* Description: Macros for generating ID classes, which are
* basically wrappers around a uint64_t.
*
* Created: 2014-02-08 17:26:46
*
* Author: Robert Escriva, [email protected]
* Ayush Dubey, [email protected]
*
* Copyright (C) 2013, Cornell University, see the LICENSE file
* for licensing agreement
* ===============================================================
*/
// Most of the following code has been 'borrowed' from
// Robert Escriva's HyperDex coordinator.
// see https://github.com/rescrv/HyperDex for the original code.
#ifndef weaver_common_ids_h_
#define weaver_common_ids_h_
// C
#include <stdint.h>
// C++
#include <iostream>
// e
#include <e/buffer.h>
#include <e/serialization.h>
// An ID is a simple wrapper around uint64_t in order to prevent devs from
// accidently using one type of ID as another.
#define OPERATOR(TYPE, OP) \
inline bool \
operator OP (const TYPE ## _id& lhs, const TYPE ## _id& rhs) \
{ \
return lhs.get() OP rhs.get(); \
}
#define CREATE_ID(TYPE) \
class TYPE ## _id \
{ \
public: \
TYPE ## _id() : m_id(0) {} \
explicit TYPE ## _id(uint64_t id) : m_id(id) {} \
public: \
uint64_t get() const { return m_id; } \
private: \
uint64_t m_id; \
}; \
std::ostream& \
operator << (std::ostream& lhs, const TYPE ## _id& rhs); \
inline size_t \
pack_size(const TYPE ## _id&) \
{ \
uint64_t i = 0; \
return e::pack_size(i); \
} \
e::packer \
operator << (e::packer pa, const TYPE ## _id& rhs); \
e::unpacker \
operator >> (e::unpacker up, TYPE ## _id& rhs); \
OPERATOR(TYPE, <) \
OPERATOR(TYPE, <=) \
OPERATOR(TYPE, ==) \
OPERATOR(TYPE, !=) \
OPERATOR(TYPE, >=) \
OPERATOR(TYPE, >)
CREATE_ID(server)
#undef OPERATOR
#undef CREATE_ID
#endif