StdAir Logo  1.00.26
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 for (BooleanList_T::const_iterator itDoW = _dowList.begin();
43 itDoW != _dowList.end(); ++itDoW) {
44 const char lDoW = (*itDoW == true)?'1':'0';
45 ostr << lDoW;
46 }
47 return ostr.str();
48 }
49
50 // ////////////////////////////////////////////////////////////////////
51 const std::string DoWStruct::describe() const {
52 std::ostringstream ostr;
53 short i = 0;
54 for (BooleanList_T::const_iterator itDoW = _dowList.begin();
55 itDoW != _dowList.end(); ++itDoW, ++i) {
56 const bool lDoW = *itDoW;
57 if (lDoW == true) {
58 ostr << DOW_STR[i] << ".";
59 }
60 }
61 return ostr.str();
62 }
63
64 // ////////////////////////////////////////////////////////////////////
65 bool DoWStruct::getDayOfWeek (const unsigned short i) const {
66 return _dowList.at (i);
67 }
68
69 // ////////////////////////////////////////////////////////////////////
70 bool DoWStruct::getStandardDayOfWeek (const unsigned short i) const {
71 unsigned short iStd = i;
72 if (iStd == 0) {
73 iStd = 6;
74 } else {
75 --iStd;
76 }
77 return _dowList.at (iStd);
78 }
79
80 // ////////////////////////////////////////////////////////////////////
81 void DoWStruct::setDayOfWeek (const unsigned short i, const bool iBool) {
82 assert (i < 7);
83 _dowList.at (i) = iBool;
84 }
85
86 // ////////////////////////////////////////////////////////////////////
87 DoWStruct DoWStruct::shift (const long& iNbOfDays) const {
89
90 for (short i = 0; i < 7; ++i) {
91 const bool lDoWBool = _dowList.at (i);
92 short lIndex = (i + iNbOfDays) % 7;
93 if (lIndex < 0) {
94 lIndex += 7;
95 }
96 oDoW.setDayOfWeek (lIndex, lDoWBool);
97 }
98
99 return oDoW;
100 }
101
102 // ////////////////////////////////////////////////////////////////////
105 for (unsigned short i = 0; i < 7; ++i) {
106 if (getDayOfWeek(i) && iDoW.getDayOfWeek(i)) {
107 oDoW.setDayOfWeek (i, true);
108 } else {
109 oDoW.setDayOfWeek (i, false);
110 }
111 }
112 return oDoW;
113 }
114
115 // ////////////////////////////////////////////////////////////////////
116 const bool DoWStruct::isValid () const {
117 for (unsigned short i = 0; i < 7; ++i) {
118 if (getDayOfWeek(i)) {
119 return true;
120 }
121 }
122 return false;
123 }
124
125}
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:51
void setDayOfWeek(const unsigned short, const bool)
Definition DoWStruct.cpp:81
bool getStandardDayOfWeek(const unsigned short i) const
Definition DoWStruct.cpp:70
DoWStruct shift(const long &) const
Definition DoWStruct.cpp:87
const std::string describeShort() const
Definition DoWStruct.cpp:40
bool getDayOfWeek(const unsigned short i) const
Definition DoWStruct.cpp:65