libbmq  a5f8a06ba1d16cb5a65643e1fa7f1a1d6aadef40
bmqt_queueflags.h
Go to the documentation of this file.
1 // Copyright 2014-2023 Bloomberg Finance L.P.
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 // bmqt_queueflags.h -*-C++-*-
17 #ifndef INCLUDED_BMQT_QUEUEFLAGS
18 #define INCLUDED_BMQT_QUEUEFLAGS
19 
28 
29 // BMQ
30 
31 // BDE
32 #include <bsl_iosfwd.h>
33 #include <bsl_string.h>
34 #include <bsls_types.h>
35 
36 namespace BloombergLP {
37 namespace bmqt {
38 
39 // =================
40 // struct QueueFlags
41 // =================
42 
44 struct QueueFlags {
45  // TYPES
46  enum Enum {
47  e_ADMIN = (1 << 0) // The queue is opened in admin mode (Valid only
48  // for BlazingMQ admin tasks)
49  ,
50  e_READ = (1 << 1) // The queue is opened for consuming messages
51  ,
52  e_WRITE = (1 << 2) // The queue is opened for posting messages
53  ,
54  e_ACK = (1 << 3) // Set to indicate interested in receiving
55  // 'ACK' events for all message posted
56  };
57 
58  // PUBLIC CONSTANTS
59 
64 
69 
70  // CLASS METHODS
71 
84  static bsl::ostream& print(bsl::ostream& stream,
85  QueueFlags::Enum value,
86  int level = 0,
87  int spacesPerLevel = 4);
88 
97  static const char* toAscii(QueueFlags::Enum value);
98 
103  static bool fromAscii(QueueFlags::Enum* out, const bslstl::StringRef& str);
104 };
105 
106 // FREE OPERATORS
107 
110 bsl::ostream& operator<<(bsl::ostream& stream, QueueFlags::Enum value);
111 
112 // =====================
113 // struct QueueFlagsUtil
114 // =====================
115 
117  public:
118  // CLASS METHODS
119 
126  static bool isSet(bsls::Types::Uint64 flags, QueueFlags::Enum flag);
127 
128  public:
129  // CLASS METHODS
130 
135  static bool isValid(bsl::ostream& errorDescription,
136  bsls::Types::Uint64 flags);
137 
139  static bsls::Types::Uint64 empty();
140 
142  static bool isEmpty(bsls::Types::Uint64 flags);
143 
145  static bool isReader(bsls::Types::Uint64 flags);
146 
148  static bool isWriter(bsls::Types::Uint64 flags);
149 
151  static bool isAdmin(bsls::Types::Uint64 flags);
152 
154  static bool isAck(bsls::Types::Uint64 flags);
155 
157  static void setReader(bsls::Types::Uint64* flags);
158 
160  static void setAdmin(bsls::Types::Uint64* flags);
161 
163  static void setWriter(bsls::Types::Uint64* flags);
164 
166  static void setAck(bsls::Types::Uint64* flags);
167 
169  static void unsetReader(bsls::Types::Uint64* flags);
170 
172  static void unsetAdmin(bsls::Types::Uint64* flags);
173 
175  static void unsetWriter(bsls::Types::Uint64* flags);
176 
178  static void unsetAck(bsls::Types::Uint64* flags);
179 
182  static bsls::Types::Uint64 additions(bsls::Types::Uint64 oldFlags,
183  bsls::Types::Uint64 newFlags);
184 
187  static bsls::Types::Uint64 removals(bsls::Types::Uint64 oldFlags,
188  bsls::Types::Uint64 newFlags);
189 
193  static bsl::ostream& prettyPrint(bsl::ostream& stream,
194  bsls::Types::Uint64 flags);
195 
202  static int fromString(bsl::ostream& errorDescription,
203  bsls::Types::Uint64* out,
204  const bsl::string& str);
205 };
206 
207 // ============================================================================
208 // INLINE DEFINITIONS
209 // ============================================================================
210 
211 // ---------------------
212 // struct QueueFlagsUtil
213 // ---------------------
214 
215 inline bool QueueFlagsUtil::isSet(bsls::Types::Uint64 flags,
216  QueueFlags::Enum flag)
217 {
218  return ((flags & flag) != 0);
219 }
220 
221 inline void QueueFlagsUtil::setReader(bsls::Types::Uint64* flags)
222 {
223  *flags |= bmqt::QueueFlags::e_READ;
224 }
225 
226 inline void QueueFlagsUtil::setAdmin(bsls::Types::Uint64* flags)
227 {
228  *flags |= bmqt::QueueFlags::e_ADMIN;
229 }
230 
231 inline void QueueFlagsUtil::setWriter(bsls::Types::Uint64* flags)
232 {
233  *flags |= bmqt::QueueFlags::e_WRITE;
234 }
235 
236 inline void QueueFlagsUtil::setAck(bsls::Types::Uint64* flags)
237 {
238  *flags |= bmqt::QueueFlags::e_ACK;
239 }
240 
241 inline void QueueFlagsUtil::unsetReader(bsls::Types::Uint64* flags)
242 {
243  *flags &= ~bmqt::QueueFlags::e_READ;
244 }
245 
246 inline void QueueFlagsUtil::unsetAdmin(bsls::Types::Uint64* flags)
247 {
248  *flags &= ~bmqt::QueueFlags::e_ADMIN;
249 }
250 
251 inline void QueueFlagsUtil::unsetWriter(bsls::Types::Uint64* flags)
252 {
253  *flags &= ~bmqt::QueueFlags::e_WRITE;
254 }
255 
256 inline void QueueFlagsUtil::unsetAck(bsls::Types::Uint64* flags)
257 {
258  *flags &= ~bmqt::QueueFlags::e_ACK;
259 }
260 
261 inline bool QueueFlagsUtil::isReader(bsls::Types::Uint64 flags)
262 {
263  return isSet(flags, bmqt::QueueFlags::e_READ);
264 }
265 
266 inline bool QueueFlagsUtil::isWriter(bsls::Types::Uint64 flags)
267 {
268  return isSet(flags, bmqt::QueueFlags::e_WRITE);
269 }
270 
271 inline bool QueueFlagsUtil::isAdmin(bsls::Types::Uint64 flags)
272 {
273  return isSet(flags, bmqt::QueueFlags::e_ADMIN);
274 }
275 
276 inline bool QueueFlagsUtil::isAck(bsls::Types::Uint64 flags)
277 {
278  return isSet(flags, bmqt::QueueFlags::e_ACK);
279 }
280 
281 inline bool QueueFlagsUtil::isEmpty(bsls::Types::Uint64 flags)
282 {
283  return flags == empty();
284 }
285 
286 inline bsls::Types::Uint64 QueueFlagsUtil::empty()
287 {
288  return 0;
289 }
290 
291 } // close package namespace
292 
293 // -----------------
294 // struct QueueFlags
295 // -----------------
296 
297 inline bsl::ostream& bmqt::operator<<(bsl::ostream& stream,
299 {
300  return bmqt::QueueFlags::print(stream, value, 0, -1);
301 }
302 
303 } // close enterprise namespace
304 
305 #endif
bsl::ostream & operator<<(bsl::ostream &stream, CompressionAlgorithmType::Enum value)
Definition: bmqt_compressionalgorithmtype.h:141
Definition: bmqa_abstractsession.h:42
Definition: bmqt_queueflags.h:116
static bool isReader(bsls::Types::Uint64 flags)
Returns true if the specified flags represent a reader.
Definition: bmqt_queueflags.h:261
static void unsetWriter(bsls::Types::Uint64 *flags)
Resets the specified flags representation for writer.
Definition: bmqt_queueflags.h:251
static bsl::ostream & prettyPrint(bsl::ostream &stream, bsls::Types::Uint64 flags)
static void setWriter(bsls::Types::Uint64 *flags)
Sets the specified flags representation for writer.
Definition: bmqt_queueflags.h:231
static bool isValid(bsl::ostream &errorDescription, bsls::Types::Uint64 flags)
static bool isWriter(bsls::Types::Uint64 flags)
Returns true if the specified flags represent a writer.
Definition: bmqt_queueflags.h:266
static void setAdmin(bsls::Types::Uint64 *flags)
Sets the specified flags representation for admin.
Definition: bmqt_queueflags.h:226
static bool isSet(bsls::Types::Uint64 flags, QueueFlags::Enum flag)
Definition: bmqt_queueflags.h:215
static void unsetReader(bsls::Types::Uint64 *flags)
Resets the specified flags representation for reader.
Definition: bmqt_queueflags.h:241
static void unsetAdmin(bsls::Types::Uint64 *flags)
Resets the specified flags representation for admin.
Definition: bmqt_queueflags.h:246
static bool isAck(bsls::Types::Uint64 flags)
Returns true if the specified flags represent ack required.
Definition: bmqt_queueflags.h:276
static bool isAdmin(bsls::Types::Uint64 flags)
Returns true if the specified flags represent an admin.
Definition: bmqt_queueflags.h:271
static bsls::Types::Uint64 removals(bsls::Types::Uint64 oldFlags, bsls::Types::Uint64 newFlags)
static int fromString(bsl::ostream &errorDescription, bsls::Types::Uint64 *out, const bsl::string &str)
static void setAck(bsls::Types::Uint64 *flags)
Sets the specified flags representation for ack.
Definition: bmqt_queueflags.h:236
static bool isEmpty(bsls::Types::Uint64 flags)
Returns true if the specified flags have the empty value.
Definition: bmqt_queueflags.h:281
static bsls::Types::Uint64 additions(bsls::Types::Uint64 oldFlags, bsls::Types::Uint64 newFlags)
static void unsetAck(bsls::Types::Uint64 *flags)
Resets the specified flags representation for ack.
Definition: bmqt_queueflags.h:256
static bsls::Types::Uint64 empty()
The empty value for flags.
Definition: bmqt_queueflags.h:286
static void setReader(bsls::Types::Uint64 *flags)
Sets the specified flags representation for reader.
Definition: bmqt_queueflags.h:221
This enum represents queue flags.
Definition: bmqt_queueflags.h:44
static const int k_LOWEST_SUPPORTED_QUEUE_FLAG
Definition: bmqt_queueflags.h:63
static const char * toAscii(QueueFlags::Enum value)
static bsl::ostream & print(bsl::ostream &stream, QueueFlags::Enum value, int level=0, int spacesPerLevel=4)
Enum
Definition: bmqt_queueflags.h:46
@ e_ACK
Definition: bmqt_queueflags.h:54
@ e_ADMIN
Definition: bmqt_queueflags.h:47
@ e_WRITE
Definition: bmqt_queueflags.h:52
@ e_READ
Definition: bmqt_queueflags.h:50
static const int k_HIGHEST_SUPPORTED_QUEUE_FLAG
Definition: bmqt_queueflags.h:68
static bool fromAscii(QueueFlags::Enum *out, const bslstl::StringRef &str)