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()},
62 using namespace cloe::schema;
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;
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)));
117 void to_json(cloe::Json& j)
const override {
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; }};
154 using namespace cloe::schema;
155 static const char* desc =
"optional number of seconds from current simulation time";
169 auto secs = cloe::Seconds{c.
get<
double>(
"time")};
170 next_time += std::chrono::duration_cast<cloe::Duration>(secs);
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: trigger.hpp:570
void emplace(TriggerPtr &&t, const Sync &s) override
Definition: trigger.hpp:578
Definition: trigger.hpp:533
friend void to_json(fable::Json &j, const Entity &e)
Definition: entity.hpp:120
void set_name(std::string name)
Definition: entity.cpp:30
const std::string & description() const
Definition: entity.hpp:90
const std::string & name() const
Definition: entity.hpp:67
Definition: trigger.hpp:478
virtual Duration time() const =0
Definition: trigger.hpp:290
Definition: trigger.hpp:396
Definition: time_event.hpp:185
void emplace(cloe::TriggerPtr &&t, const cloe::Sync &s) override
Definition: time_event.hpp:188
Definition: time_event.hpp:149
std::unique_ptr< cloe::Event > make(const cloe::Conf &c) const override
Definition: time_event.hpp:166
std::unique_ptr< cloe::Event > make(const std::string &s) const override
Definition: time_event.hpp:175
cloe::TriggerSchema schema() const override
Definition: time_event.hpp:153
Definition: time_event.hpp:98
void emplace(cloe::TriggerPtr &&t, const cloe::Sync &sync) override
Definition: time_event.hpp:102
Definition: time_event.hpp:39
cloe::EventPtr clone() const override
Definition: time_event.hpp:43
Definition: time_event.hpp:57
cloe::EventPtr make(const cloe::Conf &c) const override
Definition: time_event.hpp:74
cloe::EventPtr make(const std::string &s) const override
Definition: time_event.hpp:79
cloe::TriggerSchema schema() const override
Definition: time_event.hpp:61
bool has(const std::string &key) const
Definition: conf.hpp:166
T get() const
Definition: conf.hpp:298
Definition: schema.hpp:173
Definition: number.hpp:36
std::chrono::nanoseconds Duration
Definition: cloe_fwd.hpp:36
Definition: trigger.hpp:87
Definition: trigger.hpp:207
Definition: time_event.hpp:86