JODA  0.13.1 (59b41972)
JSON On-Demand Analysis
ReaderFlags.h
Go to the documentation of this file.
1 //
2 // Created by Nico on 22/02/2019.
3 //
4 
5 #ifndef JODA_READERFLAGS_H
6 #define JODA_READERFLAGS_H
7 
9 
10 #define JODA_READER_FLAG_T JODA_FLAG_T
12  NONE = 0,
13  JSON = (1u << 0u),
14  FILE = (1u << 1u),
15  LINESEPERATED = (1u << 2u),
16  BEAUTIFUL = (1u << 3u),
17  URL = (1u << 4u),
18 
19  // URL = (1 << 2),
20  //..
21 };
22 constexpr enum ReaderFlag operator|(const enum ReaderFlag selfValue,
23  const enum ReaderFlag inValue) {
24  return (enum ReaderFlag)(JODA_READER_FLAG_T(selfValue) |
25  JODA_READER_FLAG_T(inValue));
26 }
27 
28 constexpr enum ReaderFlag operator&(const enum ReaderFlag selfValue,
29  const enum ReaderFlag inValue) {
30  return (enum ReaderFlag)(JODA_READER_FLAG_T(selfValue) &
31  JODA_READER_FLAG_T(inValue));
32 }
33 
34 namespace std {
35 template <>
36 struct hash<ReaderFlag> {
38  typedef size_t result_type;
39 
41  using type = typename std::underlying_type<argument_type>::type;
42  return std::hash<type>()(static_cast<type>(x));
43  }
44 };
45 } // namespace std
46 inline std::ostream& operator<<(std::ostream& os, const ReaderFlag& flag) {
47  if (flag == ReaderFlag::NONE) {
48  os << "NONE";
49  } else {
50  bool first = true;
51  if ((flag & ReaderFlag::JSON) == ReaderFlag::JSON) {
52  first = false;
53  os << "JSON";
54  }
55  if ((flag & ReaderFlag::FILE) == ReaderFlag::FILE) {
56  if (!first) os << "|";
57  first = false;
58  os << "FILE";
59  }
61  if (!first) os << "|";
62  first = false;
63  os << "LINESEPERATED";
64  }
66  if (!first) os << "|";
67  first = false;
68  os << "BEAUTIFUL";
69  }
70  }
71  return os;
72 }
73 
74 /*
75  * Used ReaderFlags
76  */
77 #define JODA_JSON_FILE_LINESEPERATED_READER_FLAG \
78  (ReaderFlag::JSON | ReaderFlag::FILE | ReaderFlag::LINESEPERATED)
79 #define JODA_JSON_FILE_BEAUTIFIED_READER_FLAG \
80  (ReaderFlag::JSON | ReaderFlag::FILE | ReaderFlag::BEAUTIFUL)
81 #define JODA_JSON_URL_READER_FLAG (ReaderFlag::JSON | ReaderFlag::URL)
82 
83 /*
84  * Queue Traits
85  */
86 // Basic queue trait
87 template <ReaderFlag R_FLAGS>
89  JODA_READER_QUEUE(JODA_READER_QUEUE& q) = delete; // Delete copy contructor
90 };
91 
92 struct SampleFile {
93  double sample;
94  std::string file;
95 };
96 
97 // JSON File queue
98 template <>
101  typedef JODA_SHARED_QUEUE<
104 
105  static constexpr bool hasFlag(ReaderFlag flag) {
107  }
108 
109  static constexpr ReaderFlag getFlag() {
111  }
112 
113  static std::unique_ptr<queue_t> getQueue() {
114  return std::make_unique<queue_t>();
115  }
116  static std::unique_ptr<queue_t> getQueue(size_t minCapacity,
117  size_t maxExplicitProducers,
118  size_t maxImplicitProducers = 0) {
119  return std::make_unique<queue_t>(minCapacity, maxExplicitProducers,
120  maxImplicitProducers);
121  }
122 };
123 
124 // JSON File queue
125 template <>
131 
132  static constexpr bool hasFlag(ReaderFlag flag) {
133  return (JODA_JSON_FILE_BEAUTIFIED_READER_FLAG) == flag;
134  }
135  static constexpr ReaderFlag getFlag() {
137  }
138 
139  static std::unique_ptr<queue_t> getQueue() {
140  return std::make_unique<queue_t>();
141  }
142  static std::unique_ptr<queue_t> getQueue(size_t minCapacity,
143  size_t maxExplicitProducers,
144  size_t maxImplicitProducers = 0) {
145  return std::make_unique<queue_t>(minCapacity, maxExplicitProducers,
146  maxImplicitProducers);
147  }
148 };
149 
150 struct URLPayload {
151  std::string url;
152 };
153 
154 // JSON URL queue
155 template <>
160 
161  static constexpr bool hasFlag(ReaderFlag flag) {
162  return (JODA_JSON_URL_READER_FLAG) == flag;
163  }
164 
165  static constexpr ReaderFlag getFlag() { return JODA_JSON_URL_READER_FLAG; }
166 
167  static std::unique_ptr<queue_t> getQueue() {
168  return std::make_unique<queue_t>();
169  }
170 
171  static std::unique_ptr<queue_t> getQueue(size_t minCapacity,
172  size_t maxExplicitProducers,
173  size_t maxImplicitProducers = 0) {
174  return std::make_unique<queue_t>(minCapacity, maxExplicitProducers,
175  maxImplicitProducers);
176  }
177 };
178 
179 /*
180  * Used Reader Queues
181  */
187 
188 #endif // JODA_READERFLAGS_H
#define JODA_FLAG_T
Definition: Queue.h:11
#define JODA_JSON_URL_READER_FLAG
Definition: ReaderFlags.h:81
#define JODA_JSON_FILE_BEAUTIFIED_READER_FLAG
Definition: ReaderFlags.h:79
JODA_READER_QUEUE< JODA_JSON_FILE_LINESEPERATED_READER_FLAG > JsonFileSeperatedReaderQueue
Definition: ReaderFlags.h:183
double sample
Definition: ReaderFlags.h:93
ReaderFlag
Definition: ReaderFlags.h:11
#define JODA_JSON_FILE_LINESEPERATED_READER_FLAG
Definition: ReaderFlags.h:77
std::ostream & operator<<(std::ostream &os, const ReaderFlag &flag)
Definition: ReaderFlags.h:46
std::string url
Definition: ReaderFlags.h:151
std::string file
Definition: ReaderFlags.h:94
JODA_READER_QUEUE< JODA_JSON_URL_READER_FLAG > JsonURLReaderQueue
Definition: ReaderFlags.h:186
constexpr enum ReaderFlag operator&(const enum ReaderFlag selfValue, const enum ReaderFlag inValue)
Definition: ReaderFlags.h:28
#define JODA_READER_FLAG_T
Definition: ReaderFlags.h:10
constexpr enum ReaderFlag operator|(const enum ReaderFlag selfValue, const enum ReaderFlag inValue)
Definition: ReaderFlags.h:22
JODA_READER_QUEUE< JODA_JSON_FILE_BEAUTIFIED_READER_FLAG > JsonFileBeautifiedReaderQueue
Definition: ReaderFlags.h:185
Definition: ReaderFlags.h:150
Definition: ReaderFlags.h:92
static std::unique_ptr< queue_t > getQueue(size_t minCapacity, size_t maxExplicitProducers, size_t maxImplicitProducers=0)
Definition: ReaderFlags.h:142
static constexpr bool hasFlag(ReaderFlag flag)
Definition: ReaderFlags.h:132
SampleFile payload_t
Definition: ReaderFlags.h:127
static constexpr ReaderFlag getFlag()
Definition: ReaderFlags.h:135
static std::unique_ptr< queue_t > getQueue()
Definition: ReaderFlags.h:139
static std::unique_ptr< queue_t > getQueue()
Definition: ReaderFlags.h:113
SampleFile payload_t
Definition: ReaderFlags.h:100
static constexpr ReaderFlag getFlag()
Definition: ReaderFlags.h:109
static std::unique_ptr< queue_t > getQueue(size_t minCapacity, size_t maxExplicitProducers, size_t maxImplicitProducers=0)
Definition: ReaderFlags.h:116
static constexpr bool hasFlag(ReaderFlag flag)
Definition: ReaderFlags.h:105
static constexpr ReaderFlag getFlag()
Definition: ReaderFlags.h:165
static constexpr bool hasFlag(ReaderFlag flag)
Definition: ReaderFlags.h:161
URLPayload payload_t
Definition: ReaderFlags.h:157
static std::unique_ptr< queue_t > getQueue(size_t minCapacity, size_t maxExplicitProducers, size_t maxImplicitProducers=0)
Definition: ReaderFlags.h:171
static std::unique_ptr< queue_t > getQueue()
Definition: ReaderFlags.h:167
Definition: ReaderFlags.h:88
JODA_READER_QUEUE(JODA_READER_QUEUE &q)=delete
Definition: Queue.h:19
result_type operator()(const argument_type &x) const
Definition: ReaderFlags.h:40
ReaderFlag argument_type
Definition: ReaderFlags.h:37
size_t result_type
Definition: ReaderFlags.h:38