P4C
The P4 Compiler
Loading...
Searching...
No Matches
bson.h
1
17
18#ifndef BACKENDS_TOFINO_BF_ASM_BSON_H_
19#define BACKENDS_TOFINO_BF_ASM_BSON_H_
20
21#include <type_traits>
22
23#include "backends/tofino/bf-asm/json.h"
24
25namespace json {
26
27template <class T>
28struct bson_wrap {
29 T &o;
30 bson_wrap(T &o) : o(o) {} // NOLINT(runtime/explicit)
31 template <class U>
32 bson_wrap(U &o) : o(o) {} // NOLINT(runtime/explicit)
33};
34
35template <class T>
36bson_wrap<T> binary(T &o) {
37 return bson_wrap<T>(o);
38}
39
40std::istream &operator>>(std::istream &in, bson_wrap<std::unique_ptr<obj>> json);
41std::istream &operator>>(std::istream &in, bson_wrap<json::vector> json);
42std::istream &operator>>(std::istream &in, bson_wrap<json::map> json);
43inline std::istream &operator>>(std::istream &in, bson_wrap<obj *> json) {
44 std::unique_ptr<obj> p;
45 in >> binary(p);
46 if (in) json.o = p.release();
47 return in;
48}
49
50std::ostream &operator<<(std::ostream &out, bson_wrap<const vector>);
51std::ostream &operator<<(std::ostream &out, bson_wrap<const map>);
52std::ostream &operator<<(std::ostream &out, bson_wrap<const obj> json);
53inline std::ostream &operator<<(std::ostream &out, bson_wrap<vector> json) {
54 return operator<<(out, bson_wrap<const vector>(json.o));
55}
56inline std::ostream &operator<<(std::ostream &out, bson_wrap<map> json) {
57 return operator<<(out, bson_wrap<const map>(json.o));
58}
59inline std::ostream &operator<<(std::ostream &out, bson_wrap<obj> json) {
60 return operator<<(out, bson_wrap<const obj>(json.o));
61}
62inline std::ostream &operator<<(std::ostream &out, bson_wrap<const obj *> json) {
63 return out << binary(*json.o);
64}
65inline std::ostream &operator<<(std::ostream &out, bson_wrap<obj *> json) {
66 return out << binary(*json.o);
67}
68inline std::ostream &operator<<(std::ostream &out, bson_wrap<const std::unique_ptr<obj>> json) {
69 return out << binary(*json.o.get());
70}
71
72} // end namespace json
73
74#endif /* BACKENDS_TOFINO_BF_ASM_BSON_H_ */
Definition bson.cpp:69
Definition bson.h:28