Skip to content

Commit b16a906

Browse files
committed
changed naming of signals from sig to signal to avoid confusion with signatures.
1 parent be40fcb commit b16a906

File tree

2 files changed

+43
-34
lines changed

2 files changed

+43
-34
lines changed

include/proto_activities.h

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
#ifdef _PA_ENABLE_CPP
2121
#include <functional> /* for std::function */
2222
#include <type_traits> /* for std::true_type, std::void_t, std::enable_if etc. */
23-
#if __cplusplus >= 201703L
24-
#include <optional>
25-
#endif
2623
#endif
2724

2825
/* Types */
@@ -509,61 +506,67 @@ namespace proto_activities {
509506
}
510507
Signal(const Signal&) = delete;
511508
Signal& operator=(const Signal&) {
512-
value_ = false;
509+
is_present_ = false;
513510
return *this;
514511
}
515512
void emit() {
516-
value_ = true;
513+
is_present_ = true;
517514
}
518515
operator bool() const {
519-
return value_;
516+
return is_present_;
520517
}
521518
void update() final {
522-
value_ = false;
519+
is_present_ = false;
523520
}
524521
private:
525-
bool value_;
522+
bool is_present_{};
526523
};
527-
#if __cplusplus >= 201703L
524+
528525
template <typename T>
529526
struct ValSignal final : Updatable {
530527
ValSignal(Enter& enter) {
531528
enter.add(this);
532529
}
533530
ValSignal(const ValSignal&) = delete;
534531
ValSignal& operator=(const ValSignal&) {
535-
value_.reset();
532+
is_present_ = false;
533+
has_emitted_val_ = false;
534+
value_ = {};
536535
return *this;
537536
}
538-
void emit(T&& t) {
539-
value_.emplace(std::move(t));
537+
void emit(T&& val) {
538+
is_present_ = true;
539+
has_emitted_val_ = true;
540+
value_ = std::move(val);
540541
}
541542
operator bool() const {
542-
return value_.has_value();
543+
return is_present_;
544+
}
545+
bool has_emitted_val() const {
546+
return has_emitted_val_;
543547
}
544548
const T& val() const {
545-
return *value_;
549+
return value_;
546550
}
547551
void update() final {
548-
value_.reset();
552+
is_present_ = false;
549553
}
550554
private:
551-
std::optional<T> value_;
555+
bool is_present_{};
556+
bool has_emitted_val_{};
557+
T value_{};
552558
};
553-
#endif
554559
}
555560

556-
using pa_sig = proto_activities::Signal;
557-
#define pa_sig_res pa_enter_res
558-
#define pa_def_sig(nm) pa_sig nm{_pa_enter};
561+
using pa_signal = proto_activities::Signal;
562+
#define pa_signal_res pa_enter_res
563+
#define pa_def_signal(sig) pa_signal sig{_pa_enter};
559564
#define pa_emit(sig) sig.emit();
560565

561-
#if __cplusplus >= 201703L
562566
template <typename T>
563-
using pa_val_sig = proto_activities::ValSignal<T>;
564-
#define pa_def_val_sig(ty, nm) pa_val_sig<ty> nm{_pa_enter};
567+
using pa_val_signal = proto_activities::ValSignal<T>;
568+
#define pa_def_val_signal(ty, sig) pa_val_signal<ty> sig{_pa_enter};
565569
#define pa_emit_val(sig, val) sig.emit(val);
566-
#endif
567570

568571
#endif
569572

tests_cpp/tests.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ pa_activity (TestLifecycle, pa_ctx(pa_co_res(2); pa_use(TestLifecycleBody); pa_u
809809

810810
// Signal Tests
811811

812-
pa_activity (TestSignalsBodySub, pa_ctx(), pa_sig& s1, pa_sig& s2) {
812+
pa_activity (TestSignalsBodySub, pa_ctx(), pa_signal& s1, pa_signal& s2) {
813813
assert(!s1); assert(!s2);
814814
pa_pause;
815815

@@ -822,8 +822,8 @@ pa_activity (TestSignalsBodySub, pa_ctx(), pa_sig& s1, pa_sig& s2) {
822822
pa_pause;
823823
} pa_end
824824

825-
pa_activity (TestSignalsBody, pa_ctx(pa_sig_res; pa_use(TestSignalsBodySub);
826-
pa_def_sig(s1); pa_def_sig(s2))) {
825+
pa_activity (TestSignalsBody, pa_ctx(pa_signal_res; pa_use(TestSignalsBodySub);
826+
pa_def_signal(s1); pa_def_signal(s2))) {
827827
assert(!pa_self.s1); assert(!pa_self.s2);
828828
pa_pause;
829829

@@ -845,34 +845,42 @@ pa_activity (TestSignals, pa_ctx_tm(pa_use(TestSignalsBody))) {
845845
pa_run (TestSignalsBody); // Test re-invocation after abort
846846
} pa_end
847847

848-
#if __cplusplus >= 201703L
849-
850-
pa_activity (TestValSignalsBodySub, pa_ctx(), pa_val_sig<int>& s1, pa_val_sig<float>& s2) {
848+
pa_activity (TestValSignalsBodySub, pa_ctx(), pa_val_signal<int>& s1, pa_val_signal<float>& s2) {
851849
assert(!s1); assert(!s2);
850+
assert(s1.has_emitted_val()); assert(s2.has_emitted_val());
852851
pa_pause;
853852

854853
assert(!s1); assert(!s2);
854+
assert(s1.has_emitted_val()); assert(s2.has_emitted_val());
855+
855856
pa_emit_val(s1, 42); pa_emit_val(s2, 3.14f);
856857
assert(s1); assert(s2);
858+
assert(s1.has_emitted_val()); assert(s2.has_emitted_val());
857859
assert(s1.val() == 42); assert(s2.val() != 0.0f);
858860
pa_pause;
859861

860862
assert(!s1); assert(!s2);
863+
assert(s1.has_emitted_val()); assert(s2.has_emitted_val());
861864
pa_pause;
862865
} pa_end
863866

864-
pa_activity (TestValSignalsBody, pa_ctx(pa_sig_res; pa_use(TestValSignalsBodySub);
865-
pa_def_val_sig(int, s1); pa_def_val_sig(float, s2))) {
867+
pa_activity (TestValSignalsBody, pa_ctx(pa_signal_res; pa_use(TestValSignalsBodySub);
868+
pa_def_val_signal(int, s1); pa_def_val_signal(float, s2))) {
866869
assert(!pa_self.s1); assert(!pa_self.s2);
870+
assert(!pa_self.s1.has_emitted_val()); assert(!pa_self.s2.has_emitted_val());
867871
pa_pause;
868872

869873
assert(!pa_self.s1); assert(!pa_self.s2);
874+
assert(!pa_self.s1.has_emitted_val()); assert(!pa_self.s2.has_emitted_val());
875+
870876
pa_emit_val(pa_self.s1, 42); pa_emit_val(pa_self.s2, 3.14f);
871877
assert(pa_self.s1); assert(pa_self.s2);
878+
assert(pa_self.s1.has_emitted_val()); assert(pa_self.s2.has_emitted_val());
872879
assert(pa_self.s1.val() == 42); assert(pa_self.s2.val() != 0.0f);
873880
pa_pause;
874881

875882
assert(!pa_self.s1); assert(!pa_self.s2);
883+
assert(pa_self.s1.has_emitted_val()); assert(pa_self.s2.has_emitted_val());
876884
pa_pause;
877885

878886
pa_run(TestValSignalsBodySub, pa_self.s1, pa_self.s2);
@@ -885,8 +893,6 @@ pa_activity (TestValSignals, pa_ctx_tm(pa_use(TestValSignalsBody))) {
885893
pa_run (TestValSignalsBody); // Test re-invocation after abort
886894
} pa_end
887895

888-
#endif
889-
890896
} // namespace tests
891897

892898
// Test Driver

0 commit comments

Comments
 (0)