Skip to content

Commit ab2ad19

Browse files
committed
Add monitor property to Variable
1 parent d14fe3b commit ab2ad19

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

include/scratchcpp/variable.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace libscratchcpp
1010
{
1111

1212
class Target;
13+
class Monitor;
1314
class VariablePrivate;
1415

1516
/*! \brief The Variable class represents a Scratch variable. */
@@ -33,6 +34,9 @@ class LIBSCRATCHCPP_EXPORT Variable : public Entity
3334
Target *target() const;
3435
void setTarget(Target *target);
3536

37+
Monitor *monitor() const;
38+
void setMonitor(Monitor *monitor);
39+
3640
std::shared_ptr<Variable> clone();
3741

3842
private:

src/scratch/variable.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ void Variable::setTarget(Target *target)
6161
impl->target = target;
6262
}
6363

64+
/*! Returns the monitor of this variable. */
65+
Monitor *Variable::monitor() const
66+
{
67+
return impl->monitor;
68+
}
69+
70+
/*! Sets the monitor of this variable. */
71+
void Variable::setMonitor(Monitor *monitor)
72+
{
73+
impl->monitor = monitor;
74+
}
75+
6476
/*! Creates a copy of the variable. */
6577
std::shared_ptr<Variable> Variable::clone()
6678
{

src/scratch/variable_p.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace libscratchcpp
88
{
99

1010
class Target;
11+
class Monitor;
1112

1213
struct VariablePrivate
1314
{
@@ -18,6 +19,7 @@ struct VariablePrivate
1819
Value value;
1920
bool isCloudVariable;
2021
Target *target = nullptr;
22+
Monitor *monitor = nullptr;
2123
};
2224

2325
} // namespace libscratchcpp

test/scratch_classes/variable_test.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <scratchcpp/variable.h>
22
#include <scratchcpp/target.h>
3+
#include <scratchcpp/monitor.h>
34

45
#include "../common.h"
56

@@ -68,6 +69,16 @@ TEST(VariableTest, Target)
6869
ASSERT_EQ(var.target(), &target);
6970
}
7071

72+
TEST(VariableTest, Monitor)
73+
{
74+
Variable var("", "");
75+
ASSERT_EQ(var.monitor(), nullptr);
76+
77+
Monitor monitor("", "");
78+
var.setMonitor(&monitor);
79+
ASSERT_EQ(var.monitor(), &monitor);
80+
}
81+
7182
TEST(VariableTest, Clone)
7283
{
7384
std::shared_ptr<Variable> clone;

0 commit comments

Comments
 (0)