Welcome to mirror list, hosted at ThFree Co, Russian Federation.

opening_hours_ui.hpp « editor - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8c4d5023722868f708246f2d7109973ffbca5ff3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#pragma once

#include "std/set.hpp"
#include "std/vector.hpp"

#include "3party/opening_hours/opening_hours.hpp"

namespace editor
{
namespace ui
{

using TOpeningDays = set<osmoh::Weekday>;

class TimeTable
{
public:
  static TimeTable GetUninitializedTimeTable() { return {}; }
  static TimeTable GetPredefinedTimeTable();

  bool IsTwentyFourHours() const { return m_isTwentyFourHours; }
  void SetTwentyFourHours(bool const on) { m_isTwentyFourHours = on; }

  TOpeningDays const & GetOpeningDays() const { return m_weekdays; }
  bool SetOpeningDays(TOpeningDays const & days);

  void AddWorkingDay(osmoh::Weekday const wd);
  bool RemoveWorkingDay(osmoh::Weekday const wd);

  osmoh::Timespan const & GetOpeningTime() const { return m_openingTime; }
  bool SetOpeningTime(osmoh::Timespan const & span);

  bool CanAddExcludeTime() const;
  bool AddExcludeTime(osmoh::Timespan const & span);
  bool ReplaceExcludeTime(osmoh::Timespan const & span, size_t const index);
  bool RemoveExcludeTime(size_t const index);
  osmoh::TTimespans const & GetExcludeTime() const { return m_excludeTime; }

  bool IsValid() const;

  osmoh::Timespan GetPredefinedOpeningTime() const;
  osmoh::Timespan GetPredefinedExcludeTime() const;

private:
  TimeTable() = default;

  bool m_isTwentyFourHours;
  TOpeningDays m_weekdays;
  osmoh::Timespan m_openingTime;
  osmoh::TTimespans m_excludeTime;
};

template <typename TTimeTableSet>
class TimeTableProxyBase : public TimeTable
{
public:
  TimeTableProxyBase(TTimeTableSet & tts, size_t const index, TimeTable const & tt):
      TimeTable(tt),
      m_index(index),
      m_tts(tts)
  {
  }

  bool Commit() { return m_tts.Replace(*this, m_index); } // Slice base class on copy.

private:
  size_t const m_index;
  TTimeTableSet & m_tts;
};

class TimeTableSet;
using TTimeTableProxy = TimeTableProxyBase<TimeTableSet>;

class TimeTableSet
{
  using TTimeTableSetImpl = vector<TimeTable>;

public:
  TimeTableSet();

  TOpeningDays GetUnhandledDays() const;

  TimeTable GetComplementTimeTable() const;

  TTimeTableProxy Get(size_t const index) { return TTimeTableProxy(*this, index, m_table[index]); }
  TTimeTableProxy Front() { return Get(0); }
  TTimeTableProxy Back() { return Get(Size() - 1); }

  size_t Size() const { return m_table.size(); }
  bool Empty() const { return m_table.empty(); }

  bool IsTwentyFourPerSeven() const;

  bool Append(TimeTable const & tt);
  bool Remove(size_t const index);

  bool Replace(TimeTable const & tt, size_t const index);

  TTimeTableSetImpl::const_iterator begin() const { return m_table.begin(); }
  TTimeTableSetImpl::const_iterator end() const { return m_table.end(); }

private:
  static bool UpdateByIndex(TimeTableSet & ttSet, size_t const index);

  TTimeTableSetImpl m_table;
};
} // namespace ui
} // namespace editor