File tree Expand file tree Collapse file tree 4 files changed +61
-0
lines changed
Expand file tree Collapse file tree 4 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ class IEngine;
1212class Target ;
1313class Input ;
1414class Field ;
15+ class InputValue ;
1516class BlockPrivate ;
1617
1718/* ! \brief The Block class represents a Scratch block. */
@@ -68,6 +69,11 @@ class LIBSCRATCHCPP_EXPORT Block : public Entity
6869
6970 BlockPrototype *mutationPrototype ();
7071
72+ bool isTopLevelReporter () const ;
73+ void setIsTopLevelReporter (bool isTopLevelReporter);
74+
75+ InputValue *topLevelReporterInfo ();
76+
7177 private:
7278 spimpl::unique_impl_ptr<BlockPrivate> impl;
7379};
Original file line number Diff line number Diff line change @@ -58,6 +58,41 @@ BlockPrototype *Block::mutationPrototype()
5858 return &impl->mutationPrototype ;
5959}
6060
61+ /* ! Returns true if this is a top level reporter block for a variable or a list. */
62+ bool Block::isTopLevelReporter () const
63+ {
64+ return impl->isTopLevelReporter ;
65+ }
66+
67+ /* !
68+ * Sets whether this block is a top level reporter block for a variable or a list.
69+ * \note Setting this to true will allow the use topLevelReporterInfo().
70+ */
71+ void Block::setIsTopLevelReporter (bool isTopLevelReporter)
72+ {
73+ impl->isTopLevelReporter = isTopLevelReporter;
74+
75+ if (isTopLevelReporter && !impl->topLevelReporterInfo )
76+ impl->topLevelReporterInfo = std::make_unique<InputValue>(InputValue::Type::Variable);
77+ else if (impl->topLevelReporterInfo ) {
78+ impl->topLevelReporterInfo .reset ();
79+ impl->topLevelReporterInfo = nullptr ;
80+ }
81+ }
82+
83+ /* !
84+ * Returns the information about this top level reporter block (if this is a top level reporter block).
85+ * \note This function will return nullptr if this isn't a top level reporter block. Use setIsTopLevelReporter(true)
86+ * before using this function.
87+ */
88+ InputValue *Block::topLevelReporterInfo ()
89+ {
90+ if (impl->topLevelReporterInfo )
91+ return impl->topLevelReporterInfo .get ();
92+ else
93+ return nullptr ;
94+ }
95+
6196/* ! Returns the next block. */
6297std::shared_ptr<Block> Block::next () const
6398{
Original file line number Diff line number Diff line change 33#pragma once
44
55#include < scratchcpp/blockprototype.h>
6+ #include < scratchcpp/inputvalue.h>
67
78namespace libscratchcpp
89{
@@ -33,6 +34,8 @@ struct BlockPrivate
3334 Target *target = nullptr ;
3435 BlockPrototype mutationPrototype;
3536 bool mutationHasNext = true ;
37+ bool isTopLevelReporter = false ;
38+ std::unique_ptr<InputValue> topLevelReporterInfo = nullptr ;
3639};
3740
3841} // namespace libscratchcpp
Original file line number Diff line number Diff line change @@ -241,3 +241,20 @@ TEST_F(BlockTest, MutationPrototype)
241241 Block block (" " , " " );
242242 ASSERT_TRUE (block.mutationPrototype ());
243243}
244+
245+ TEST_F (BlockTest, TopLevelReporter)
246+ {
247+ Block block (" " , " " );
248+ ASSERT_FALSE (block.isTopLevelReporter ());
249+ ASSERT_EQ (block.topLevelReporterInfo (), nullptr );
250+
251+ for (int i = 0 ; i < 2 ; i++) {
252+ block.setIsTopLevelReporter (true );
253+ ASSERT_TRUE (block.isTopLevelReporter ());
254+ ASSERT_TRUE (block.topLevelReporterInfo ());
255+
256+ block.setIsTopLevelReporter (false );
257+ ASSERT_FALSE (block.isTopLevelReporter ());
258+ ASSERT_EQ (block.topLevelReporterInfo (), nullptr );
259+ }
260+ }
You can’t perform that action at this time.
0 commit comments