$treeview $search $mathjax
00001 // ////////////////////////////////////////////////////////////////////// 00002 // Import section 00003 // ////////////////////////////////////////////////////////////////////// 00004 // STL 00005 #include <sstream> 00006 #include <cassert> 00007 // STDAIR 00008 #include <stdair/basic/BasConst_Period_BOM.hpp> 00009 #include <stdair/bom/DoWStruct.hpp> 00010 00011 namespace stdair { 00012 00013 // //////////////////////////////////////////////////////////////////// 00014 DoWStruct::DoWStruct () { 00015 for (unsigned short i = 0; i < 7; ++i) { 00016 _dowList.push_back (false); 00017 } 00018 } 00019 00020 // //////////////////////////////////////////////////////////////////// 00021 DoWStruct::DoWStruct (const std::string& iDowString) { 00022 const unsigned short lDowStringSize = iDowString.size(); 00023 assert (lDowStringSize == 7); 00024 00025 _dowList.reserve (lDowStringSize); 00026 for (std::string::const_iterator itChar = iDowString.begin(); 00027 itChar != iDowString.end(); ++itChar) { 00028 const bool isDoWSet = (*itChar == '1')?true:false; 00029 _dowList.push_back (isDoWSet); 00030 } 00031 } 00032 00033 // //////////////////////////////////////////////////////////////////// 00034 DoWStruct::DoWStruct (const DoWStruct& iDowStruct) : 00035 _dowList (iDowStruct._dowList) { 00036 00037 } 00038 00039 // //////////////////////////////////////////////////////////////////// 00040 const std::string DoWStruct::describeShort() const { 00041 std::ostringstream ostr; 00042 short i = 0; 00043 for (BooleanList_T::const_iterator itDoW = _dowList.begin(); 00044 itDoW != _dowList.end(); ++itDoW, ++i) { 00045 const char lDoW = (*itDoW == true)?'1':'0'; 00046 ostr << lDoW; 00047 } 00048 return ostr.str(); 00049 } 00050 00051 // //////////////////////////////////////////////////////////////////// 00052 const std::string DoWStruct::describe() const { 00053 std::ostringstream ostr; 00054 short i = 0; 00055 for (BooleanList_T::const_iterator itDoW = _dowList.begin(); 00056 itDoW != _dowList.end(); ++itDoW, ++i) { 00057 const bool lDoW = *itDoW; 00058 if (lDoW == true) { 00059 ostr << DOW_STR[i] << "."; 00060 } 00061 } 00062 return ostr.str(); 00063 } 00064 00065 // //////////////////////////////////////////////////////////////////// 00066 bool DoWStruct::getDayOfWeek (const unsigned short i) const { 00067 return _dowList.at (i); 00068 } 00069 00070 // //////////////////////////////////////////////////////////////////// 00071 bool DoWStruct::getStandardDayOfWeek (const unsigned short i) const { 00072 unsigned short iStd = i; 00073 if (iStd == 0) { 00074 iStd = 6; 00075 } else { 00076 --iStd; 00077 } 00078 return _dowList.at (iStd); 00079 } 00080 00081 // //////////////////////////////////////////////////////////////////// 00082 void DoWStruct::setDayOfWeek (const unsigned short i, const bool iBool) { 00083 assert (i < 7); 00084 _dowList.at (i) = iBool; 00085 } 00086 00087 // //////////////////////////////////////////////////////////////////// 00088 DoWStruct DoWStruct::shift (const long& iNbOfDays) const { 00089 DoWStruct oDoW (DEFAULT_DOW_STRING); 00090 00091 for (short i = 0; i < 7; ++i) { 00092 const bool lDoWBool = _dowList.at (i); 00093 short lIndex = (i + iNbOfDays) % 7; 00094 if (lIndex < 0) { 00095 lIndex += 7; 00096 } 00097 oDoW.setDayOfWeek (lIndex, lDoWBool); 00098 } 00099 00100 return oDoW; 00101 } 00102 00103 // //////////////////////////////////////////////////////////////////// 00104 DoWStruct DoWStruct::intersection (const DoWStruct& iDoW) const { 00105 DoWStruct oDoW (DEFAULT_DOW_STRING); 00106 for (unsigned short i = 0; i < 7; ++i) { 00107 if (getDayOfWeek(i) && iDoW.getDayOfWeek(i)) { 00108 oDoW.setDayOfWeek (i, true); 00109 } else { 00110 oDoW.setDayOfWeek (i, false); 00111 } 00112 } 00113 return oDoW; 00114 } 00115 00116 // //////////////////////////////////////////////////////////////////// 00117 const bool DoWStruct::isValid () const { 00118 for (unsigned short i = 0; i < 7; ++i) { 00119 if (getDayOfWeek(i)) { 00120 return true; 00121 } 00122 } 00123 return false; 00124 } 00125 00126 }