P4C
The P4 Compiler
Loading...
Searching...
No Matches
rapidjson_adapter.h
1
19#ifndef _BACKENDS_TOFINO_BF_P4C_LOGGING_RAPIDJSON_ADAPTER_H_
20#define _BACKENDS_TOFINO_BF_P4C_LOGGING_RAPIDJSON_ADAPTER_H_
21
22#include <rapidjson/document.h>
23#include <rapidjson/prettywriter.h>
24
25namespace Logging {
26
28using PlainWriter = rapidjson::Writer<rapidjson::StringBuffer>;
29using PrettyWriter = rapidjson::PrettyWriter<rapidjson::StringBuffer>;
30
36class Writer {
37 public:
38 virtual void Key(const char *s) = 0;
39 virtual void Bool(bool b) = 0;
40 virtual void Int(int n) = 0;
41 virtual void Double(double d) = 0;
42 virtual void String(const char *s) = 0;
43 virtual void StartArray() = 0;
44 virtual void EndArray() = 0;
45 virtual void StartObject() = 0;
46 virtual void EndObject() = 0;
47
48 virtual ~Writer() {}
49};
50
52 PrettyWriter w;
53
54 public:
55 virtual void Key(const char *s) { w.Key(s); }
56 virtual void Bool(bool b) { w.Bool(b); }
57 virtual void Int(int n) { w.Int(n); }
58 virtual void Double(double d) { w.Double(d); }
59 virtual void String(const char *s) { w.String(s); }
60 virtual void StartArray() { w.StartArray(); }
61 virtual void EndArray() { w.EndArray(); }
62 virtual void StartObject() { w.StartObject(); }
63 virtual void EndObject() { w.EndObject(); }
64
65 explicit PrettyWriterAdapter(rapidjson::StringBuffer &sb) : w(sb) {}
66};
67
68class PlainWriterAdapter : public Writer {
70
71 public:
72 virtual void Key(const char *s) { w.Key(s); }
73 virtual void Bool(bool b) { w.Bool(b); }
74 virtual void Int(int n) { w.Int(n); }
75 virtual void Double(double d) { w.Double(d); }
76 virtual void String(const char *s) { w.String(s); }
77 virtual void StartArray() { w.StartArray(); }
78 virtual void EndArray() { w.EndArray(); }
79 virtual void StartObject() { w.StartObject(); }
80 virtual void EndObject() { w.EndObject(); }
81
82 explicit PlainWriterAdapter(rapidjson::StringBuffer &sb) : w(sb) {}
83};
84
85} // namespace Logging
86
87#endif /* _BACKENDS_TOFINO_BF_P4C_LOGGING_RAPIDJSON_ADAPTER_H_ */
Definition rapidjson_adapter.h:68
Definition rapidjson_adapter.h:51
Definition rapidjson_adapter.h:36
Definition filelog.h:32
rapidjson::Writer< rapidjson::StringBuffer > PlainWriter
Plain writer does not indent with whitespaces.
Definition rapidjson_adapter.h:28