Skip to content

Commit dd51952

Browse files
committed
Add target property to List
1 parent 8297cd5 commit dd51952

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

include/scratchcpp/list.h

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

14+
class Target;
1415
class ListPrivate;
1516

1617
/*! \brief The List class represents a Scratch list. */
@@ -25,6 +26,9 @@ class LIBSCRATCHCPP_EXPORT List
2526
const std::string &name();
2627
void setName(const std::string &name);
2728

29+
Target *target() const;
30+
void setTarget(Target *target);
31+
2832
long indexOf(const Value &value) const;
2933
bool contains(const Value &value) const;
3034

src/scratch/list.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ void List::setName(const std::string &name)
2626
impl->name = name;
2727
}
2828

29+
/*! Returns the sprite or stage this list belongs to. */
30+
Target *List::target() const
31+
{
32+
return impl->target;
33+
}
34+
35+
/*! Sets the sprite or stage this list belongs to. */
36+
void List::setTarget(Target *target)
37+
{
38+
impl->target = target;
39+
}
40+
2941
/*! Returns the index of the given item. */
3042
long List::indexOf(const Value &value) const
3143
{

src/scratch/list_p.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
namespace libscratchcpp
88
{
99

10+
class Target;
11+
1012
struct ListPrivate
1113
{
1214
ListPrivate(const std::string &name);
1315

1416
std::string name;
17+
Target *target = nullptr;
1518
};
1619

1720
} // namespace libscratchcpp

test/scratch_classes/list_test.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <scratchcpp/list.h>
2+
#include <scratchcpp/target.h>
23

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

@@ -18,6 +19,16 @@ TEST(ListTest, Name)
1819
ASSERT_EQ(list.name(), "test list");
1920
}
2021

22+
TEST(ListTest, Target)
23+
{
24+
List list("", "");
25+
ASSERT_EQ(list.target(), nullptr);
26+
27+
Target target;
28+
list.setTarget(&target);
29+
ASSERT_EQ(list.target(), &target);
30+
}
31+
2132
TEST(ListTest, IndexOf)
2233
{
2334
List list("", "test list");

0 commit comments

Comments
 (0)