Leosac  0.8.0
Open Source Access Control
Schedule.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include "LeosacFwd.hpp"
23 #include "tools/ISchedule.hpp"
26 #include "tools/ToolsFwd.hpp"
27 #include "tools/db/database.hpp"
28 #include <chrono>
29 #include <string>
30 #include <vector>
31 
32 namespace Leosac
33 {
34 namespace Tools
35 {
40 #pragma db object optimistic
41 class Schedule : public virtual ISchedule
42 {
43  public:
44  Schedule(const std::string &sched_name = "");
45  virtual ~Schedule() = default;
46  Schedule(const Schedule &) = default;
47 
48  const std::string &name() const override;
49 
50  bool
51  is_in_schedule(const std::chrono::system_clock::time_point &tp) const override;
52 
53  void add_timeframe(const SingleTimeFrame &tf) override;
54 
55  const std::string &description() const override;
56 
57  void name(const std::string &) override;
58 
59  void description(const std::string &) override;
60 
61  void clear_timeframes() override;
62 
63  ScheduleId id() const override;
64 
65  std::vector<SingleTimeFrame> timeframes() const override;
66 
67  void add_mapping(const Tools::ScheduleMappingPtr &map) override;
68 
69  void clear_mapping() override;
70 
71  std::vector<ScheduleMappingPtr> mapping() const override;
72 
73  size_t odb_version() const override;
74 
75  private:
76  friend class odb::access;
77  friend class ::Leosac::TestAccess;
78 
79 #pragma db id auto
81 
82 #pragma db id_column("schedule_id") value_column("timeframe")
83  std::vector<SingleTimeFrame> timeframes_;
84 
85 #pragma db unique
86  std::string name_;
87 
88  std::string description_;
89 
90 #pragma db id_column("schedule_id") value_column("schedule_mapping_id")
91  std::vector<Tools::ScheduleMappingPtr> mapping_;
92 
93 #pragma db version
94  size_t odb_version_;
95 };
96 
98 {
99  public:
100  static void validate(const ISchedule &sched);
101  static void validate_name(const std::string &name);
102 };
103 }
104 }
105 
106 #ifdef ODB_COMPILER
107 #include "tools/ScheduleMapping.hpp"
108 #endif
Leosac::Tools::Schedule::odb_version_
size_t odb_version_
Definition: Schedule.hpp:94
Leosac::Tools::Schedule::Schedule
Schedule(const std::string &sched_name="")
Definition: Schedule.cpp:27
Leosac::Tools::Schedule::timeframes_
std::vector< SingleTimeFrame > timeframes_
Definition: Schedule.hpp:83
Leosac::Tools::Schedule::name_
std::string name_
Definition: Schedule.hpp:86
Leosac::Tools::Schedule::timeframes
std::vector< SingleTimeFrame > timeframes() const override
Retrieves the list of timesframes that compose this schedule.
Definition: Schedule.cpp:63
database.hpp
LeosacFwd.hpp
Leosac::Tools::Schedule::id
ScheduleId id() const override
Definition: Schedule.cpp:58
Leosac::Tools::Schedule::mapping_
std::vector< Tools::ScheduleMappingPtr > mapping_
Definition: Schedule.hpp:91
Leosac::Tools::ScheduleMappingPtr
std::shared_ptr< ScheduleMapping > ScheduleMappingPtr
Definition: ToolsFwd.hpp:41
Leosac::Tools::Schedule::add_timeframe
void add_timeframe(const SingleTimeFrame &tf) override
Add the given timeframe to this schedule;.
Definition: Schedule.cpp:43
ISchedule.hpp
ToolsFwd.hpp
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Tools::Schedule::access
friend class odb::access
Definition: Schedule.hpp:76
Leosac::Tools::Schedule::description
const std::string & description() const override
Definition: Schedule.cpp:53
Leosac::Tools::ScheduleId
unsigned long ScheduleId
Definition: ToolsFwd.hpp:33
Leosac::Tools::Schedule::clear_mapping
void clear_mapping() override
Definition: Schedule.cpp:96
Leosac::Tools::ScheduleValidator
Definition: Schedule.hpp:97
Leosac::Tools::Schedule::name
const std::string & name() const override
Retrieve the name of the schedule.
Definition: Schedule.cpp:48
Leosac::Tools::ScheduleValidator::validate_name
static void validate_name(const std::string &name)
Definition: Schedule.cpp:111
Leosac::Tools::Schedule::clear_timeframes
void clear_timeframes() override
Remove all the timeframes from this schedule.
Definition: Schedule.cpp:84
Leosac::Tools::Schedule::id_
ScheduleId id_
Definition: Schedule.hpp:80
Leosac::Tools::Schedule::description_
std::string description_
Definition: Schedule.hpp:88
Leosac::Tools::ISchedule
Definition: ISchedule.hpp:38
Leosac::Tools::SingleTimeFrame
This struct abstracts what we call a single time frame.
Definition: SingleTimeFrame.hpp:38
ScheduleMapping.hpp
Leosac::Tools::Schedule
A schedule is simply a list of time frame (SingleTimeFrame) with a name.
Definition: Schedule.hpp:41
Leosac::Tools::Schedule::odb_version
size_t odb_version() const override
Definition: Schedule.cpp:68
Leosac::Tools::Schedule::mapping
std::vector< ScheduleMappingPtr > mapping() const override
Definition: Schedule.cpp:101
Leosac::Tools::Schedule::is_in_schedule
bool is_in_schedule(const std::chrono::system_clock::time_point &tp) const override
Check whether or not the given time point can be found in the schedule.
Definition: Schedule.cpp:33
Leosac::Tools::Schedule::add_mapping
void add_mapping(const Tools::ScheduleMappingPtr &map) override
Definition: Schedule.cpp:89
Leosac::Tools::Schedule::~Schedule
virtual ~Schedule()=default
Leosac::Tools::ScheduleValidator::validate
static void validate(const ISchedule &sched)
Definition: Schedule.cpp:106
SingleTimeFrame.hpp