File tree Expand file tree Collapse file tree 4 files changed +26
-0
lines changed
Expand file tree Collapse file tree 4 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,9 @@ class LIBSCRATCHCPP_EXPORT Script
3131 ExecutableCode *code () const ;
3232 void setCode (std::shared_ptr<ExecutableCode> code);
3333
34+ ExecutableCode *hatPredicateCode () const ;
35+ void setHatPredicateCode (std::shared_ptr<ExecutableCode> code);
36+
3437 bool runHatPredicate (Target *target);
3538
3639 std::shared_ptr<Thread> start ();
Original file line number Diff line number Diff line change @@ -42,6 +42,18 @@ void Script::setCode(std::shared_ptr<ExecutableCode> code)
4242 impl->code = code;
4343}
4444
45+ /* ! Returns the executable code of the hat predicate. */
46+ ExecutableCode *Script::hatPredicateCode () const
47+ {
48+ return impl->hatPredicateCode .get ();
49+ }
50+
51+ /* ! Sets the executable code of the hat predicate. */
52+ void Script::setHatPredicateCode (std::shared_ptr<ExecutableCode> code)
53+ {
54+ impl->hatPredicateCode = code;
55+ }
56+
4557/* !
4658 * Runs the edge-activated hat predicate as the given target and returns the reported value.
4759 * \note If there isn't any predicate, nothing will happen and the returned value will be false.
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ struct ScriptPrivate
2222 ScriptPrivate (const ScriptPrivate &) = delete ;
2323
2424 std::shared_ptr<ExecutableCode> code;
25+ std::shared_ptr<ExecutableCode> hatPredicateCode;
2526
2627 Target *target = nullptr ;
2728 std::shared_ptr<Block> topBlock;
Original file line number Diff line number Diff line change @@ -41,6 +41,16 @@ TEST_F(ScriptTest, Code)
4141 ASSERT_EQ (script.code (), code.get ());
4242}
4343
44+ TEST_F (ScriptTest, HatPredicateCode)
45+ {
46+ Script script (nullptr , nullptr , nullptr );
47+ ASSERT_EQ (script.hatPredicateCode (), nullptr );
48+
49+ auto code = std::make_shared<ExecutableCodeMock>();
50+ script.setHatPredicateCode (code);
51+ ASSERT_EQ (script.hatPredicateCode (), code.get ());
52+ }
53+
4454TEST_F (ScriptTest, Start)
4555{
4656 Script script1 (nullptr , nullptr , nullptr );
You can’t perform that action at this time.
0 commit comments