Skip to content

Commit bc135d0

Browse files
committed
Add a factory for ICodeBuilder
1 parent 3a68b54 commit bc135d0

File tree

5 files changed

+73
-0
lines changed

5 files changed

+73
-0
lines changed

src/dev/engine/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ target_sources(scratchcpp
44
executioncontext_p.cpp
55
executioncontext_p.h
66
internal/icodebuilder.h
7+
internal/icodebuilderfactory.h
8+
internal/codebuilderfactory.cpp
9+
internal/codebuilderfactory.h
710
internal/llvmcodebuilder.cpp
811
internal/llvmcodebuilder.h
912
internal/llvmexecutablecode.cpp
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
#include "codebuilderfactory.h"
4+
#include "llvmcodebuilder.h"
5+
6+
using namespace libscratchcpp;
7+
8+
std::shared_ptr<CodeBuilderFactory> CodeBuilderFactory::m_instance = std::make_shared<CodeBuilderFactory>();
9+
10+
std::shared_ptr<CodeBuilderFactory> CodeBuilderFactory::instance()
11+
{
12+
return m_instance;
13+
}
14+
15+
std::shared_ptr<ICodeBuilder> CodeBuilderFactory::create(const std::string &id) const
16+
{
17+
return std::make_shared<LLVMCodeBuilder>(id);
18+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
#pragma once
4+
5+
#include "icodebuilderfactory.h"
6+
7+
namespace libscratchcpp
8+
{
9+
10+
class CodeBuilderFactory : public ICodeBuilderFactory
11+
{
12+
public:
13+
static std::shared_ptr<CodeBuilderFactory> instance();
14+
std::shared_ptr<ICodeBuilder> create(const std::string &id) const override;
15+
16+
private:
17+
static std::shared_ptr<CodeBuilderFactory> m_instance;
18+
};
19+
20+
} // namespace libscratchcpp
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
#pragma once
4+
5+
#include <memory>
6+
7+
namespace libscratchcpp
8+
{
9+
10+
class ICodeBuilder;
11+
12+
class ICodeBuilderFactory
13+
{
14+
public:
15+
virtual ~ICodeBuilderFactory() { }
16+
17+
virtual std::shared_ptr<ICodeBuilder> create(const std::string &id) const = 0;
18+
};
19+
20+
} // namespace libscratchcpp
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
#include <dev/engine/internal/icodebuilderfactory.h>
4+
#include <gmock/gmock.h>
5+
6+
using namespace libscratchcpp;
7+
8+
class CodeBuilderFactoryMock : public ICodeBuilderFactory
9+
{
10+
public:
11+
MOCK_METHOD(std::shared_ptr<ICodeBuilder>, create, (const std::string &), (const, override));
12+
};

0 commit comments

Comments
 (0)