File tree Expand file tree Collapse file tree 5 files changed +36
-9
lines changed
Expand file tree Collapse file tree 5 files changed +36
-9
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ class LIBSCRATCHCPP_EXPORT Block : public Entity
2323 public:
2424 friend class Engine ;
2525
26- Block (const std::string &id, const std::string &opcode);
26+ Block (const std::string &id, const std::string &opcode, bool isMonitorBlock = false );
2727 Block (const Block &) = delete ;
2828
2929 CompilerValue *compile (Compiler *compiler);
@@ -90,6 +90,8 @@ class LIBSCRATCHCPP_EXPORT Block : public Entity
9090
9191 InputValue *topLevelReporterInfo ();
9292
93+ bool isMonitorBlock () const ;
94+
9395 private:
9496 void updateInputMap ();
9597 void updateFieldMap ();
Original file line number Diff line number Diff line change 1313using namespace libscratchcpp ;
1414
1515/* ! Constructs Block */
16- Block::Block (const std::string &id, const std::string &opcode) :
16+ Block::Block (const std::string &id, const std::string &opcode, bool isMonitorBlock ) :
1717 Entity(id),
18- impl(spimpl::make_unique_impl<BlockPrivate>(opcode))
18+ impl(spimpl::make_unique_impl<BlockPrivate>(opcode, isMonitorBlock ))
1919{
2020}
2121
@@ -117,6 +117,12 @@ InputValue *Block::topLevelReporterInfo()
117117 return nullptr ;
118118}
119119
120+ /* ! Returns true if this block belongs to a monitor. */
121+ bool Block::isMonitorBlock () const
122+ {
123+ return impl->isMonitorBlock ;
124+ }
125+
120126/* ! Returns the next block. */
121127std::shared_ptr<Block> Block::next () const
122128{
Original file line number Diff line number Diff line change 44
55using namespace libscratchcpp ;
66
7- BlockPrivate::BlockPrivate (const std::string &opcode) :
8- opcode(opcode)
7+ BlockPrivate::BlockPrivate (const std::string &opcode, bool isMonitorBlock) :
8+ opcode(opcode),
9+ isMonitorBlock(isMonitorBlock)
910{
1011}
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ class Comment;
1818
1919struct BlockPrivate
2020{
21- BlockPrivate (const std::string &opcode);
21+ BlockPrivate (const std::string &opcode, bool isMonitorBlock );
2222 BlockPrivate (const BlockPrivate &) = delete ;
2323
2424 std::string opcode;
@@ -43,6 +43,7 @@ struct BlockPrivate
4343 bool mutationHasNext = true ;
4444 bool isTopLevelReporter = false ;
4545 std::unique_ptr<InputValue> topLevelReporterInfo = nullptr ;
46+ bool isMonitorBlock = false ;
4647};
4748
4849} // namespace libscratchcpp
Original file line number Diff line number Diff line change @@ -33,9 +33,26 @@ class BlockTest : public testing::Test
3333
3434TEST_F (BlockTest, Constructors)
3535{
36- Block block (" abc" , " motion_movesteps" );
37- ASSERT_EQ (block.id (), " abc" );
38- ASSERT_EQ (block.opcode (), " motion_movesteps" );
36+ {
37+ Block block (" abc" , " motion_movesteps" );
38+ ASSERT_EQ (block.id (), " abc" );
39+ ASSERT_EQ (block.opcode (), " motion_movesteps" );
40+ ASSERT_FALSE (block.isMonitorBlock ());
41+ }
42+
43+ {
44+ Block block (" def" , " data_listcontents" , false );
45+ ASSERT_EQ (block.id (), " def" );
46+ ASSERT_EQ (block.opcode (), " data_listcontents" );
47+ ASSERT_FALSE (block.isMonitorBlock ());
48+ }
49+
50+ {
51+ Block block (" ghi" , " sensing_of" , true );
52+ ASSERT_EQ (block.id (), " ghi" );
53+ ASSERT_EQ (block.opcode (), " sensing_of" );
54+ ASSERT_TRUE (block.isMonitorBlock ());
55+ }
3956}
4057
4158TEST_F (BlockTest, Next)
You can’t perform that action at this time.
0 commit comments