529 lines
14 KiB
C++
529 lines
14 KiB
C++
/**
|
|
* @file include/ActivMiddleware/ActivBase/Timeband.h
|
|
*
|
|
* @brief Header file for the timeband class.
|
|
*/
|
|
|
|
#if (!defined ACTIV_BASE_TIMEBAND_H)
|
|
#define ACTIV_BASE_TIMEBAND_H
|
|
|
|
#include "ActivMiddleware/ActivBase/External.h"
|
|
|
|
#include "ActivMiddleware/ActivBase/IniFileParser.h"
|
|
#include "ActivMiddleware/ActivBase/FieldTypes/DateTime.h"
|
|
|
|
#include <bitset>
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
/**
|
|
* @brief Timeband class.
|
|
*/
|
|
class Timeband
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Enabled date flag enum.
|
|
*/
|
|
enum EnabledDateFlag
|
|
{
|
|
ENABLED_DATE_END_TIME,
|
|
ENABLED_DATE_START_TIME
|
|
};
|
|
|
|
/**
|
|
* @brief Enabled weeks mode enum.
|
|
*/
|
|
enum EnabledWeeksMode
|
|
{
|
|
ENABLED_WEEKS_MODE_ALL,
|
|
ENABLED_WEEKS_MODE_EVEN,
|
|
ENABLED_WEEKS_MODE_ODD
|
|
};
|
|
|
|
typedef std::set<Date> DateSet; ///< Date set type.
|
|
typedef std::bitset<7> EnabledDaysBitmap; ///< Enabled days bitmap type.
|
|
|
|
/**
|
|
* @brief Settings class.
|
|
*
|
|
* Deprecated, use the Timeband class directly.
|
|
*/
|
|
class Settings
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Default constructor.
|
|
*
|
|
* Settings for an "always on" 24*7 timeband.
|
|
*/
|
|
ACTIV_BASE_API Settings();
|
|
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param startTime start time of the timeband.
|
|
* @param endTime end time of the timeband.
|
|
* @param enabledDaysBitmapString enabled days bitmap string, e.g. "-mtwtf-".
|
|
* @param enabledDateFlag the enabled date flag.
|
|
* @param disabledDateSet the disabled date set.
|
|
* @param enabledWeeksMode the enabled weeks mode.
|
|
*
|
|
* @throw Exception
|
|
*/
|
|
ACTIV_BASE_API Settings(const Time &startTime, const Time &endTime, const String &enabledDaysBitmapString,
|
|
const EnabledDateFlag enabledDateFlag = ENABLED_DATE_END_TIME, const DateSet &disabledDateSet = DateSet(),
|
|
const EnabledWeeksMode enabledWeeksMode = ENABLED_WEEKS_MODE_ALL);
|
|
|
|
/**
|
|
* @brief Read settings from an ini file section.
|
|
*
|
|
* @param keyNamePrefix
|
|
* @param sectionIterator iterator to an ini file section.
|
|
*
|
|
* @throw Exception
|
|
*/
|
|
ACTIV_BASE_API void Read(const String &keyNamePrefix, const IniFileParser::ConstSectionIterator §ionIterator);
|
|
|
|
EnabledDaysBitmap m_enabledDaysBitmap; ///< Enabled days bitmap.
|
|
DateSet m_disabledDateSet; ///< Disabled date set.
|
|
Time m_startTime; ///< Start time of timeband.
|
|
Time m_endTime; ///< End time of timeband.
|
|
EnabledDateFlag m_enabledDateFlag; ///< Enabled date flag.
|
|
EnabledWeeksMode m_enabledWeeksMode; ///< Enabled weeks mode.
|
|
};
|
|
|
|
/**
|
|
* @brief Default constructor.
|
|
*
|
|
* Creates an "always on" 24*7 timeband.
|
|
*/
|
|
ACTIV_BASE_API Timeband();
|
|
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param settings object's settings.
|
|
*/
|
|
ACTIV_BASE_API Timeband(const Settings &settings);
|
|
|
|
//! Copy constructor.
|
|
ACTIV_BASE_API Timeband(const Timeband &rhs);
|
|
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param startTime start time of the timeband.
|
|
* @param endTime end time of the timeband.
|
|
* @param enabledDaysBitmapString enabled days bitmap string, e.g. "-mtwtf-".
|
|
* @param enabledDateFlag the endabled date flag.
|
|
* @param disabledDateSet the disabled date set.
|
|
* @param enabledWeeksMode the enabled weeks mode.
|
|
*/
|
|
ACTIV_BASE_API Timeband(const Time &startTime, const Time &endTime, const String &enabledDaysBitmapString,
|
|
const EnabledDateFlag enabledDateFlag = ENABLED_DATE_END_TIME, const DateSet &disabledDateSet = DateSet(),
|
|
const EnabledWeeksMode enabledWeeksMode = ENABLED_WEEKS_MODE_ALL);
|
|
|
|
/**
|
|
* @brief Is the time within this timeband?
|
|
*
|
|
* @param dateTime date/time to test.
|
|
*
|
|
* @return Boolean.
|
|
*/
|
|
ACTIV_BASE_API bool IsIn(const DateTime &dateTime) const;
|
|
|
|
/**
|
|
* @brief Read settings from an ini file section.
|
|
*
|
|
* @param keyNamePrefix
|
|
* @param sectionIterator iterator to an ini file section.
|
|
*
|
|
* @throw Exception
|
|
*/
|
|
void Read(const String &keyNamePrefix, const IniFileParser::ConstSectionIterator §ionIterator);
|
|
|
|
/**
|
|
* @brief Get the start time.
|
|
*
|
|
* @return const reference to the start time.
|
|
*/
|
|
const Time &GetStartTime() const;
|
|
|
|
/**
|
|
* @brief Get the end time.
|
|
*
|
|
* @return const reference to the end time.
|
|
*/
|
|
const Time &GetEndTime() const;
|
|
|
|
/**
|
|
* @brief Get the enabled days string.
|
|
*
|
|
* @return the enabled days string.
|
|
*/
|
|
ACTIV_BASE_API const String GetEnabledDaysString() const;
|
|
|
|
/**
|
|
* @brief Get the disabled date set.
|
|
*
|
|
* @return the disabled date set.
|
|
*/
|
|
const DateSet &GetDisabledDateSet() const;
|
|
|
|
/**
|
|
* @brief Get the enabled date flag.
|
|
*
|
|
* @return the enabled date flag.
|
|
*/
|
|
EnabledDateFlag GetEnabledDateFlag() const;
|
|
|
|
/**
|
|
* @brief Get the enabled weeks mode.
|
|
*
|
|
* @return the enabled weeks mode.
|
|
*/
|
|
EnabledWeeksMode GetEnabledWeeksMode() const;
|
|
|
|
/**
|
|
* @brief Set the start time.
|
|
*
|
|
* @param startTime the new start time.
|
|
*/
|
|
void SetStartTime(const Time &startTime);
|
|
|
|
/**
|
|
* @brief Set the end time.
|
|
*
|
|
* @param endTime the new end time.
|
|
*/
|
|
void SetEndTime(const Time &endTime);
|
|
|
|
/**
|
|
* @brief Set the enabled days string.
|
|
*
|
|
* @param enabledDaysString the new enabled days string.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval ...
|
|
*/
|
|
StatusCode SetEnabledDaysString(const String &enabledDaysString);
|
|
|
|
/**
|
|
* @brief Set the disbaled date set.
|
|
*
|
|
* @param disabledDateSet the new disabled date set.
|
|
*/
|
|
void SetDisabledDateSet(const DateSet &disabledDateSet);
|
|
|
|
/**
|
|
* @brief Set the enabled date flag.
|
|
*
|
|
* @param enabledDateFlag the new enabled date flag.
|
|
*/
|
|
void SetEnabledDateFlag(const EnabledDateFlag enabledDateFlag);
|
|
|
|
/**
|
|
* @brief Set the enabled weeks mode.
|
|
*
|
|
* @param enabledWeeksMode the new enabled weeks mode.
|
|
*/
|
|
void SetEnabledWeeksMode(const EnabledWeeksMode enabledWeeksMode);
|
|
|
|
/**
|
|
* @brief Add disabled date.
|
|
*
|
|
* @param disabledDate the disabled date to add.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval ...
|
|
*/
|
|
ACTIV_BASE_API StatusCode AddDisabledDate(const Date &disabledDate);
|
|
|
|
/**
|
|
* @brief Remove disabled date.
|
|
*
|
|
* @param disabledDate the disabled date to remove.
|
|
*
|
|
* @retval STATUS_CODE_SUCCESS
|
|
* @retval ...
|
|
*/
|
|
ACTIV_BASE_API StatusCode RemoveDisabledDate(const Date &disabledDate);
|
|
|
|
/**
|
|
* @brief Equality operator.
|
|
*
|
|
* @param rhs the object to compare with.
|
|
*
|
|
* @return the result of the test.
|
|
*
|
|
* @throw StatusCodeException
|
|
*/
|
|
ACTIV_BASE_API bool operator==(const Timeband &rhs) const;
|
|
|
|
/**
|
|
* @brief Inequality operator.
|
|
*
|
|
* @param rhs the object to compare with.
|
|
*
|
|
* @return the result of the test.
|
|
*
|
|
* @throw StatusCodeException
|
|
*/
|
|
ACTIV_BASE_API bool operator!=(const Timeband &rhs) const;
|
|
|
|
/**
|
|
* @brief Assignment operator.
|
|
*
|
|
* @param rhs the object to assign from.
|
|
*
|
|
* @return the result.
|
|
*
|
|
* @throw StatusCodeException
|
|
*/
|
|
ACTIV_BASE_API Timeband &operator=(const Timeband &rhs);
|
|
|
|
/**
|
|
* @brief Get the disabled dates string.
|
|
*
|
|
* @return the disabled dates string.
|
|
*/
|
|
ACTIV_BASE_API const String GetDisabledDateSetString() const;
|
|
|
|
/**
|
|
* @brief Get the enabled date flag string.
|
|
*
|
|
* @return the disabled dates flag string.
|
|
*/
|
|
ACTIV_BASE_API const String GetEnabledDateFlagString() const;
|
|
|
|
/**
|
|
* @brief Get the enabled weeks mode string.
|
|
*
|
|
* @return the enabled weeks mode string.
|
|
*/
|
|
ACTIV_BASE_API const String GetEnabledWeeksModeString() const;
|
|
|
|
/**
|
|
* @brief Convert the timeband to a string.
|
|
*
|
|
* @return the timeband as a string.
|
|
*/
|
|
ACTIV_BASE_API const String ToString() const;
|
|
|
|
/**
|
|
* @brief Convert the timeband to a log string.
|
|
*
|
|
* @return the timeband as a log string.
|
|
*/
|
|
ACTIV_BASE_API const String ToLogString() const;
|
|
|
|
/**
|
|
* @brief Convert string to enabled days bitmap.
|
|
*
|
|
* @param enabledDaysBitmapString the string to convert.
|
|
* @param enabledDaysBitmap the enabled days bitmap to receive the result.
|
|
*
|
|
* @return STATUS_CODE_SUCCESS or an error status.
|
|
*/
|
|
ACTIV_BASE_API static StatusCode ConvertStringToEnabledDaysBitmap(const String enabledDaysBitmapString,
|
|
EnabledDaysBitmap &enabledDaysBitmap);
|
|
|
|
private:
|
|
/**
|
|
* @brief Is enabled day?
|
|
*
|
|
* @param date the date to test.
|
|
*/
|
|
bool IsEnabledDay(const Date &date) const;
|
|
|
|
/**
|
|
* @brief Is enabled week?
|
|
*
|
|
* @param date the date to test.
|
|
*/
|
|
bool IsEnabledWeek(const Date &date) const;
|
|
|
|
Settings m_settings; ///< Object's settings.
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* @brief Timeband list class.
|
|
*/
|
|
class TimebandList
|
|
{
|
|
public:
|
|
typedef std::vector<Timeband::Settings> Settings;
|
|
typedef std::vector<Timeband> List;
|
|
|
|
//! Default constructor.
|
|
ACTIV_BASE_API TimebandList();
|
|
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param timeband
|
|
*/
|
|
ACTIV_BASE_API TimebandList(const Timeband &timeband);
|
|
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param settings list of Timeband::Settings.
|
|
*/
|
|
ACTIV_BASE_API TimebandList(const Settings &settings);
|
|
|
|
/**
|
|
* @brief Read settings, from potentially multiple timebands defined in sub-sections of sectionIterator.
|
|
*
|
|
* @param sectionNamePrefix
|
|
* @param sectionIterator iterator to an ini file section.
|
|
*
|
|
* @throw Exception
|
|
*/
|
|
ACTIV_BASE_API void Read(const String §ionNamePrefix, const IniFileParser::ConstSectionIterator §ionIterator);
|
|
|
|
//! Clear (removes all timebands in the list).
|
|
ACTIV_BASE_API void Clear();
|
|
|
|
/**
|
|
* @brief Add timeband to the list.
|
|
*
|
|
* @param timeband
|
|
*/
|
|
ACTIV_BASE_API void Add(const Timeband &timeband);
|
|
|
|
/**
|
|
* @brief Get time band list.
|
|
*
|
|
* @return A reference to the underlying timeband list.
|
|
*/
|
|
const List &GetTimebandList() const;
|
|
|
|
/**
|
|
* @brief Is the time within the timebands?
|
|
*
|
|
* @param dateTime date/time to test.
|
|
*
|
|
* @return Boolean.
|
|
*/
|
|
bool IsIn(const DateTime &dateTime) const;
|
|
|
|
private:
|
|
List m_list;
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void Timeband::Read(const String &keyNamePrefix, const IniFileParser::ConstSectionIterator §ionIterator)
|
|
{
|
|
m_settings.Read(keyNamePrefix, sectionIterator);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline const Time &Timeband::GetStartTime() const
|
|
{
|
|
return m_settings.m_startTime;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline const Time &Timeband::GetEndTime() const
|
|
{
|
|
return m_settings.m_endTime;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline const Timeband::DateSet &Timeband::GetDisabledDateSet() const
|
|
{
|
|
return m_settings.m_disabledDateSet;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline Timeband::EnabledDateFlag Timeband::GetEnabledDateFlag() const
|
|
{
|
|
return m_settings.m_enabledDateFlag;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline Timeband::EnabledWeeksMode Timeband::GetEnabledWeeksMode() const
|
|
{
|
|
return m_settings.m_enabledWeeksMode;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void Timeband::SetStartTime(const Time &startTime)
|
|
{
|
|
m_settings.m_startTime = startTime;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void Timeband::SetEndTime(const Time &endTime)
|
|
{
|
|
m_settings.m_endTime = endTime;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCode Timeband::SetEnabledDaysString(const String &enabledDaysString)
|
|
{
|
|
return ConvertStringToEnabledDaysBitmap(enabledDaysString, m_settings.m_enabledDaysBitmap);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void Timeband::SetDisabledDateSet(const DateSet &disabledDateSet)
|
|
{
|
|
m_settings.m_disabledDateSet = disabledDateSet;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void Timeband::SetEnabledDateFlag(const EnabledDateFlag enabledDateFlag)
|
|
{
|
|
m_settings.m_enabledDateFlag = enabledDateFlag;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void Timeband::SetEnabledWeeksMode(const EnabledWeeksMode enabledWeeksMode)
|
|
{
|
|
m_settings.m_enabledWeeksMode = enabledWeeksMode;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline const TimebandList::List &TimebandList::GetTimebandList() const
|
|
{
|
|
return m_list;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline bool TimebandList::IsIn(const DateTime &dateTime) const
|
|
{
|
|
for (List::const_iterator iter = m_list.begin(), iterEnd = m_list.end(); iter != iterEnd; ++iter)
|
|
{
|
|
if (iter->IsIn(dateTime))
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
} // namespace Activ
|
|
|
|
#endif // (!defined ACTIV_BASE_TIMEBAND_H)
|