43 cloe::EventPtr
clone()
const override {
return std::make_unique<TimeEvent>(
name(), time_); }
44 void to_json(cloe::Json& j)
const override {
46 {
"time", cloe::Seconds{time_}.count()},
63 static const char* desc =
"absolute number of seconds in simulation time";
75 auto secs = cloe::Seconds{c.
get<
double>(
"time")};
76 return std::make_unique<TimeEvent>(
name(), std::chrono::duration_cast<
cloe::Duration>(secs));
79 cloe::EventPtr
make(
const std::string& s)
const override {
81 {
"time", std::stod(s)},
93 cloe::TriggerPtr trigger;
96 using TimeEmplaceHook = std::function<void(const cloe::Trigger&, cloe::Duration)>;
100 TimeCallback(cloe::Logger log, TimeEmplaceHook h) : log_(log), hook_(h) {}
103 auto now = sync.
time();
104 auto when =
dynamic_cast<const TimeEvent&
>(t->event()).time();
107 log_->error(
"Inserting timed trigger for the past!");
108 log_->error(
"> trigger time = {} s", std::chrono::duration_cast<cloe::Seconds>(when).count());
109 log_->error(
"> current time = {} s", std::chrono::duration_cast<cloe::Seconds>(now).count());
111 if (t->is_sticky()) {
112 log_->error(
"Inserting timed trigger that is sticky discards stickiness!");
114 storage_.emplace(std::make_shared<TimeTrigger>(when, std::move(t)));
119 decltype(storage_) st_copy{storage_};
120 while (!st_copy.empty()) {
121 j.push_back(st_copy.top());
127 auto now = sync.
time();
128 while (!storage_.empty() && storage_.top()->time <= now) {
129 auto tt = storage_.top();
131 this->execute(std::move(tt->trigger), sync);
137 TimeEmplaceHook hook_;
143 std::shared_ptr<TimeTrigger>, std::vector<std::shared_ptr<TimeTrigger>>,
144 std::function<bool(const std::shared_ptr<TimeTrigger>&,
const std::shared_ptr<TimeTrigger>&)>>
145 storage_{[](
const std::shared_ptr<TimeTrigger>& x,
146 const std::shared_ptr<TimeTrigger>& y) ->
bool {
return x->time > y->time; }};
155 static const char* desc =
"optional number of seconds from current simulation time";
161 {
"time", Number<double>(
nullptr, desc)},
169 auto secs = cloe::Seconds{c.
get<
double>(
"time")};
172 return std::make_unique<TimeEvent>(
name(), next_time);
175 std::unique_ptr<cloe::Event>
make(
const std::string& s)
const override {
178 {
"time", std::stod(s)},
187 using cloe::AliasCallback::AliasCallback;
189 auto& time_event =
const_cast<TimeEvent&
>(
dynamic_cast<const TimeEvent&
>(t->event()));
191 time_event.time_ += s.
time();
Definition: time_event.hpp:185
cloe::EventPtr make(const cloe::Conf &c) const override
Definition: time_event.hpp:74
virtual Duration time() const =0
void to_json(cloe::Json &j) const override
Definition: time_event.hpp:44
Definition: time_event.hpp:149
Definition: number.hpp:39
Definition: trigger.hpp:579
Definition: time_event.hpp:86
T get() const
Definition: conf.hpp:164
void emplace(cloe::TriggerPtr &&t, const cloe::Sync &s) override
Definition: time_event.hpp:188
std::unique_ptr< cloe::Event > make(const std::string &s) const override
Definition: time_event.hpp:175
std::unique_ptr< cloe::Event > make(const cloe::Conf &c) const override
Definition: time_event.hpp:166
bool has(const std::string &key) const
Definition: conf.hpp:130
Definition: time_event.hpp:98
void set_name(const std::string &name)
Definition: entity.cpp:30
Definition: time_event.hpp:39
std::chrono::nanoseconds Duration
Definition: duration.hpp:45
void emplace(TriggerPtr &&t, const Sync &s) override
Definition: trigger.hpp:587
Definition: trigger.hpp:487
Definition: schema.hpp:178
void emplace(cloe::TriggerPtr &&t, const cloe::Sync &sync) override
Definition: time_event.hpp:102
Definition: time_event.hpp:57
Definition: trigger.hpp:300
void to_json(cloe::Json &j) const override
Definition: time_event.hpp:117
cloe::TriggerSchema schema() const override
Definition: time_event.hpp:61
std::string name() const
Definition: entity.hpp:68
std::string description() const
Definition: entity.hpp:91
Definition: trigger.hpp:542
cloe::EventPtr clone() const override
Definition: time_event.hpp:43
cloe::TriggerSchema schema() const override
Definition: time_event.hpp:153
Definition: coordinator.cpp:39
Definition: trigger.hpp:87
cloe::EventPtr make(const std::string &s) const override
Definition: time_event.hpp:79
Definition: trigger.hpp:207