69 void log(
const string & msg)
72 cout <<
"[SmartHome] " << msg <<
endl;
85 state->log(
"Lights turned ON");
94 state->log(
"Lights turned OFF");
103 state->log(
"Temperature increased to " +
to_string(state->temperature) +
"C");
112 state->log(
"Security System ARMED");
121 state->alarm_armed =
true;
122 state->log(
"PANIC! Lights ON, Alarm ARMED, Police Notified!");
132 cout <<
"\n=== LEGACY EXAMPLE: Smart Home Event Simulation (void* interface) ===" <<
endl;
139 cout <<
"Registering events..." <<
endl;
148 cout <<
"-----------------------------------" <<
endl;
178 if (
home.lights_on &&
home.alarm_armed)
179 cout <<
" (System responded correctly to panic)" <<
endl;
182 cout <<
"\n=== Legacy Example Finished ===" <<
endl;
197 void log(
const string & msg)
199 cout <<
"[ModernHome] " << msg <<
endl;
205 cout <<
"\n=== MODERN EXAMPLE: Type-Safe Event System with Lambdas ===" <<
endl;
217 h.log(
"Lights turned ON (lambda)");
223 h.log(
"Lights turned OFF (lambda)");
229 h.log(
"Temperature increased to " +
to_string(
h.temperature) +
235 h.alarm_armed =
true;
236 h.log(
"Security System ARMED (lambda)");
244 return h.alarm_armed && !
h.lights_on;
249 return h.temperature >= 20 &&
h.temperature <= 24;
259 "C (lambda with param)");
263 cout <<
"\n--- Scenario: Evening Routine ---" <<
endl;
277 cout <<
"\n--- Advanced: Stateful Event (Counter) ---" <<
endl;
294 cout <<
"\n=== Modern Example Finished ===" <<
endl;
308 cout <<
"\n=== All Examples Completed ===" <<
endl;
size_t size() const noexcept
Count the number of elements of the list.
Dynamic (growable) event table implementation.
Event-driven table abstraction for event-driven simulations.
void * on_lights_on(void *data)
void * on_lights_off(void *data)
void * on_temp_up(void *data)
void run_legacy_example()
void run_modern_example()
void * on_arm_alarm(void *data)
void * on_panic(void *data)
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
DynList< T > maps(const C &c, Op op)
Classic map operation.
void log(const string &msg)
void log(const string &msg)