StdAir Logo  1.00.16
C++ Standard Airline IT Object Library
Loading...
Searching...
No Matches
DoWStruct.cpp
Go to the documentation of this file.
1// //////////////////////////////////////////////////////////////////////
2// Import section
3// //////////////////////////////////////////////////////////////////////
4// STL
5#include <sstream>
6#include <cassert>
7// STDAIR
10
11namespace stdair {
12
13 // ////////////////////////////////////////////////////////////////////
15 for (unsigned short i = 0; i < 7; ++i) {
16 _dowList.push_back (false);
17 }
18 }
19
20 // ////////////////////////////////////////////////////////////////////
21 DoWStruct::DoWStruct (const std::string& iDowString) {
22 const unsigned short lDowStringSize = iDowString.size();
23 assert (lDowStringSize == 7);
24
25 _dowList.reserve (lDowStringSize);
26 for (std::string::const_iterator itChar = iDowString.begin();
27 itChar != iDowString.end(); ++itChar) {
28 const bool isDoWSet = (*itChar == '1')?true:false;
29 _dowList.push_back (isDoWSet);
30 }
31 }
32
33 // ////////////////////////////////////////////////////////////////////
34 DoWStruct::DoWStruct (const DoWStruct& iDowStruct) :
35 _dowList (iDowStruct._dowList) {
36
37 }
38
39 // ////////////////////////////////////////////////////////////////////
40 const std::string DoWStruct::describeShort() const {
41 std::ostringstream ostr;
42 short i = 0;
43 for (BooleanList_T::const_iterator itDoW = _dowList.begin();
44 itDoW != _dowList.end(); ++itDoW, ++i) {
45 const char lDoW = (*itDoW == true)?'1':'0';
46 ostr << lDoW;
47 }
48 return ostr.str();
49 }
50
51 // ////////////////////////////////////////////////////////////////////
52 const std::string DoWStruct::describe() const {
53 std::ostringstream ostr;
54 short i = 0;
55 for (BooleanList_T::const_iterator itDoW = _dowList.begin();
56 itDoW != _dowList.end(); ++itDoW, ++i) {
57 const bool lDoW = *itDoW;
58 if (lDoW == true) {
59 ostr << DOW_STR[i] << ".";
60 }
61 }
62 return ostr.str();
63 }
64
65 // ////////////////////////////////////////////////////////////////////
66 bool DoWStruct::getDayOfWeek (const unsigned short i) const {
67 return _dowList.at (i);
68 }
69
70 // ////////////////////////////////////////////////////////////////////
71 bool DoWStruct::getStandardDayOfWeek (const unsigned short i) const {
72 unsigned short iStd = i;
73 if (iStd == 0) {
74 iStd = 6;
75 } else {
76 --iStd;
77 }
78 return _dowList.at (iStd);
79 }
80
81 // ////////////////////////////////////////////////////////////////////
82 void DoWStruct::setDayOfWeek (const unsigned short i, const bool iBool) {
83 assert (i < 7);
84 _dowList.at (i) = iBool;
85 }
86
87 // ////////////////////////////////////////////////////////////////////
88 DoWStruct DoWStruct::shift (const long& iNbOfDays) const {
90
91 for (short i = 0; i < 7; ++i) {
92 const bool lDoWBool = _dowList.at (i);
93 short lIndex = (i + iNbOfDays) % 7;
94 if (lIndex < 0) {
95 lIndex += 7;
96 }
97 oDoW.setDayOfWeek (lIndex, lDoWBool);
98 }
99
100 return oDoW;
101 }
102
103 // ////////////////////////////////////////////////////////////////////
106 for (unsigned short i = 0; i < 7; ++i) {
107 if (getDayOfWeek(i) && iDoW.getDayOfWeek(i)) {
108 oDoW.setDayOfWeek (i, true);
109 } else {
110 oDoW.setDayOfWeek (i, false);
111 }
112 }
113 return oDoW;
114 }
115
116 // ////////////////////////////////////////////////////////////////////
117 const bool DoWStruct::isValid () const {
118 for (unsigned short i = 0; i < 7; ++i) {
119 if (getDayOfWeek(i)) {
120 return true;
121 }
122 }
123 return false;
124 }
125
126}
Handle on the StdAir library context.
const std::string DOW_STR[]
Definition BasConst.cpp:53
const DOW_String_T DEFAULT_DOW_STRING
DoWStruct intersection(const DoWStruct &) const
DoWStruct(const std::string &iDowString)
Definition DoWStruct.cpp:21
const bool isValid() const
const std::string describe() const
Definition DoWStruct.cpp:52
void setDayOfWeek(const unsigned short, const bool)
Definition DoWStruct.cpp:82
bool getStandardDayOfWeek(const unsigned short i) const
Definition DoWStruct.cpp:71
DoWStruct shift(const long &) const
Definition DoWStruct.cpp:88
const std::string describeShort() const
Definition DoWStruct.cpp:40
bool getDayOfWeek(const unsigned short i) const
Definition DoWStruct.cpp:66