Skip to content

Commit 11de169

Browse files
committed
Block: Add isMonitorBlock property
1 parent 4b32859 commit 11de169

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed

include/scratchcpp/block.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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();

src/scratch/block.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
using 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. */
121127
std::shared_ptr<Block> Block::next() const
122128
{

src/scratch/block_p.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
using 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
}

src/scratch/block_p.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Comment;
1818

1919
struct 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

test/scratch_classes/block_test.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,26 @@ class BlockTest : public testing::Test
3333

3434
TEST_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

4158
TEST_F(BlockTest, Next)

0 commit comments

Comments
 (0)