Skip to content

Commit

Permalink
update: change to static lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Lord-Turmoil committed Sep 24, 2023
1 parent 1cd17b0 commit e5434fd
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 26 deletions.
9 changes: 7 additions & 2 deletions mioc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Copyright (C) 2018 - 2023 Tony's Studio. All rights reserved.
# CMakeLists for MinIoc.

add_library(mioc INTERFACE)
target_include_directories(mioc INTERFACE include)
# Add all source files
file(GLOB_RECURSE SRC_LIST CONFIGURE_DEPENDS src/*.cpp)

# Add source to this project's executable.
add_library(mioc STATIC ${SRC_LIST} "src/ServiceContainer.cpp")

target_include_directories(mioc PUBLIC include)
7 changes: 1 addition & 6 deletions mioc/include/mioc/ServiceContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ using ServiceContainerPtr = std::shared_ptr<ServiceContainer>;
class ServiceContainer final
{
public:
explicit ServiceContainer(bool lazy = DEFAULT_LAZINESS) : _lazy(lazy)
{
}
explicit ServiceContainer(bool lazy = DEFAULT_LAZINESS);

// Any copy of service container is not allowed.
ServiceContainer(const ServiceContainer&) = delete;
Expand Down Expand Up @@ -125,9 +123,6 @@ class ServiceContainer final
bool _lazy;
};

// This is a random number, change it as you wish.
int ServiceContainer::_nextTypeId = 75159;


MIOC_END

Expand Down
26 changes: 8 additions & 18 deletions mioc/include/mioc/SingletonContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,18 @@
MIOC_BEGIN


class SingletonContainer
class SingletonContainer final
{
public:
SingletonContainer(const SingletonContainer&) = delete;
SingletonContainer& operator=(const SingletonContainer&) = delete;
SingletonContainer(SingletonContainer&&) = delete;
SingletonContainer& operator=(SingletonContainer&&) = delete;

~SingletonContainer() = default;

static ServiceContainerPtr GetContainer()
{
if (_container == nullptr)
{
_container = ServiceContainer::New(_lazy);
}
return _container;
}

static ServiceContainerPtr GetContainer(bool lazy)
{
_lazy = lazy;
return GetContainer();
}
static ServiceContainerPtr GetContainer();
static ServiceContainerPtr GetContainer(bool lazy);

private:
// Prevent instantiation.
Expand All @@ -41,9 +34,6 @@ class SingletonContainer
static bool _lazy;
};

std::shared_ptr<ServiceContainer> SingletonContainer::_container;
bool SingletonContainer::_lazy = DEFAULT_LAZINESS;


MIOC_END

Expand Down
12 changes: 12 additions & 0 deletions mioc/src/ServiceContainer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <mioc/ServiceContainer.h>

MIOC_BEGIN

ServiceContainer::ServiceContainer(bool lazy) : _lazy(lazy)
{
}

// This is a random number, change it as you wish.
int ServiceContainer::_nextTypeId = 75159;

MIOC_END
25 changes: 25 additions & 0 deletions mioc/src/SingletonContainer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <mioc/SingletonContainer.h>

MIOC_BEGIN


ServiceContainerPtr SingletonContainer::GetContainer()
{
if (_container == nullptr)
{
_container = ServiceContainer::New(_lazy);
}
return _container;
}

ServiceContainerPtr SingletonContainer::GetContainer(bool lazy)
{
_lazy = lazy;
return GetContainer();
}

std::shared_ptr<ServiceContainer> SingletonContainer::_container;
bool SingletonContainer::_lazy = DEFAULT_LAZINESS;


MIOC_END

0 comments on commit e5434fd

Please sign in to comment.