BDE 4.39.x 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 last possible element in `data`.
324 ///
325 /// \pre The behavior is undefined unless
326 /// `0 == (data & 1)`, `index >= 0`, and `index <= 8`.
327 DayOfWeekSet_Iter(int data, int index);
328
329 /// Create an iterator having the value of the specified `original`
330 /// iterator.
331 DayOfWeekSet_Iter(const DayOfWeekSet_Iter& original);
332
333 /// Destroy this iterator.
335
336 // MANIPULATORS
337
338 /// Assign to this iterator the value of the specified `rhs` iterator,
339 /// and return a reference providing modifiable access to this iterator.
341
342 /// Advance this iterator to the next valid data element, and return a
343 /// reference providing modifiable access to this iterator. If there is
344 /// no next valid data element, this iterator will be set equal to
345 /// `end()`.
347
348 /// Advance this iterator to the next valid data element, and return by
349 /// value the value of this iterator before it was incremented. If
350 /// there is no next valid data element, this iterator will be set equal
351 /// to `end()`.
353
354 /// Regress this iterator to the previous valid data element, and return
355 /// a reference providing modifiable access to this iterator. If there
356 /// is no preceding data element, the value of `reverse_iterator(*this)`
357 /// will be `rend()`.
359
360 /// Regress this iterator to the previous valid data element, and return
361 /// by value the value of this iterator before it was decremented. If
362 /// there is no preceding data element, the value of
363 /// `reverse_iterator(*this)` will be `rend()`.
365
366 // ACCESSORS
367
368 /// Return a reference providing non-modifiable access to the day of
369 /// week value referenced by this iterator.
370 ///
371 /// \pre The behavior is undefined unless the iterator refers to a valid day of the week, specifically,
372 /// the behavior is undefined if `*this == end()`.
373 const DayOfWeek::Enum& operator*() const;
374};
375
376// FREE OPERATORS
377
378/// Return `true` if the specified `lhs` and `rhs` iterators have the same
379/// value, and `false` otherwise. Two iterators have the same value if they
380/// refer to data at the same index position.
381///
382/// \pre The behavior is undefined unless `lhs` and `rhs` both reference into the same set of data.
383bool operator==(const DayOfWeekSet_Iter& lhs, const DayOfWeekSet_Iter& rhs);
384
385/// Return `true` if the specified `lhs` and `rhs` iterators do not have the
386/// same value, and `false` otherwise. Two iterators do not have the same
387/// value if they do not refer to data at the same index position.
388///
389/// \pre The behavior is undefined unless `lhs` and `rhs` both reference into the
390/// same set of data.
391bool operator!=(const DayOfWeekSet_Iter& lhs, const DayOfWeekSet_Iter& rhs);
392
393 // ==================
394 // class DayOfWeekSet
395 // ==================
396
397/// This class implements an efficient value-semantic, ordered set of
398/// `DayOfWeek` values. This set requires a fixed capacity, and all
399/// operations operate in constant time, and provide the no-throw guarantee.
400///
401/// See @ref bdlt_dayofweekset
403
404 // DATA
405 unsigned char d_days; // bits '1 .. 7' reflect '[ SUN, MON, ..., SAT ]';
406 // bit 0 is unused
407
408 // FRIENDS
409 friend bool operator==(const DayOfWeekSet&, const DayOfWeekSet&);
410 friend bool operator!=(const DayOfWeekSet&, const DayOfWeekSet&);
412 template <class HASHALG>
413 friend void hashAppend(HASHALG& hashAlg, const DayOfWeekSet&);
414
415 public:
416 // TYPES
417
418 /// Standard nested alias for set container's iterator.
420
421 /// Standard nested alias for set container's constant iterator.
423
424 /// Standard nested alias for set container's reverse iterator.
425 typedef bsl::reverse_iterator<iterator> reverse_iterator;
426
427 /// Standard nested alias for set container's constant reverse iterator.
429
430 // CLASS METHODS
431
432 // Aspects
433
434 /// Return the maximum valid BDEX format version, as indicated by the
435 /// specified `versionSelector`, to be passed to the `bdexStreamOut` method.
436 ///
437 /// \note Note that it is highly recommended that `versionSelector`
438 /// be formatted as "YYYYMMDD", a date representation. Also note that
439 /// `versionSelector` should be a *compile*-time-chosen value that
440 /// selects a format version supported by both externalizer and
441 /// unexternalizer. See the `bslx` package-level documentation for more
442 /// information on BDEX streaming of value-semantic types and
443 /// containers.
444 static int maxSupportedBdexVersion(int versionSelector);
445
446 // CREATORS
447
448 /// Create an empty set.
449 DayOfWeekSet();
450
451 /// Create a set initialized to the value of the specified `original`
452 /// set.
453 DayOfWeekSet(const DayOfWeekSet& original);
454
455 /// Destroy this object.
457
458 // MANIPULATORS
459
460 /// Assign to this set the value of the specified `rhs` set, and return
461 /// a reference providing modifiable access to this set.
463
464 /// Assign to this set the union of this set with the specified `rhs`
465 /// set (i.e., a set containing elements that are in either this set or
466 /// the `rhs` set, or in both sets), and return a reference providing
467 /// modifiable access to this set.
469
470 /// Assign to this set the intersection of this set with the specified
471 /// `rhs` set (i.e., a set containing elements that are in both this
472 /// set and the `rhs` set), and return a reference providing modifiable
473 /// access to this set.
475
476 /// Assign to this set the exclusive-or of this set with the specified
477 /// `rhs` set (i.e., a set containing elements that are either in this
478 /// set, but not `rhs`, or in `rhs`, but not in this set), and return a
479 /// reference providing modifiable access to this set.
481
482 /// Assign to this set the subtraction of the specified `rhs` set from
483 /// this set (i.e., a set containing elements that are in this set, but
484 /// not in the `rhs` set), and return a reference providing modifiable
485 /// access to this set.
487
488 /// Add the specified `value` to this set.
489 void add(DayOfWeek::Enum value);
490
491 /// Remove the specified `value` from this set. Return `true` if
492 /// `value` was a member of this set, and `false` otherwise.
493 bool remove(DayOfWeek::Enum value);
494
495 /// Remove all members of this set.
496 void removeAll();
497
498 // Aspects
499
500 /// Assign to this object the value read from the specified input
501 /// `stream` using the specified `version` format, and return a
502 /// reference to `stream`. If `stream` is initially invalid, this
503 /// operation has no effect. If `version` is not supported, this object
504 /// is unaltered and `stream` is invalidated, but otherwise unmodified.
505 /// If `version` is supported but `stream` becomes invalid during this
506 /// operation, this object has an undefined, but valid, state.
507 ///
508 /// \note Note that no version is read from `stream`. See the `bslx` package-level
509 /// documentation for more information on BDEX streaming of
510 /// value-semantic types and containers.
511 template <class STREAM>
512 STREAM& bdexStreamIn(STREAM& stream, int version);
513
514 // ACCESSORS
515
516 /// Return `true` if this set contains all elements of the specified
517 /// `set`, and `false` otherwise.
518 bool areMembers(const DayOfWeekSet& set) const;
519
520 /// Return an iterator referencing the first valid element in this set.
521 iterator begin() const;
522
523 /// Return an iterator indicating one position past the last possible
524 /// element in this set.
525 iterator end() const;
526
527 /// Return `true` if there are no elements in this set, and `false`
528 /// otherwise.
529 bool isEmpty() const;
530
531 /// Return `true` if the specified `value` is an element of this set,
532 /// and `false` otherwise.
533 bool isMember(DayOfWeek::Enum value) const;
534
535 /// Return the number of elements in this set.
536 int length() const;
537
538 /// Return a reverse iterator referencing the last valid element in this
539 /// set.
540 reverse_iterator rbegin() const;
541
542 /// Return a reverse iterator indicating one position before the first
543 /// possible element in this set.
544 reverse_iterator rend() const;
545
546 // Aspects
547
548 /// Write the value of this object, using the specified `version`
549 /// format, to the specified output `stream`, and return a reference to
550 /// `stream`. If `stream` is initially invalid, this operation has no
551 /// effect. If `version` is not supported, `stream` is invalidated, but otherwise unmodified.
552 ///
553 /// \note Note that `version` is not written to
554 /// `stream`. See the `bslx` package-level documentation for more
555 /// information on BDEX streaming of value-semantic types and
556 /// containers.
557 template <class STREAM>
558 STREAM& bdexStreamOut(STREAM& stream, int version) const;
559
560 /// Format this object to the specified output `stream` at the (absolute
561 /// value of) the optionally specified indentation `level`, and return a
562 /// reference to `stream`. If `level` is specified, optionally specify
563 /// `spacesPerLevel`, the number of spaces per indentation level for
564 /// this and all of its nested objects. If `level` is negative,
565 /// suppress indentation of the first line. If `spacesPerLevel` is
566 /// negative, format the entire output on one line, suppressing all but
567 /// the initial indentation (as governed by `level`). If `stream` is
568 /// not valid on entry, this operation has no effect.
569 bsl::ostream& print(bsl::ostream& stream,
570 int level = 0,
571 int spacesPerLevel = 4) const;
572
573#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
574
575 /// Return the most current BDEX streaming version number supported by
576 /// this class.
577 ///
578 /// @deprecated Use @ref maxSupportedBdexVersion(int) instead.
579 static int maxSupportedBdexVersion();
580
581#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
582
583};
584
585// FREE OPERATORS
586
587/// Return a set containing the complement of the specified `set` (i.e.,
588/// those members *not* contained in `set`).
590
591/// Return a set containing the union of the specified `lhs` and `rhs` sets
592/// (i.e., a set containing elements that are in either `lhs` or `rhs` or
593/// both).
595
596/// Return a set containing the intersection of the specified `lhs` and
597/// `rhs` sets (i.e., a set containing elements that are in both `lhs` and
598/// `rhs`).
600
601/// Return a set containing the exclusive-or of the specified `lhs` and
602/// `rhs` sets (i.e., a set containing elements that are either in `lhs`,
603/// but not `rhs`, or in `rhs`, but not `lhs`).
605
606/// Return a set containing the subtraction of the specified `rhs` set from
607/// the specified `lhs` set (i.e., a set containing elements that are in
608/// `lhs`, but not in `rhs`).
610
611/// Return `true` if the specified `lhs` and `rhs` sets have the same value,
612/// and `false` otherwise. Two sets have the same value if they have the
613/// same length and all the elements of one set are members of the other
614/// set.
615bool operator==(const DayOfWeekSet& lhs, const DayOfWeekSet& rhs);
616
617/// Return `true` if the specified `lhs` and `rhs` sets do not have the same
618/// value, and `false` otherwise. Two sets do not have the same value if
619/// they differ in length or there exists an element of one set that is not
620/// a member of the other set.
621bool operator!=(const DayOfWeekSet& lhs, const DayOfWeekSet& rhs);
622
623/// Write the specified `rhs` set to the specified output `stream` in some
624/// reasonable (single-line) format, and return a reference to `stream`.
625bsl::ostream& operator<<(bsl::ostream& stream, const DayOfWeekSet& rhs);
626
627// FREE FUNCTIONS
628
629/// Pass the specified `object` to the specified `hashAlg`. This function
630/// integrates with the `bslh` modular hashing system and effectively
631/// provides a `bsl::hash` specialization for `DayOfWeekSet`.
632template <class HASHALG>
633void hashAppend(HASHALG& hashAlg, const DayOfWeekSet& object);
634
635// ============================================================================
636// INLINE DEFINITIONS
637// ============================================================================
638
639 // -----------------------
640 // class DayOfWeekSet_Iter
641 // -----------------------
642
643// CREATORS
644inline
646: d_data(0)
647, d_index(8)
648{
649}
650
651inline
653: d_data(original.d_data)
654, d_index(original.d_index)
655{
656}
657
658inline
660{
661 BSLS_ASSERT(0 == (d_data & 1)); // lsb is unused and always 0
662 BSLS_ASSERT(d_index >= 0);
663 BSLS_ASSERT(d_index <= 8);
664}
665
666// MANIPULATORS
667inline
670{
671 d_data = rhs.d_data;
672 d_index = rhs.d_index;
673 return *this;
674}
675
676inline
678{
679 DayOfWeekSet_Iter tmp(*this);
680 this->operator++();
681 return tmp;
682}
683
684inline
686{
687 DayOfWeekSet_Iter tmp(*this);
688 this->operator--();
689 return tmp;
690}
691
692// ACCESSORS
693inline
701
702} // close package namespace
703
704// FREE OPERATORS
705inline
706bool bdlt::operator==(const DayOfWeekSet_Iter& lhs,
707 const DayOfWeekSet_Iter& rhs)
708{
709 BSLS_ASSERT_SAFE(lhs.d_data == rhs.d_data);
710
711 // If the data is not the same, either the objects were not initially the
712 // same, or one has subsequently been modified.
713
714 return lhs.d_index == rhs.d_index;
715}
716
717inline
718bool bdlt::operator!=(const DayOfWeekSet_Iter& lhs,
719 const DayOfWeekSet_Iter& rhs)
720{
721 return !(lhs == rhs);
722}
723
724namespace bdlt {
725
726 // ------------------
727 // class DayOfWeekSet
728 // ------------------
729
730// CLASS METHODS
731
732 // Aspects
733
734inline
735int DayOfWeekSet::maxSupportedBdexVersion(int /* versionSelector */)
736{
737 return 1;
738}
739
740// CREATORS
741inline
743: d_days(0)
744{
745}
746
747inline
749: d_days(original.d_days)
750{
751}
752
753inline
755{
756 BSLS_ASSERT(!(d_days & 1));
757}
758
759// MANIPULATORS
760inline
762{
763 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 d_days = static_cast<unsigned char>(d_days ^ rhs.d_days);
785 return *this;
786}
787
788inline
790{
791 const int mask = d_days & rhs.d_days;
792 d_days = static_cast<unsigned char>(d_days - mask);
793 return *this;
794}
795
796inline
798{
799 d_days = static_cast<unsigned char>(d_days | (1 << value));
800}
801
802inline
804{
805 const int mask = 1 << value;
806 const bool rv = d_days & mask;
807 d_days &= static_cast<unsigned char>(~mask);
808 return rv;
809}
810
811inline
813{
814 d_days = 0;
815}
816
817 // Aspects
818
819template <class STREAM>
820STREAM& DayOfWeekSet::bdexStreamIn(STREAM& stream, int version)
821{
822 if (stream) {
823 switch (version) { // switch on the schema version
824 case 1: {
825 unsigned char tmp;
826 stream.getUint8(tmp);
827
828 if (stream && 0 == (tmp & 1)) {
829 d_days = tmp;
830 }
831 else {
832 stream.invalidate();
833 }
834 } break;
835 default: {
836 stream.invalidate(); // unrecognized version number
837 }
838 }
839 }
840 return stream;
841}
842
843// ACCESSORS
844inline
846{
847 return set.d_days == (d_days & set.d_days);
848}
849
850inline
855
856inline
861
862inline
864{
865 return 0 == d_days;
866}
867
868inline
870{
871 const int mask = 1 << value;
872 return mask == (d_days & mask);
873}
874
875inline
877{
878 return bdlb::BitUtil::numBitsSet(static_cast<unsigned int>(d_days));
879}
880
881inline
886
887inline
892
893 // Aspects
894
895template <class STREAM>
896STREAM& DayOfWeekSet::bdexStreamOut(STREAM& stream, int version) const
897{
898 if (stream) {
899 switch (version) { // switch on the schema version
900 case 1: {
901 stream.putUint8(d_days);
902 } break;
903 default: {
904 stream.invalidate(); // unrecognized version number
905 }
906 }
907 }
908 return stream;
909}
910
911#ifndef BDE_OPENSOURCE_PUBLICATION // pending deprecation
912
913inline
918
919#endif // BDE_OPENSOURCE_PUBLICATION -- pending deprecation
920
921} // close package namespace
922
923// FREE OPERATORS
924inline
925bdlt::DayOfWeekSet bdlt::operator~(const DayOfWeekSet& set)
926{
927 DayOfWeekSet tmp(set);
928 tmp.d_days = static_cast<unsigned char>(~tmp.d_days & 0xfe);
929 return tmp;
930}
931
932inline
933bool bdlt::operator==(const DayOfWeekSet& lhs, const DayOfWeekSet& rhs)
934{
935 return lhs.d_days == rhs.d_days;
936}
937
938inline
939bool bdlt::operator!=(const DayOfWeekSet& lhs, const DayOfWeekSet& rhs)
940{
941 return lhs.d_days != rhs.d_days;
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
966bdlt::DayOfWeekSet bdlt::operator-(const DayOfWeekSet& lhs,
967 const DayOfWeekSet& rhs)
968{
969 return DayOfWeekSet(lhs) -= rhs;
970}
971
972inline
973bsl::ostream& bdlt::operator<<(bsl::ostream& stream, const DayOfWeekSet& rhs)
974{
975 return rhs.print(stream, 0, -1);
976}
977
978// FREE FUNCTIONS
979template <class HASHALG>
980inline
981void bdlt::hashAppend(HASHALG& hashAlg, const DayOfWeekSet& object)
982{
983 using ::BloombergLP::bslh::hashAppend;
984 hashAppend(hashAlg, object.d_days);
985}
986
987// TRAITS SPECIALIZATIONS
988namespace bslmf {
989template <>
990struct IsBitwiseCopyable<bdlt::DayOfWeekSet_Iter> : ::bsl::true_type {};
991template <>
992struct IsBitwiseCopyable<bdlt::DayOfWeekSet> : ::bsl::true_type {};
993}
994
995
996
997#endif
998
999// ----------------------------------------------------------------------------
1000// Copyright 2014 Bloomberg Finance L.P.
1001//
1002// Licensed under the Apache License, Version 2.0 (the "License");
1003// you may not use this file except in compliance with the License.
1004// You may obtain a copy of the License at
1005//
1006// http://www.apache.org/licenses/LICENSE-2.0
1007//
1008// Unless required by applicable law or agreed to in writing, software
1009// distributed under the License is distributed on an "AS IS" BASIS,
1010// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1011// See the License for the specific language governing permissions and
1012// limitations under the License.
1013// ----------------------------- END-OF-FILE ----------------------------------
1014
1015/** @} */
1016/** @} */
1017/** @} */
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:645
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:669
~DayOfWeekSet_Iter()
Destroy this iterator.
Definition bdlt_dayofweekset.h:659
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:694
Definition bdlt_dayofweekset.h:402
DayOfWeekSet_Iter iterator
Standard nested alias for set container's iterator.
Definition bdlt_dayofweekset.h:419
bool isEmpty() const
Definition bdlt_dayofweekset.h:863
bool remove(DayOfWeek::Enum value)
Definition bdlt_dayofweekset.h:803
friend bool operator==(const DayOfWeekSet &, const DayOfWeekSet &)
static int maxSupportedBdexVersion()
Definition bdlt_dayofweekset.h:914
DayOfWeekSet & operator&=(const DayOfWeekSet &rhs)
Definition bdlt_dayofweekset.h:775
DayOfWeekSet()
Create an empty set.
Definition bdlt_dayofweekset.h:742
friend DayOfWeekSet operator~(const DayOfWeekSet &)
STREAM & bdexStreamIn(STREAM &stream, int version)
Definition bdlt_dayofweekset.h:820
iterator end() const
Definition bdlt_dayofweekset.h:857
bool areMembers(const DayOfWeekSet &set) const
Definition bdlt_dayofweekset.h:845
int length() const
Return the number of elements in this set.
Definition bdlt_dayofweekset.h:876
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:425
reverse_iterator rbegin() const
Definition bdlt_dayofweekset.h:882
reverse_iterator const_reverse_iterator
Standard nested alias for set container's constant reverse iterator.
Definition bdlt_dayofweekset.h:428
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:851
~DayOfWeekSet()
Destroy this object.
Definition bdlt_dayofweekset.h:754
iterator const_iterator
Standard nested alias for set container's constant iterator.
Definition bdlt_dayofweekset.h:422
bool isMember(DayOfWeek::Enum value) const
Definition bdlt_dayofweekset.h:869
STREAM & bdexStreamOut(STREAM &stream, int version) const
Definition bdlt_dayofweekset.h:896
reverse_iterator rend() const
Definition bdlt_dayofweekset.h:888
friend void hashAppend(HASHALG &hashAlg, const DayOfWeekSet &)
void add(DayOfWeek::Enum value)
Add the specified value to this set.
Definition bdlt_dayofweekset.h:797
DayOfWeekSet & operator-=(const DayOfWeekSet &rhs)
Definition bdlt_dayofweekset.h:789
void removeAll()
Remove all members of this set.
Definition bdlt_dayofweekset.h:812
DayOfWeekSet & operator|=(const DayOfWeekSet &rhs)
Definition bdlt_dayofweekset.h:768
DayOfWeekSet & operator^=(const DayOfWeekSet &rhs)
Definition bdlt_dayofweekset.h:782
DayOfWeekSet & operator=(const DayOfWeekSet &rhs)
Definition bdlt_dayofweekset.h:761
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1917
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
void hashAppend(HASH_ALGORITHM &hashAlgorithm, const BigEndianInt16 &object)
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)
ALLOCATOR const STRING_VIEW_LIKE_TYPE & rhs
Definition bslstl_string.h:3918
ALLOCATOR & lhs
Definition bslstl_string.h:3917
Definition bdlbb_blob.h:579
static int numBitsSet(unsigned int value)
Return the number of 1 bits in the specified value.
Definition bdlb_bitutil.h:362
Enum
Enumerated day-of-week values.
Definition bdlt_dayofweek.h:125
Definition bslmf_isbitwisecopyable.h:298