Skip to content

Commit 4fda69d

Browse files
committed
Add ExecutionContext class
1 parent 774022a commit 4fda69d

File tree

10 files changed

+111
-0
lines changed

10 files changed

+111
-0
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ target_sources(scratchcpp
6767

6868
if (LIBSCRATCHCPP_USE_LLVM)
6969
target_compile_definitions(scratchcpp PUBLIC USE_LLVM)
70+
target_sources(scratchcpp
71+
PUBLIC
72+
include/scratchcpp/dev/executioncontext.h
73+
)
7074

7175
else()
7276
target_sources(scratchcpp
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
#pragma once
4+
5+
#include "../global.h"
6+
#include "../spimpl.h"
7+
8+
namespace libscratchcpp
9+
{
10+
11+
class Target;
12+
class ExecutionContextPrivate;
13+
14+
/*! \brief The ExecutionContext represents the execution context of a target (can be a clone) with variables, lists, etc. */
15+
class LIBSCRATCHCPP_EXPORT ExecutionContext
16+
{
17+
public:
18+
ExecutionContext(Target *target);
19+
ExecutionContext(const ExecutionContext &) = delete;
20+
virtual ~ExecutionContext() { }
21+
22+
Target *target() const;
23+
24+
private:
25+
spimpl::unique_impl_ptr<ExecutionContextPrivate> impl;
26+
};
27+
28+
} // namespace libscratchcpp

src/dev/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
add_subdirectory(blocks)
2+
add_subdirectory(engine)

src/dev/engine/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
target_sources(scratchcpp
2+
PRIVATE
3+
executioncontext.cpp
4+
executioncontext_p.cpp
5+
executioncontext_p.h
6+
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
#include <scratchcpp/dev/executioncontext.h>
4+
5+
#include "executioncontext_p.h"
6+
7+
using namespace libscratchcpp;
8+
9+
/*! Constructs ExecutionContext. */
10+
ExecutionContext::ExecutionContext(Target *target) :
11+
impl(spimpl::make_unique_impl<ExecutionContextPrivate>(target))
12+
{
13+
}
14+
15+
/*! Returns the Target of this context. */
16+
Target *ExecutionContext::target() const
17+
{
18+
return impl->target;
19+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
#include "executioncontext_p.h"
4+
5+
using namespace libscratchcpp;
6+
7+
ExecutionContextPrivate::ExecutionContextPrivate(Target *target) :
8+
target(target)
9+
{
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
#pragma once
4+
5+
namespace libscratchcpp
6+
{
7+
8+
class Target;
9+
10+
struct ExecutionContextPrivate
11+
{
12+
ExecutionContextPrivate(Target *target);
13+
14+
Target *target = nullptr;
15+
};
16+
17+
} // namespace libscratchcpp

test/dev/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
add_subdirectory(blocks)
2+
add_subdirectory(executioncontext)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
add_executable(
2+
executioncontext_test
3+
executioncontext_test.cpp
4+
)
5+
6+
target_link_libraries(
7+
executioncontext_test
8+
GTest::gtest_main
9+
scratchcpp
10+
)
11+
12+
gtest_discover_tests(executioncontext_test)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <scratchcpp/dev/executioncontext.h>
2+
#include <scratchcpp/target.h>
3+
4+
#include "../../common.h"
5+
6+
using namespace libscratchcpp;
7+
8+
TEST(ExecutionContextTest, Constructor)
9+
{
10+
Target target;
11+
ExecutionContext ctx(&target);
12+
ASSERT_EQ(ctx.target(), &target);
13+
}

0 commit comments

Comments
 (0)