JODA  0.13.1 (59b41972)
JSON On-Demand Analysis
ParserFlags.h
Go to the documentation of this file.
1 //
2 // Created by Nico on 22/02/2019.
3 //
4 
5 #ifndef JODA_PARSERFLAGS_H
6 #define JODA_PARSERFLAGS_H
7 
10 #include <joda/document/IOrigin.h>
11 
12 #define JODA_PARSER_FLAG_T JODA_FLAG_T
14  NONE = 0,
15  JSON = (1u << 0u),
16  TEXT = (1u << 1u),
17  MEMORY = (1u << 2u),
18  STREAM = (1u << 3u),
19 
20  // XML = (1 << 1)
21  // URL = (1 << 2),
22  //..
23 };
24 
25 constexpr enum ParserFlag operator|(const enum ParserFlag selfValue,
26  const enum ParserFlag inValue) {
27  return (enum ParserFlag)(JODA_PARSER_FLAG_T(selfValue) |
28  JODA_PARSER_FLAG_T(inValue));
29 }
30 
31 constexpr enum ParserFlag operator&(const enum ParserFlag selfValue,
32  const enum ParserFlag inValue) {
33  return (enum ParserFlag)(JODA_PARSER_FLAG_T(selfValue) &
34  JODA_PARSER_FLAG_T(inValue));
35 }
36 
37 namespace std {
38 template <>
39 struct hash<ParserFlag> {
41  typedef size_t result_type;
42 
44  using type = typename std::underlying_type<argument_type>::type;
45  return std::hash<type>()(static_cast<type>(x));
46  }
47 };
48 } // namespace std
49 
50 inline std::ostream& operator<<(std::ostream& os, const ParserFlag& flag) {
51  if (flag == ParserFlag::NONE) {
52  os << "NONE";
53  } else {
54  bool first = true;
55  if ((flag & ParserFlag::JSON) == ParserFlag::JSON) {
56  first = false;
57  os << "JSON";
58  }
59  if ((flag & ParserFlag::TEXT) == ParserFlag::TEXT) {
60  if (!first) os << "|";
61  first = false;
62  os << "TEXT";
63  }
64  if ((flag & ParserFlag::MEMORY) == ParserFlag::MEMORY) {
65  if (!first) os << "|";
66  first = false;
67  os << "MEMORY";
68  }
69  if ((flag & ParserFlag::STREAM) == ParserFlag::STREAM) {
70  if (!first) os << "|";
71  first = false;
72  os << "STREAM";
73  }
74  }
75  return os;
76 }
77 
78 /*
79  * Used ParserFlags
80  */
81 #define JODA_JSON_TEXT_PARSER_FLAG \
82  (ParserFlag::JSON | ParserFlag::TEXT | ParserFlag::MEMORY)
83 #define JODA_JSON_TEXT_STREAM_PARSER_FLAG \
84  (ParserFlag::JSON | ParserFlag::TEXT | ParserFlag::STREAM)
85 
86 /*
87  * Queue Traits
88  */
89 // Basic queue trait
90 template <ParserFlag R_FLAGS>
92  JODA_PARSER_QUEUE(JODA_PARSER_QUEUE& q) = delete; // Delete copy contructor
93 };
94 
96  static const size_t BLOCK_SIZE = 256; // Use bigger blocks
97 };
98 // JSON Text queue
99 template <>
101  typedef std::pair<std::unique_ptr<IOrigin>, std::string> payload_t;
105 
106  static constexpr bool hasFlag(ParserFlag flag) {
107  return (JODA_JSON_TEXT_PARSER_FLAG) == flag;
108  }
109  static constexpr ParserFlag getFlag() { return JODA_JSON_TEXT_PARSER_FLAG; }
110 
111  static std::unique_ptr<queue_t> getQueue() {
112  return std::make_unique<queue_t>();
113  }
114  static std::unique_ptr<queue_t> getQueue(size_t minCapacity,
115  size_t maxExplicitProducers,
116  size_t maxImplicitProducers = 0) {
117  return std::make_unique<queue_t>(minCapacity, maxExplicitProducers,
118  maxImplicitProducers);
119  }
120 };
121 
122 // JSON Text Stream queue
123 template <>
125  typedef std::pair<std::unique_ptr<IDPositionOrigin>,
126  std::unique_ptr<std::basic_istream<char>>>
132 
133  static constexpr bool hasFlag(ParserFlag flag) {
134  return (JODA_JSON_TEXT_STREAM_PARSER_FLAG) == flag;
135  }
136 
137  static constexpr ParserFlag getFlag() {
139  }
140 
141  static std::unique_ptr<queue_t> getQueue() {
142  return std::make_unique<queue_t>();
143  }
144 
145  static std::unique_ptr<queue_t> getQueue(size_t minCapacity,
146  size_t maxExplicitProducers,
147  size_t maxImplicitProducers = 0) {
148  return std::make_unique<queue_t>(minCapacity, maxExplicitProducers,
149  maxImplicitProducers);
150  }
151 };
152 
153 /*
154  * Used Parser Queues
155  */
159 
160 #endif // JODA_PARSERFLAGS_H
#define JODA_JSON_TEXT_PARSER_FLAG
Definition: ParserFlags.h:81
JODA_PARSER_QUEUE< JODA_JSON_TEXT_PARSER_FLAG > JsonTextParserQueue
Definition: ParserFlags.h:156
JODA_PARSER_QUEUE< JODA_JSON_TEXT_STREAM_PARSER_FLAG > JsonTextStreamParserQueue
Definition: ParserFlags.h:158
#define JODA_JSON_TEXT_STREAM_PARSER_FLAG
Definition: ParserFlags.h:83
#define JODA_PARSER_FLAG_T
Definition: ParserFlags.h:12
ParserFlag
Definition: ParserFlags.h:13
std::ostream & operator<<(std::ostream &os, const ParserFlag &flag)
Definition: ParserFlags.h:50
constexpr enum ParserFlag operator&(const enum ParserFlag selfValue, const enum ParserFlag inValue)
Definition: ParserFlags.h:31
constexpr enum ParserFlag operator|(const enum ParserFlag selfValue, const enum ParserFlag inValue)
Definition: ParserFlags.h:25
#define JODA_FLAG_T
Definition: Queue.h:11
static constexpr ParserFlag getFlag()
Definition: ParserFlags.h:109
static std::unique_ptr< queue_t > getQueue(size_t minCapacity, size_t maxExplicitProducers, size_t maxImplicitProducers=0)
Definition: ParserFlags.h:114
static constexpr bool hasFlag(ParserFlag flag)
Definition: ParserFlags.h:106
static std::unique_ptr< queue_t > getQueue()
Definition: ParserFlags.h:111
std::pair< std::unique_ptr< IOrigin >, std::string > payload_t
Definition: ParserFlags.h:101
static constexpr bool hasFlag(ParserFlag flag)
Definition: ParserFlags.h:133
static std::unique_ptr< queue_t > getQueue()
Definition: ParserFlags.h:141
static std::unique_ptr< queue_t > getQueue(size_t minCapacity, size_t maxExplicitProducers, size_t maxImplicitProducers=0)
Definition: ParserFlags.h:145
static constexpr ParserFlag getFlag()
Definition: ParserFlags.h:137
std::pair< std::unique_ptr< IDPositionOrigin >, std::unique_ptr< std::basic_istream< char > > > payload_t
Definition: ParserFlags.h:127
Definition: ParserFlags.h:91
JODA_PARSER_QUEUE(JODA_PARSER_QUEUE &q)=delete
Definition: Queue.h:19
Definition: ParserFlags.h:95
static const size_t BLOCK_SIZE
Definition: ParserFlags.h:96
Definition: concurrentqueue.h:349
ParserFlag argument_type
Definition: ParserFlags.h:40
size_t result_type
Definition: ParserFlags.h:41
result_type operator()(const argument_type &x) const
Definition: ParserFlags.h:43