BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlt_dayofweekset.h
Go to the documentation of this file.
1/// @file bdlt_dayofweekset.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdlt_dayofweekset.h -*-C++-*-
8#ifndef INCLUDED_BDLT_DAYOFWEEKSET
9#define INCLUDED_BDLT_DAYOFWEEKSET
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdlt_dayofweekset bdlt_dayofweekset
15/// @brief Provide an ordered set of (unique) `bdlt::DayOfWeek::Enum` values.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdlt
19/// @{
20/// @addtogroup bdlt_dayofweekset
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdlt_dayofweekset-purpose"> Purpose</a>
25/// * <a href="#bdlt_dayofweekset-classes"> Classes </a>
26/// * <a href="#bdlt_dayofweekset-description"> Description </a>
27/// * <a href="#bdlt_dayofweekset-supplementary-overloaded-operators"> Supplementary Overloaded Operators </a>
28/// * <a href="#bdlt_dayofweekset-usage"> Usage </a>
29/// * <a href="#bdlt_dayofweekset-example-1-manipulation-and-traversal-of-day-of-week-sets"> Example 1: Manipulation and Traversal of Day of Week Sets </a>
30///
31/// # Purpose {#bdlt_dayofweekset-purpose}
32/// Provide an ordered set of (unique) `bdlt::DayOfWeek::Enum` values.
33///
34/// # Classes {#bdlt_dayofweekset-classes}
35///
36/// - bdlt::DayOfWeekSet: ordered set of (unique) `bdlt::DayOfWeek::Enum` values
37///
38/// @see bdlt_dayofweek
39///
40/// # Description {#bdlt_dayofweekset-description}
41/// This component implements an efficient value-semantic, ordered
42/// set class, `bdlt::DayOfWeekSet`, for elements of the `bdlt::DayOfWeek::Enum`
43/// enumeration. As there are only seven possible element values, asymptotic
44/// performance characterization is not appropriate; all operations implicitly
45/// run in constant time and provide the no-throw guarantee.
46///
47/// ## Supplementary Overloaded Operators {#bdlt_dayofweekset-supplementary-overloaded-operators}
48///
49///
50/// In addition to the standard value-semantic operators `=`, `==`, `!=`, and
51/// `<<`, the following canonical set of binary and unary (free) operators are
52/// defined on `bdlt::DayOfWeekSet` objects:
53/// @code
54/// set S: { e_MON, e_TUE, e_WED }
55/// set T: { e_MON, e_WED, e_FRI }
56///
57/// Union: S | T { e_MON, e_TUE, e_WED, e_FRI }
58///
59/// Intersection: S & T { e_MON, e_WED }
60///
61/// Exclusive Or: S ^ T { e_TUE, e_FRI }
62///
63/// Subtraction: S - T { e_TUE }
64/// T - S { e_FRI }
65///
66/// Unary Negation: ~S { e_SUN, e_THU, e_FRI, e_SAT }
67/// ~T { e_SUN, e_TUE, e_THU, e_SAT }
68/// @endcode
69/// The corresponding assignment (member) operators `|=` , `&=`, `^=`, and `-=`
70/// (but not `~=`) are also provided.
71///
72/// ## Usage {#bdlt_dayofweekset-usage}
73///
74///
75/// This section illustrates intended use of this component.
76///
77/// ### Example 1: Manipulation and Traversal of Day of Week Sets {#bdlt_dayofweekset-example-1-manipulation-and-traversal-of-day-of-week-sets}
78///
79///
80/// A `bdlt::DayOfWeekSet` is useful for recording recurring appointments, or
81/// special days (e.g., weekend days), in a calendar. The following snippets of
82/// code illustrate how to create and use a `bdlt::DayOfWeek` set.
83///
84/// First, we create a couple of commonly useful sets. First we define the
85/// `bdlt::DayOfWeekSet` `weekendDays`:
86/// @code
87/// bdlt::DayOfWeekSet weekendDays;
88/// @endcode
89/// Then, we notice that this set is initially empty.
90/// @code
91/// assert(0 == weekendDays.length());
92/// @endcode
93/// Next, we add the days that characterize weekends:
94/// @code
95/// weekendDays.add(bdlt::DayOfWeek::e_SUN);
96/// assert(1 == weekendDays.length());
97///
98/// weekendDays.add(bdlt::DayOfWeek::e_SAT);
99/// assert(2 == weekendDays.length());
100/// @endcode
101/// Then, we observe that `weekendDays` now contains precisely the days we
102/// expect it to contain:
103/// @code
104/// assert(true == weekendDays.isMember(bdlt::DayOfWeek::e_SUN));
105/// assert(false == weekendDays.isMember(bdlt::DayOfWeek::e_MON));
106/// assert(false == weekendDays.isMember(bdlt::DayOfWeek::e_TUE));
107/// assert(false == weekendDays.isMember(bdlt::DayOfWeek::e_WED));
108/// assert(false == weekendDays.isMember(bdlt::DayOfWeek::e_THU));
109/// assert(false == weekendDays.isMember(bdlt::DayOfWeek::e_FRI));
110/// assert(true == weekendDays.isMember(bdlt::DayOfWeek::e_SAT));
111/// @endcode
112/// Next, we create the complementary `bdlt::DayOfWeekSet` `weekDays` directly
113/// from `weekendDays` via a combination of unary negation and copy
114/// construction:
115/// @code
116/// bdlt::DayOfWeekSet weekDays(~weekendDays);
117///
118/// assert(5 == weekDays.length());
119///
120/// assert(false == weekDays.isMember(bdlt::DayOfWeek::e_SUN));
121/// assert(true == weekDays.isMember(bdlt::DayOfWeek::e_MON));
122/// assert(true == weekDays.isMember(bdlt::DayOfWeek::e_TUE));
123/// assert(true == weekDays.isMember(bdlt::DayOfWeek::e_WED));
124/// assert(true == weekDays.isMember(bdlt::DayOfWeek::e_THU));
125/// assert(true == weekDays.isMember(bdlt::DayOfWeek::e_FRI));
126/// assert(false == weekDays.isMember(bdlt::DayOfWeek::e_SAT));
127/// @endcode
128/// Then, to create a set containing all of the days in the week, we do so via
129/// unary negation of the default constructed value:
130/// @code
131/// const bdlt::DayOfWeekSet NO_DAYS;
132/// const bdlt::DayOfWeekSet ALL_DAYS(~NO_DAYS);
133///
134/// assert(7 == ALL_DAYS.length());
135/// @endcode
136/// Next, we observe that neither `weekDays` nor `weekendDays` represent the
137/// same value as `ALL_DAYS`, but their union does:
138/// @code
139/// assert(ALL_DAYS != weekendDays);
140/// assert(ALL_DAYS != weekDays);
141/// assert(ALL_DAYS == (weekDays | weekendDays));
142/// assert(ALL_DAYS == (weekDays ^ weekendDays));
143///
144/// assert(weekendDays == ALL_DAYS - weekDays);
145///
146/// assert(weekDays == ALL_DAYS - weekendDays);
147///
148/// assert(weekDays == ALL_DAYS - weekendDays);
149/// @endcode
150/// Then, we observe that similarly, neither `weekDays` nor `weekendDays`
151/// represents the same value as `NO_DAYS`, but their intersection does:
152/// @code
153/// assert(NO_DAYS != weekendDays);
154/// assert(NO_DAYS != weekDays);
155/// assert(NO_DAYS == (weekDays & weekendDays));
156///
157/// assert(weekendDays == weekendDays - weekDays);
158///
159/// assert(weekDays == weekDays - weekendDays);
160/// @endcode
161/// Next, we create the corresponding set `eDays` consisting of the only days of
162/// the week that have an `E` in them: `TUESDAY` and `WEDNESDAY`:
163/// @code
164/// bdlt::DayOfWeekSet eDays; assert(0 == eDays.length());
165/// eDays.add(bdlt::DayOfWeek::e_TUE); assert(1 == eDays.length());
166/// eDays.add(bdlt::DayOfWeek::e_WED); assert(2 == eDays.length());
167///
168/// assert(false == eDays.isMember(bdlt::DayOfWeek::e_SUN));
169/// assert(false == eDays.isMember(bdlt::DayOfWeek::e_MON));
170/// assert(true == eDays.isMember(bdlt::DayOfWeek::e_TUE));
171/// assert(true == eDays.isMember(bdlt::DayOfWeek::e_WED));
172/// assert(false == eDays.isMember(bdlt::DayOfWeek::e_THU));
173/// assert(false == eDays.isMember(bdlt::DayOfWeek::e_FRI));
174/// assert(false == eDays.isMember(bdlt::DayOfWeek::e_SAT));
175/// @endcode
176/// Then, we create a set consisting of days that have an `n` in them: `MONDAY`,
177/// `WEDNESDAY`, and `SUNDAY`. We create the corresponding set `nDays` starting
178/// with the value of `eDays` by first removing `TUESDAY`, and then adding
179/// `SUNDAY` and `MONDAY`:
180/// @code
181/// bdlt::DayOfWeekSet nDays(eDays); assert(2 == nDays.length());
182///
183/// nDays.remove(bdlt::DayOfWeek::e_TUE); assert(1 == nDays.length());
184///
185/// nDays.add(bdlt::DayOfWeek::e_SUN); assert(2 == nDays.length());
186/// nDays.add(bdlt::DayOfWeek::e_MON); assert(3 == nDays.length());
187///
188/// assert(true == nDays.isMember(bdlt::DayOfWeek::e_SUN));
189/// assert(true == nDays.isMember(bdlt::DayOfWeek::e_MON));
190/// assert(false == nDays.isMember(bdlt::DayOfWeek::e_TUE));
191/// assert(true == nDays.isMember(bdlt::DayOfWeek::e_WED));
192/// assert(false == nDays.isMember(bdlt::DayOfWeek::e_THU));
193/// assert(false == nDays.isMember(bdlt::DayOfWeek::e_FRI));
194/// assert(false == nDays.isMember(bdlt::DayOfWeek::e_SAT));
195/// @endcode
196/// Next, we observe that all `eDays` are `weekDays`, but that's not true of
197/// `nDays`:
198/// @code
199/// assert(true == weekDays.areMembers(eDays));
200/// assert(false == weekDays.areMembers(nDays));
201/// @endcode
202/// Now, we observe that iteration order is defined by increasing enumerated
203/// `bdlt::DayOfWeek::Day` value `[ SUN .. SAT ]`. The following use of the
204/// *forward* (bi-directional) iterator:
205/// @code
206/// for (bdlt::DayOfWeekSet::iterator it = ALL_DAYS.begin();
207/// it != ALL_DAYS.end();
208/// ++it) {
209/// bsl::cout << *it << bsl::endl;
210/// }
211/// @endcode
212/// produces:
213/// @code
214/// SUN
215/// MON
216/// TUE
217/// WED
218/// THU
219/// FRI
220/// SAT
221/// @endcode
222/// on standard output.
223///
224/// Finally, we observe that, similarly, the following use of the *reverse*
225/// iterator:
226/// @code
227/// for (bdlt::DayOfWeekSet::reverse_iterator it = weekDays.rbegin();
228/// it != weekDays.rend();
229/// ++it) {
230/// bsl::cout << *it << bsl::endl;
231/// }
232/// @endcode
233/// produces:
234/// @code
235/// FRI
236/// THU
237/// WED
238/// TUE
239/// MON
240/// @endcode
241/// @}
242/** @} */
243/** @} */
244
245/** @addtogroup bdl
246 * @{
247 */
248/** @addtogroup bdlt
249 * @{
250 */
251/** @addtogroup bdlt_dayofweekset
252 * @{
253 */
254
255#include <bdlscm_version.h>
256
257#include <bdlt_dayofweek.h>
258
259#include <bdlb_bitutil.h>
260
261#include <bslh_hash.h>
262
265
266#include <bsls_assert.h>
267#include <bsls_libraryfeatures.h>
268#include <bsls_review.h>
269
270#include <bsl_cstddef.h>
271#include <bsl_iosfwd.h>
272#include <bsl_iterator.h>
273
274
275namespace bdlt {
276
277 // =======================
278 // class DayOfWeekSet_Iter
279 // =======================
280
281/// Implementation of standard bidirectional iterator for `DayOfWeekSet`.
282/// Any modification of a `DayOfWeekSet` will invalidate any iterators
283/// referring to that `DayOfWeekSet`.
285#if defined(BSLS_LIBRARYFEATURES_STDCPP_LIBCSTD)
286// Sun CC workaround: iterators must be derived from 'std::iterator' to work
287// with the native std library algorithms. However, 'std::iterator' is
288// deprecated in C++17, so do not rely on derivation unless required, to avoid
289// deprecation warnings on modern compilers.
290 : public bsl::iterator<bsl::bidirectional_iterator_tag,
291 const DayOfWeek::Enum>
292#endif // BSLS_LIBRARYFEATURES_STDCPP_LIBCSTD
293{
294
295 public:
296 // PUBLIC TYPES
297 typedef bsl::bidirectional_iterator_tag iterator_category;
299 typedef bsl::ptrdiff_t difference_type;
300 typedef const DayOfWeek::Enum *pointer;
302
303 // CLASS DATA
304 static const DayOfWeek::Enum s_dayOfWeekArray[9]; // = { ???, SUN, ...
305
306 // DATA
307 unsigned char d_data; // copy of days of the week from the original
308 // container
309 signed char d_index; // current position in the iteration; value
310 // '[0 .. 8]'
311
312 // FRIENDS
313 friend bool operator==(const DayOfWeekSet_Iter&, const DayOfWeekSet_Iter&);
314
315 public:
316 // CREATORS
317
318 /// Create a default (invalid) iterator.
320
321 /// Create an iterator using the specified `data` and `index`. If
322 /// `index` is 1, this iterator references the first valid element of
323 /// `data`; if `index` is 8, then this iterator references one past the
324 /// last possible element in `data`. The behavior is undefined unless
325 /// `0 == (data & 1)`, `index >= 0`, and `index <= 8`.
326 DayOfWeekSet_Iter(int data, int index);
327
328 /// Create an iterator having the value of the specified `original`
329 /// iterator.
330 DayOfWeekSet_Iter(const DayOfWeekSet_Iter& original);
331
332 /// Destroy this iterator.
334
335 // MANIPULATORS
336
337 /// Assign to this iterator the value of the specified `rhs` iterator,
338 /// and return a reference providing modifiable access to this iterator.
340
341 /// Advance this iterator to the next valid data element, and return a
342 /// reference providing modifiable access to this iterator. If there is
343 /// no next valid data element, this iterator will be set equal to
344 /// `end()`.
346
347 /// Advance this iterator to the next valid data element, and return by
348 /// value the value of this iterator before it was incremented. If
349 /// there is no next valid data element, this iterator will be set equal
350 /// to `end()`.
352
353 /// Regress this iterator to the previous valid data element, and return
354 /// a reference providing modifiable access to this iterator. If there
355 /// is no preceding data element, the value of `reverse_iterator(*this)`
356 /// will be `rend()`.
358
359 /// Regress this iterator to the previous valid data element, and return
360 /// by value the value of this iterator before it was decremented. If
361 /// there is no preceding data element, the value of
362 /// `reverse_iterator(*this)` will be `rend()`.
364
365 // ACCESSORS
366
367 /// Return a reference providing non-modifiable access to the day of
368 /// week value referenced by this iterator. The behavior is undefined
369 /// unless the iterator refers to a valid day of the week, specifically,
370 /// the behavior is undefined if `*this == end()`.
371 const DayOfWeek::Enum& operator*() const;
372};
373
374// FREE OPERATORS
375
376/// Return `true` if the specified `lhs` and `rhs` iterators have the same
377/// value, and `false` otherwise. Two iterators have the same value if they
378/// refer to data at the same index position. The behavior is undefined
379/// unless `lhs` and `rhs` both reference into the same set of data.
380bool operator==(const DayOfWeekSet_Iter& lhs, const DayOfWeekSet_Iter& rhs);
381
382/// Return `true` if the specified `lhs` and `rhs` iterators do not have the
383/// same value, and `false` otherwise. Two iterators do not have the same
384/// value if they do not refer to data at the same index position. The
385/// behavior is undefined unless `lhs` and `rhs` both reference into the
386/// same set of data.
387bool operator!=(const DayOfWeekSet_Iter& lhs, const DayOfWeekSet_Iter& rhs);
388
389 // ==================
390 // class DayOfWeekSet
391 // ==================
392
393/// This class implements an efficient value-semantic, ordered set of
394/// `DayOfWeek` values. This set requires a fixed capacity, and all
395/// operations operate in constant time, and provide the no-throw guarantee.
396///
397/// See @ref bdlt_dayofweekset
399
400 // DATA
401 unsigned char d_days; // bits '1 .. 7' reflect '[ SUN, MON, ..., SAT ]';
402 // bit 0 is unused
403
404 // FRIENDS
405 friend bool operator==(const DayOfWeekSet&, const DayOfWeekSet&);
406 friend bool operator!=(const DayOfWeekSet&, const DayOfWeekSet&);
408 template <class HASHALG>
409 friend void hashAppend(HASHALG& hashAlg, const DayOfWeekSet&);
410
411 public:
412 // TYPES
413
414 /// Standard nested alias for set container's iterator.
416
417 /// Standard nested alias for set container's constant iterator.
419
420 /// Standard nested alias for set container's reverse iterator.
421 typedef bsl::reverse_iterator<iterator> reverse_iterator;
422
423 /// Standard nested alias for set container's constant reverse iterator.
425
426 // CLASS METHODS
427
428 // Aspects
429
430 /// Return the maximum valid BDEX format version, as indicated by the
431 /// specified `versionSelector`, to be passed to the `bdexStreamOut`
432 /// method. Note that it is highly recommended that `versionSelector`
433 /// be formatted as "YYYYMMDD", a date representation. Also note that
434 /// `versionSelector` should be a *compile*-time-chosen value that
435 /// selects a format version supported by both externalizer and
436 /// unexternalizer. See the `bslx` package-level documentation for more
437 /// information on BDEX streaming of value-semantic types and
438 /// containers.
439 static int maxSupportedBdexVersion(int versionSelector);
440
441 // CREATORS
442
443 /// Create an empty set.
444 DayOfWeekSet();
445
446 /// Create a set initialized to the value of the specified `original`
447 /// set.
448 DayOfWeekSet(const DayOfWeekSet& original);
449
450 /// Destroy this object.
452
453 // MANIPULATORS
454
455 /// Assign to this set the value of the specified `rhs` set, and return
456 /// a reference providing modifiable access to this set.
458
459 /// Assign to this set the union of this set with the specified `rhs`
460 /// set (i.e., a set containing elements that are in either this set or
461 /// the `rhs` set, or in both sets), and return a reference providing
462 /// modifiable access to this set.
464
465 /// Assign to this set the intersection of this set with the specified
466 /// `rhs` set (i.e., a set containing elements that are in both this
467 /// set and the `rhs` set), and return a reference providing modifiable
468 /// access to this set.
470
471 /// Assign to this set the exclusive-or of this set with the specified
472 /// `rhs` set (i.e., a set containing elements that are either in this
473 /// set, but not `rhs`, or in `rhs`, but not in this set), and return a
474 /// reference providing modifiable access to this set.
476
477 /// Assign to this set the subtraction of the specified `rhs` set from
478 /// this set (i.e., a set containing elements that are in this set, but
479 /// not in the `rhs` set), and return a reference providing modifiable
480 /// access to this set.
482
483 /// Add the specified `value` to this set.
484 void add(DayOfWeek::Enum value);
485
486 /// Remove the specified `value` from this set. Return `true` if
487 /// `value` was a member of this set, and `false` otherwise.
488 bool remove(DayOfWeek::Enum value);
489
490 /// Remove all members of this set.
491 void removeAll();
492
493 // Aspects
494
495 /// Assign to this object the value read from the specified input
496 /// `stream` using the specified `version` format, and return a
497 /// reference to `stream`. If `stream` is initially invalid, this
498 /// operation has no effect. If `version` is not supported, this object
499 /// is unaltered and `stream` is invalidated, but otherwise unmodified.
500 /// If `version` is supported but `stream` becomes invalid during this
501 /// operation, this object has an undefined, but valid, state. Note
502 /// that no version is read from `stream`. See the `bslx` package-level
503 /// documentation for more information on BDEX streaming of
504 /// value-semantic types and containers.
505 template <class STREAM>
506 STREAM& bdexStreamIn(STREAM& stream, int version);
507
508 // ACCESSORS
509
510 /// Return `true` if this set contains all elements of the specified
511 /// `set`, and `false` otherwise.
512 bool areMembers(const DayOfWeekSet& set) const;
513
514 /// Return an iterator referencing the first valid element in this set.
515 iterator begin() const;
516
517 /// Return an iterator indicating one position past the last possible
518 /// element in this set.
519 iterator end() const;
520
521 /// Return `true` if there are no elements in this set, and `false`
522 /// otherwise.
523 bool isEmpty() const;
524
525 /// Return `true` if the specified `value` is an element of this set,
526 /// and `false` otherwise.
527 bool isMember(DayOfWeek::Enum value) const;
528
529 /// Return the number of elements in this set.
530 int length() const;
531
532 /// Return a reverse iterator referencing the last valid element in this
533 /// set.
534 reverse_iterator rbegin() const;
535
536 /// Return a reverse iterator indicating one position before the first
537 /// possible element in this set.
538 reverse_iterator rend() const;
539
540 // Aspects
541
542 /// Write the value of this object, using the specified `version`
543 /// format, to the specified output `stream`, and return a reference to
544 /// `stream`. If `stream` is initially invalid, this operation has no
545 /// effect. If `version` is not supported, `stream` is invalidated, but
546 /// otherwise unmodified. Note that `version` is not written to
547 /// `stream`. See the `bslx` package-level documentation for more
548 /// information on BDEX streaming of value-semantic types and
549 /// containers.
550 template <class STREAM>
551 STREAM& bdexStreamOut(STREAM& stream, int version) const;
552
553 /// Format this object to the specified output `stream` at the (absolute
554 /// value of) the optionally specified indentation `level`, and return a
555 /// reference to `stream`. If `level` is specified, optionally specify
556 /// `spacesPerLevel`, the number of spaces per indentation level for
557 /// this and all of its nested objects. If `level` is negative,
558 /// suppress indentation of the first line. If `spacesPerLevel` is
559 /// negative, format the entire output on one line, suppressing all but
560 /// the initial indentation (as governed by `level`). If `stream` is
561 /// not valid on entry, this operation has no effect.
562 bsl::ostream& print(bsl::ostream& stream,
563 int level = 0,
564 int spacesPerLevel = 4) const;
565
566#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
567
568 /// @deprecated Use @ref maxSupportedBdexVersion(int) instead.
569 ///
570 /// Return the most current BDEX streaming version number supported by
571 /// this class.
572 static int maxSupportedBdexVersion();
573
574#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
575
576};
577
578// FREE OPERATORS
579
580/// Return a set containing the complement of the specified `set` (i.e.,
581/// those members *not* contained in `set`).
583
584/// Return a set containing the union of the specified `lhs` and `rhs` sets
585/// (i.e., a set containing elements that are in either `lhs` or `rhs` or
586/// both).
588
589/// Return a set containing the intersection of the specified `lhs` and
590/// `rhs` sets (i.e., a set containing elements that are in both `lhs` and
591/// `rhs`).
593
594/// Return a set containing the exclusive-or of the specified `lhs` and
595/// `rhs` sets (i.e., a set containing elements that are either in `lhs`,
596/// but not `rhs`, or in `rhs`, but not `lhs`).
598
599/// Return a set containing the subtraction of the specified `rhs` set from
600/// the specified `lhs` set (i.e., a set containing elements that are in
601/// `lhs`, but not in `rhs`).
603
604/// Return `true` if the specified `lhs` and `rhs` sets have the same value,
605/// and `false` otherwise. Two sets have the same value if they have the
606/// same length and all the elements of one set are members of the other
607/// set.
608bool operator==(const DayOfWeekSet& lhs, const DayOfWeekSet& rhs);
609
610/// Return `true` if the specified `lhs` and `rhs` sets do not have the same
611/// value, and `false` otherwise. Two sets do not have the same value if
612/// they differ in length or there exists an element of one set that is not
613/// a member of the other set.
614bool operator!=(const DayOfWeekSet& lhs, const DayOfWeekSet& rhs);
615
616/// Write the specified `rhs` set to the specified output `stream` in some
617/// reasonable (single-line) format, and return a reference to `stream`.
618bsl::ostream& operator<<(bsl::ostream& stream, const DayOfWeekSet& rhs);
619
620// FREE FUNCTIONS
621
622/// Pass the specified `object` to the specified `hashAlg`. This function
623/// integrates with the `bslh` modular hashing system and effectively
624/// provides a `bsl::hash` specialization for `DayOfWeekSet`.
625template <class HASHALG>
626void hashAppend(HASHALG& hashAlg, const DayOfWeekSet& object);
627
628// ============================================================================
629// INLINE DEFINITIONS
630// ============================================================================
631
632 // -----------------------
633 // class DayOfWeekSet_Iter
634 // -----------------------
635
636// CREATORS
637inline
639: d_data(0)
640, d_index(8)
641{
642}
643
644inline
646: d_data(original.d_data)
647, d_index(original.d_index)
648{
649}
650
651inline
653{
654 BSLS_ASSERT(0 == (d_data & 1)); // lsb is unused and always 0
655 BSLS_ASSERT(d_index >= 0);
656 BSLS_ASSERT(d_index <= 8);
657}
658
659// MANIPULATORS
660inline
663{
664 d_data = rhs.d_data;
665 d_index = rhs.d_index;
666 return *this;
667}
668
669inline
671{
672 DayOfWeekSet_Iter tmp(*this);
673 this->operator++();
674 return tmp;
675}
676
677inline
679{
680 DayOfWeekSet_Iter tmp(*this);
681 this->operator--();
682 return tmp;
683}
684
685// ACCESSORS
686inline
694
695} // close package namespace
696
697// FREE OPERATORS
698inline
699bool bdlt::operator==(const DayOfWeekSet_Iter& lhs,
700 const DayOfWeekSet_Iter& rhs)
701{
702 BSLS_ASSERT_SAFE(lhs.d_data == rhs.d_data);
703
704 // If the data is not the same, either the objects were not initially the
705 // same, or one has subsequently been modified.
706
707 return lhs.d_index == rhs.d_index;
708}
709
710inline
711bool bdlt::operator!=(const DayOfWeekSet_Iter& lhs,
712 const DayOfWeekSet_Iter& rhs)
713{
714 return !(lhs == rhs);
715}
716
717namespace bdlt {
718
719 // ------------------
720 // class DayOfWeekSet
721 // ------------------
722
723// CLASS METHODS
724
725 // Aspects
726
727inline
728int DayOfWeekSet::maxSupportedBdexVersion(int /* versionSelector */)
729{
730 return 1;
731}
732
733// CREATORS
734inline
736: d_days(0)
737{
738}
739
740inline
742: d_days(original.d_days)
743{
744}
745
746inline
748{
749 BSLS_ASSERT(!(d_days & 1));
750}
751
752// MANIPULATORS
753inline
755{
756 d_days = rhs.d_days;
757 return *this;
758}
759
760inline
762{
763 d_days = static_cast<unsigned char>(d_days | rhs.d_days);
764 return *this;
765}
766
767inline
769{
770 d_days = static_cast<unsigned char>(d_days & rhs.d_days);
771 return *this;
772}
773
774inline
776{
777 d_days = static_cast<unsigned char>(d_days ^ rhs.d_days);
778 return *this;
779}
780
781inline
783{
784 const int mask = d_days & rhs.d_days;
785 d_days = static_cast<unsigned char>(d_days - mask);
786 return *this;
787}
788
789inline
791{
792 d_days = static_cast<unsigned char>(d_days | (1 << value));
793}
794
795inline
797{
798 const int mask = 1 << value;
799 const bool rv = d_days & mask;
800 d_days &= static_cast<unsigned char>(~mask);
801 return rv;
802}
803
804inline
806{
807 d_days = 0;
808}
809
810 // Aspects
811
812template <class STREAM>
813STREAM& DayOfWeekSet::bdexStreamIn(STREAM& stream, int version)
814{
815 if (stream) {
816 switch (version) { // switch on the schema version
817 case 1: {
818 unsigned char tmp;
819 stream.getUint8(tmp);
820
821 if (stream && 0 == (tmp & 1)) {
822 d_days = tmp;
823 }
824 else {
825 stream.invalidate();
826 }
827 } break;
828 default: {
829 stream.invalidate(); // unrecognized version number
830 }
831 }
832 }
833 return stream;
834}
835
836// ACCESSORS
837inline
839{
840 return set.d_days == (d_days & set.d_days);
841}
842
843inline
848
849inline
854
855inline
857{
858 return 0 == d_days;
859}
860
861inline
863{
864 const int mask = 1 << value;
865 return mask == (d_days & mask);
866}
867
868inline
870{
871 return bdlb::BitUtil::numBitsSet(static_cast<unsigned int>(d_days));
872}
873
874inline
879
880inline
885
886 // Aspects
887
888template <class STREAM>
889STREAM& DayOfWeekSet::bdexStreamOut(STREAM& stream, int version) const
890{
891 if (stream) {
892 switch (version) { // switch on the schema version
893 case 1: {
894 stream.putUint8(d_days);
895 } break;
896 default: {
897 stream.invalidate(); // unrecognized version number
898 }
899 }
900 }
901 return stream;
902}
903
904#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
905
906inline
911
912#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
913
914} // close package namespace
915
916// FREE OPERATORS
917inline
918bdlt::DayOfWeekSet bdlt::operator~(const DayOfWeekSet& set)
919{
920 DayOfWeekSet tmp(set);
921 tmp.d_days = static_cast<unsigned char>(~tmp.d_days & 0xfe);
922 return tmp;
923}
924
925inline
926bool bdlt::operator==(const DayOfWeekSet& lhs, const DayOfWeekSet& rhs)
927{
928 return lhs.d_days == rhs.d_days;
929}
930
931inline
932bool bdlt::operator!=(const DayOfWeekSet& lhs, const DayOfWeekSet& rhs)
933{
934 return lhs.d_days != rhs.d_days;
935}
936
937inline
938bdlt::DayOfWeekSet bdlt::operator|(const DayOfWeekSet& lhs,
939 const DayOfWeekSet& rhs)
940{
941 return DayOfWeekSet(lhs) |= rhs;
942}
943
944inline
945bdlt::DayOfWeekSet bdlt::operator&(const DayOfWeekSet& lhs,
946 const DayOfWeekSet& rhs)
947{
948 return DayOfWeekSet(lhs) &= rhs;
949}
950
951inline
952bdlt::DayOfWeekSet bdlt::operator^(const DayOfWeekSet& lhs,
953 const DayOfWeekSet& rhs)
954{
955 return DayOfWeekSet(lhs) ^= rhs;
956}
957
958inline
959bdlt::DayOfWeekSet bdlt::operator-(const DayOfWeekSet& lhs,
960 const DayOfWeekSet& rhs)
961{
962 return DayOfWeekSet(lhs) -= rhs;
963}
964
965inline
966bsl::ostream& bdlt::operator<<(bsl::ostream& stream, const DayOfWeekSet& rhs)
967{
968 return rhs.print(stream, 0, -1);
969}
970
971// FREE FUNCTIONS
972template <class HASHALG>
973inline
974void bdlt::hashAppend(HASHALG& hashAlg, const DayOfWeekSet& object)
975{
976 using ::BloombergLP::bslh::hashAppend;
977 hashAppend(hashAlg, object.d_days);
978}
979
980// TRAITS SPECIALIZATIONS
981namespace bslmf {
982template <>
983struct IsBitwiseCopyable<bdlt::DayOfWeekSet_Iter> : ::bsl::true_type {};
984template <>
985struct IsBitwiseCopyable<bdlt::DayOfWeekSet> : ::bsl::true_type {};
986}
987
988
989
990#endif
991
992// ----------------------------------------------------------------------------
993// Copyright 2014 Bloomberg Finance L.P.
994//
995// Licensed under the Apache License, Version 2.0 (the "License");
996// you may not use this file except in compliance with the License.
997// You may obtain a copy of the License at
998//
999// http://www.apache.org/licenses/LICENSE-2.0
1000//
1001// Unless required by applicable law or agreed to in writing, software
1002// distributed under the License is distributed on an "AS IS" BASIS,
1003// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1004// See the License for the specific language governing permissions and
1005// limitations under the License.
1006// ----------------------------- END-OF-FILE ----------------------------------
1007
1008/** @} */
1009/** @} */
1010/** @} */
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
Definition bdlt_dayofweekset.h:293
DayOfWeekSet_Iter & operator--()
bsl::bidirectional_iterator_tag iterator_category
Definition bdlt_dayofweekset.h:297
const DayOfWeek::Enum & reference
Definition bdlt_dayofweekset.h:301
DayOfWeekSet_Iter()
Create a default (invalid) iterator.
Definition bdlt_dayofweekset.h:638
bsl::ptrdiff_t difference_type
Definition bdlt_dayofweekset.h:299
DayOfWeekSet_Iter & operator++()
friend bool operator==(const DayOfWeekSet_Iter &, const DayOfWeekSet_Iter &)
static const DayOfWeek::Enum s_dayOfWeekArray[9]
Definition bdlt_dayofweekset.h:304
DayOfWeek::Enum value_type
Definition bdlt_dayofweekset.h:298
DayOfWeekSet_Iter & operator=(const DayOfWeekSet_Iter &rhs)
Definition bdlt_dayofweekset.h:662
~DayOfWeekSet_Iter()
Destroy this iterator.
Definition bdlt_dayofweekset.h:652
unsigned char d_data
Definition bdlt_dayofweekset.h:307
const DayOfWeek::Enum * pointer
Definition bdlt_dayofweekset.h:300
signed char d_index
Definition bdlt_dayofweekset.h:309
DayOfWeekSet_Iter(int data, int index)
const DayOfWeek::Enum & operator*() const
Definition bdlt_dayofweekset.h:687
Definition bdlt_dayofweekset.h:398
DayOfWeekSet_Iter iterator
Standard nested alias for set container's iterator.
Definition bdlt_dayofweekset.h:415
bool isEmpty() const
Definition bdlt_dayofweekset.h:856
bool remove(DayOfWeek::Enum value)
Definition bdlt_dayofweekset.h:796
friend bool operator==(const DayOfWeekSet &, const DayOfWeekSet &)
static int maxSupportedBdexVersion()
Definition bdlt_dayofweekset.h:907
DayOfWeekSet & operator&=(const DayOfWeekSet &rhs)
Definition bdlt_dayofweekset.h:768
DayOfWeekSet()
Create an empty set.
Definition bdlt_dayofweekset.h:735
friend DayOfWeekSet operator~(const DayOfWeekSet &)
STREAM & bdexStreamIn(STREAM &stream, int version)
Definition bdlt_dayofweekset.h:813
iterator end() const
Definition bdlt_dayofweekset.h:850
bool areMembers(const DayOfWeekSet &set) const
Definition bdlt_dayofweekset.h:838
int length() const
Return the number of elements in this set.
Definition bdlt_dayofweekset.h:869
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
bsl::reverse_iterator< iterator > reverse_iterator
Standard nested alias for set container's reverse iterator.
Definition bdlt_dayofweekset.h:421
reverse_iterator rbegin() const
Definition bdlt_dayofweekset.h:875
reverse_iterator const_reverse_iterator
Standard nested alias for set container's constant reverse iterator.
Definition bdlt_dayofweekset.h:424
friend bool operator!=(const DayOfWeekSet &, const DayOfWeekSet &)
iterator begin() const
Return an iterator referencing the first valid element in this set.
Definition bdlt_dayofweekset.h:844
~DayOfWeekSet()
Destroy this object.
Definition bdlt_dayofweekset.h:747
iterator const_iterator
Standard nested alias for set container's constant iterator.
Definition bdlt_dayofweekset.h:418
bool isMember(DayOfWeek::Enum value) const
Definition bdlt_dayofweekset.h:862
STREAM & bdexStreamOut(STREAM &stream, int version) const
Definition bdlt_dayofweekset.h:889
reverse_iterator rend() const
Definition bdlt_dayofweekset.h:881
friend void hashAppend(HASHALG &hashAlg, const DayOfWeekSet &)
void add(DayOfWeek::Enum value)
Add the specified value to this set.
Definition bdlt_dayofweekset.h:790
DayOfWeekSet & operator-=(const DayOfWeekSet &rhs)
Definition bdlt_dayofweekset.h:782
void removeAll()
Remove all members of this set.
Definition bdlt_dayofweekset.h:805
DayOfWeekSet & operator|=(const DayOfWeekSet &rhs)
Definition bdlt_dayofweekset.h:761
DayOfWeekSet & operator^=(const DayOfWeekSet &rhs)
Definition bdlt_dayofweekset.h:775
DayOfWeekSet & operator=(const DayOfWeekSet &rhs)
Definition bdlt_dayofweekset.h:754
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1762
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
void hashAppend(HASH_ALGORITHM &hashAlg, const baljsn::EncoderTestAddress &object)
Definition baljsn_encoder_testtypes.h:9236
Definition bbldc_basicisma30360.h:112
bool operator==(const Calendar &lhs, const Calendar &rhs)
Date operator-(const Date &date, int numDays)
DayOfWeekSet operator&(const DayOfWeekSet &lhs, const DayOfWeekSet &rhs)
DayOfWeekSet operator|(const DayOfWeekSet &lhs, const DayOfWeekSet &rhs)
bsl::ostream & operator<<(bsl::ostream &stream, const Calendar &calendar)
DayOfWeekSet operator^(const DayOfWeekSet &lhs, const DayOfWeekSet &rhs)
void hashAppend(HASHALG &hashAlg, const Calendar &object)
bool operator!=(const Calendar &lhs, const Calendar &rhs)
DayOfWeekSet operator~(const DayOfWeekSet &set)
Definition bdlbb_blob.h:576
static int numBitsSet(unsigned int value)
Definition bdlb_bitutil.h:360
Enum
Enumerated day-of-week values.
Definition bdlt_dayofweek.h:123
Definition bslmf_isbitwisecopyable.h:298