JODA  0.13.1 (59b41972)
JSON On-Demand Analysis
ContainerFlags.h
Go to the documentation of this file.
1 //
2 // Created by Nico on 22/02/2019.
3 //
4 
5 #ifndef JODA_CONTAINERFLAGS_H
6 #define JODA_CONTAINERFLAGS_H
7 
9 #include "JSONContainer.h"
10 
11 #define JODA_CONTAINER_FLAG_T JODA_FLAG_T
13  NONE = 0,
14  JSON = (1u << 0u),
15  REF = (1u << 1u)
16  //..
17 };
18 constexpr enum ContainerFlag operator|(const enum ContainerFlag selfValue,
19  const enum ContainerFlag inValue) {
20  return (enum ContainerFlag)(JODA_CONTAINER_FLAG_T(selfValue) |
21  JODA_CONTAINER_FLAG_T(inValue));
22 }
23 
24 constexpr enum ContainerFlag operator&(const enum ContainerFlag selfValue,
25  const enum ContainerFlag inValue) {
26  return (enum ContainerFlag)(JODA_CONTAINER_FLAG_T(selfValue) &
27  JODA_CONTAINER_FLAG_T(inValue));
28 }
29 namespace std {
30 template <>
31 struct hash<ContainerFlag> {
33  typedef size_t result_type;
34 
36  using type = typename std::underlying_type<argument_type>::type;
37  return std::hash<type>()(static_cast<type>(x));
38  }
39 };
40 } // namespace std
41 
42 inline std::ostream& operator<<(std::ostream& os, const ContainerFlag& flag) {
43  if (flag == ContainerFlag::NONE) {
44  os << "NONE";
45  } else {
46  bool first = true;
47  if ((flag & ContainerFlag::JSON) == ContainerFlag::JSON) {
48  first = false;
49  os << "JSON";
50  }
51  if ((flag & ContainerFlag::REF) == ContainerFlag::REF) {
52  if (!first) os << "|";
53  first = false;
54  os << "REF";
55  }
56  }
57  return os;
58 }
59 
60 /*
61  * Used ContainerFlags
62  */
63 #define JODA_JSON_CONTAINER_FLAG (ContainerFlag::JSON)
64 #define JODA_JSON_CONTAINER_REF_FLAG (ContainerFlag::JSON | ContainerFlag::REF)
65 
66 /*
67  * Queue Traits
68  */
69 // Basic queue trait
70 template <ContainerFlag R_FLAGS>
73  delete; // Delete copy contructor
74 };
75 
76 // JSON Container queue
77 template <>
79  typedef std::unique_ptr<JSONContainer> payload_t;
82 
83  static constexpr bool hasFlag(ContainerFlag flag) {
84  return (JODA_JSON_CONTAINER_FLAG) == flag;
85  }
86 
87  static constexpr ContainerFlag getFlag() { return JODA_JSON_CONTAINER_FLAG; }
88 
89  static std::unique_ptr<queue_t> getQueue() {
90  return std::make_unique<queue_t>();
91  }
92  static std::unique_ptr<queue_t> getQueue(size_t minCapacity,
93  size_t maxExplicitProducers,
94  size_t maxImplicitProducers = 0) {
95  return std::make_unique<queue_t>(minCapacity, maxExplicitProducers,
96  maxImplicitProducers);
97  }
98 };
99 
100 // JSON Container Reference queue
101 template <>
107 
108  static constexpr bool hasFlag(ContainerFlag flag) {
109  return (JODA_JSON_CONTAINER_REF_FLAG) == flag;
110  }
111 
112  static constexpr ContainerFlag getFlag() {
114  }
115 
116  static std::unique_ptr<queue_t> getQueue() {
117  return std::make_unique<queue_t>();
118  }
119  static std::unique_ptr<queue_t> getQueue(size_t minCapacity,
120  size_t maxExplicitProducers,
121  size_t maxImplicitProducers = 0) {
122  return std::make_unique<queue_t>(minCapacity, maxExplicitProducers,
123  maxImplicitProducers);
124  }
125 };
126 
127 /*
128  * Used Container Queues
129  */
133 
134 #endif // JODA_CONTAINERFLAGS_H
std::ostream & operator<<(std::ostream &os, const ContainerFlag &flag)
Definition: ContainerFlags.h:42
ContainerFlag
Definition: ContainerFlags.h:12
constexpr enum ContainerFlag operator|(const enum ContainerFlag selfValue, const enum ContainerFlag inValue)
Definition: ContainerFlags.h:18
JODA_CONTAINER_QUEUE< JODA_JSON_CONTAINER_REF_FLAG > JsonContainerRefQueue
Definition: ContainerFlags.h:132
JODA_CONTAINER_QUEUE< JODA_JSON_CONTAINER_FLAG > JsonContainerQueue
Definition: ContainerFlags.h:130
constexpr enum ContainerFlag operator&(const enum ContainerFlag selfValue, const enum ContainerFlag inValue)
Definition: ContainerFlags.h:24
#define JODA_CONTAINER_FLAG_T
Definition: ContainerFlags.h:11
#define JODA_JSON_CONTAINER_FLAG
Definition: ContainerFlags.h:63
#define JODA_JSON_CONTAINER_REF_FLAG
Definition: ContainerFlags.h:64
#define JODA_FLAG_T
Definition: Queue.h:11
Definition: JSONContainer.h:37
std::unique_ptr< JSONContainer > payload_t
Definition: ContainerFlags.h:79
static constexpr bool hasFlag(ContainerFlag flag)
Definition: ContainerFlags.h:83
static constexpr ContainerFlag getFlag()
Definition: ContainerFlags.h:87
static std::unique_ptr< queue_t > getQueue(size_t minCapacity, size_t maxExplicitProducers, size_t maxImplicitProducers=0)
Definition: ContainerFlags.h:92
static std::unique_ptr< queue_t > getQueue()
Definition: ContainerFlags.h:89
JSONContainer * payload_t
Definition: ContainerFlags.h:103
static constexpr bool hasFlag(ContainerFlag flag)
Definition: ContainerFlags.h:108
static std::unique_ptr< queue_t > getQueue()
Definition: ContainerFlags.h:116
static constexpr ContainerFlag getFlag()
Definition: ContainerFlags.h:112
static std::unique_ptr< queue_t > getQueue(size_t minCapacity, size_t maxExplicitProducers, size_t maxImplicitProducers=0)
Definition: ContainerFlags.h:119
Definition: ContainerFlags.h:71
JODA_CONTAINER_QUEUE(JODA_CONTAINER_QUEUE &q)=delete
Definition: Queue.h:19
size_t result_type
Definition: ContainerFlags.h:33
ContainerFlag argument_type
Definition: ContainerFlags.h:32
result_type operator()(const argument_type &x) const
Definition: ContainerFlags.h:35