Skip to content

Commit bb2aa3e

Browse files
committed
Add monitor property to List
1 parent ab2ad19 commit bb2aa3e

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

include/scratchcpp/list.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace libscratchcpp
1212
{
1313

1414
class Target;
15+
class Monitor;
1516
class ListPrivate;
1617

1718
/*! \brief The List class represents a Scratch list. */
@@ -29,6 +30,9 @@ class LIBSCRATCHCPP_EXPORT List
2930
Target *target() const;
3031
void setTarget(Target *target);
3132

33+
Monitor *monitor() const;
34+
void setMonitor(Monitor *monitor);
35+
3236
long indexOf(const Value &value) const;
3337
bool contains(const Value &value) const;
3438

src/scratch/list.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ void List::setTarget(Target *target)
3838
impl->target = target;
3939
}
4040

41+
/*! Returns the monitor of this list. */
42+
Monitor *List::monitor() const
43+
{
44+
return impl->monitor;
45+
}
46+
47+
/*! Sets the monitor of this list. */
48+
void List::setMonitor(Monitor *monitor)
49+
{
50+
impl->monitor = monitor;
51+
}
52+
4153
/*! Returns the index of the given item. */
4254
long List::indexOf(const Value &value) const
4355
{

src/scratch/list_p.h

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

1010
class Target;
11+
class Monitor;
1112

1213
struct ListPrivate
1314
{
1415
ListPrivate(const std::string &name);
1516

1617
std::string name;
1718
Target *target = nullptr;
19+
Monitor *monitor = nullptr;
1820
};
1921

2022
} // namespace libscratchcpp

test/scratch_classes/list_test.cpp

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

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

@@ -29,6 +30,16 @@ TEST(ListTest, Target)
2930
ASSERT_EQ(list.target(), &target);
3031
}
3132

33+
TEST(ListTest, Monitor)
34+
{
35+
List list("", "");
36+
ASSERT_EQ(list.monitor(), nullptr);
37+
38+
Monitor monitor("", "");
39+
list.setMonitor(&monitor);
40+
ASSERT_EQ(list.monitor(), &monitor);
41+
}
42+
3243
TEST(ListTest, IndexOf)
3344
{
3445
List list("", "test list");

0 commit comments

Comments
 (0)