Skip to content

Commit 5114029

Browse files
committed
Code cleanup
1 parent ced29ab commit 5114029

File tree

8 files changed

+442
-436
lines changed

8 files changed

+442
-436
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ jobs:
119119
shell: cmd /C CALL {0}
120120
run: |
121121
cd bld
122-
ctest -V --config Release -R test
122+
ctest -V --build-config Release -R test
123123
124124
- name: Run C++ examples
125125
shell: cmd /C CALL {0}
126126
run: |
127127
cd bld
128-
ctest -V --config Release -R example
128+
ctest -V --build-config Release -R example
129129
130130
- name: Install
131131
shell: cmd /C CALL {0}

CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ message(STATUS "Building xplugin v${${PROJECT_NAME}_VERSION}")
4949
# Headers
5050
################################################################
5151
set(XPLUGIN_HEADERS
52-
${XPLUGIN_INCLUDE_DIR}/xplugin/xplugin_config.hpp
53-
${XPLUGIN_INCLUDE_DIR}/xplugin/xshared_library.hpp
54-
${XPLUGIN_INCLUDE_DIR}/xplugin/xfactory.hpp
55-
${XPLUGIN_INCLUDE_DIR}/xplugin/xplugin_registry.hpp
52+
${XPLUGIN_INCLUDE_DIR}/xplugin/xfactory.hpp
53+
${XPLUGIN_INCLUDE_DIR}/xplugin/xlazy_shared_library_plugin_factory.hpp
54+
${XPLUGIN_INCLUDE_DIR}/xplugin/xplugin_config.hpp
55+
${XPLUGIN_INCLUDE_DIR}/xplugin/xplugin_registry.hpp
56+
${XPLUGIN_INCLUDE_DIR}/xplugin/xshared_library.hpp
5657
)
5758

5859
################################################################

environment_emscripten.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ dependencies:
77
- cmake
88
- python
99
- microsoft::playwright
10+
- nodejs

include/xplugin/xfactory.hpp

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,40 @@
2222
namespace xp
2323
{
2424

25-
template <class BASE_TYPE, class... ARGS>
26-
class xfactory_base
27-
{
28-
public:
29-
using base_type = BASE_TYPE;
30-
virtual ~xfactory_base() = default;
31-
virtual std::unique_ptr<base_type> create(ARGS...) = 0;
32-
};
33-
34-
// default implementation of the factory
35-
template <class CONCRETE_TYPE, class BASE_TYPE, class... ARGS>
36-
class xfactory : public xfactory_base<BASE_TYPE, ARGS...>
37-
{
38-
public:
39-
using concrete_type = CONCRETE_TYPE;
40-
using base_type = BASE_TYPE;
41-
using factory_base_type = xfactory_base<BASE_TYPE, ARGS...>;
42-
virtual ~xfactory() = default;
43-
std::unique_ptr<base_type> create(ARGS... args) override;
44-
};
45-
46-
template <class CONCRETE_TYPE, class BASE_TYPE, class... ARGS>
47-
auto xfactory<CONCRETE_TYPE, BASE_TYPE, ARGS...>::create(ARGS... args) -> std::unique_ptr<base_type>
48-
{
49-
return std::make_unique<concrete_type>(args...);
50-
}
25+
template <class BASE_TYPE, class... ARGS>
26+
class xfactory_base
27+
{
28+
public:
29+
using base_type = BASE_TYPE;
30+
31+
xfactory_base() = default;
32+
virtual ~xfactory_base() = default;
33+
34+
xfactory_base(const xfactory_base&) = delete;
35+
xfactory_base& operator=(const xfactory_base&) = delete;
36+
xfactory_base(xfactory_base&&) = delete;
37+
xfactory_base& operator=(xfactory_base&&) = delete;
38+
39+
virtual std::unique_ptr<base_type> create(ARGS...) = 0;
40+
};
41+
42+
// default implementation of the factory
43+
template <class CONCRETE_TYPE, class BASE_TYPE, class... ARGS>
44+
class xfactory : public xfactory_base<BASE_TYPE, ARGS...>
45+
{
46+
public:
47+
using concrete_type = CONCRETE_TYPE;
48+
using base_type = BASE_TYPE;
49+
using factory_base_type = xfactory_base<BASE_TYPE, ARGS...>;
50+
virtual ~xfactory() = default;
51+
std::unique_ptr<base_type> create(ARGS... args) override;
52+
};
53+
54+
template <class CONCRETE_TYPE, class BASE_TYPE, class... ARGS>
55+
auto xfactory<CONCRETE_TYPE, BASE_TYPE, ARGS...>::create(ARGS... args) -> std::unique_ptr<base_type>
56+
{
57+
return std::make_unique<concrete_type>(args...);
58+
}
5159

5260
} // namespace xp
5361

include/xplugin/xlazy_shared_library_plugin_factory.hpp

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,66 +16,66 @@
1616
namespace xp
1717
{
1818

19-
// lazy storage of a shared library
20-
// and the factory it contains.
21-
// Both are loaded / created on demand
22-
template <class FACTORY_BASE, bool THREAD_SAFE>
23-
class xlazy_shared_library_plugin_factory
24-
{
25-
public:
26-
using factory_base_type = FACTORY_BASE;
27-
xlazy_shared_library_plugin_factory(const xlazy_shared_library_plugin_factory &) = delete;
28-
xlazy_shared_library_plugin_factory &operator=(const xlazy_shared_library_plugin_factory &) = delete;
19+
// lazy storage of a shared library
20+
// and the factory it contains.
21+
// Both are loaded / created on demand
22+
template <class FACTORY_BASE, bool THREAD_SAFE>
23+
class xlazy_shared_library_plugin_factory
24+
{
25+
public:
26+
using factory_base_type = FACTORY_BASE;
27+
xlazy_shared_library_plugin_factory(const xlazy_shared_library_plugin_factory &) = delete;
28+
xlazy_shared_library_plugin_factory &operator=(const xlazy_shared_library_plugin_factory &) = delete;
2929

30-
xlazy_shared_library_plugin_factory(xlazy_shared_library_plugin_factory &&other) = delete;
31-
xlazy_shared_library_plugin_factory &operator=(xlazy_shared_library_plugin_factory &&other) = delete;
30+
xlazy_shared_library_plugin_factory(xlazy_shared_library_plugin_factory &&other) = delete;
31+
xlazy_shared_library_plugin_factory &operator=(xlazy_shared_library_plugin_factory &&other) = delete;
3232

33-
~xlazy_shared_library_plugin_factory() = default;
33+
~xlazy_shared_library_plugin_factory() = default;
3434

35-
inline xlazy_shared_library_plugin_factory(const std::filesystem::path &path);
35+
xlazy_shared_library_plugin_factory(const std::filesystem::path &path);
3636

37-
inline const std::filesystem::path &path() const noexcept;
37+
const std::filesystem::path& path() const noexcept;
3838

39-
factory_base_type *factory() const;
39+
factory_base_type* factory() const;
4040

41-
private:
42-
using create_plugin_factory_type = factory_base_type *(*)();
43-
using mutex_type = xmutex_t<THREAD_SAFE>;
44-
using scoped_lock_type = xscoped_lock_t<THREAD_SAFE, mutex_type>;
41+
private:
42+
using create_plugin_factory_type = factory_base_type *(*)();
43+
using mutex_type = xmutex_t<THREAD_SAFE>;
44+
using scoped_lock_type = xscoped_lock_t<THREAD_SAFE, mutex_type>;
4545

46-
mutable mutex_type m_mutex;
47-
std::filesystem::path m_path;
48-
mutable std::unique_ptr<xshared_library> m_library;
49-
mutable std::unique_ptr<factory_base_type> m_factory;
50-
};
46+
mutable mutex_type m_mutex;
47+
std::filesystem::path m_path;
48+
mutable std::unique_ptr<xshared_library> m_library;
49+
mutable std::unique_ptr<factory_base_type> m_factory;
50+
};
5151

52-
template <class FACTORY_BASE, bool THREAD_SAFE>
53-
inline xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::xlazy_shared_library_plugin_factory(
54-
const std::filesystem::path &path)
55-
: m_path(path),
56-
m_library()
57-
{
58-
}
59-
60-
template <class FACTORY_BASE, bool THREAD_SAFE>
61-
inline typename xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::factory_base_type *
62-
xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::factory() const
63-
{
64-
scoped_lock_type lock(m_mutex);
65-
if (!m_factory)
52+
template <class FACTORY_BASE, bool THREAD_SAFE>
53+
xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::xlazy_shared_library_plugin_factory(
54+
const std::filesystem::path &path)
55+
: m_path(path)
56+
, m_library()
6657
{
58+
}
6759

68-
m_library.reset(new xshared_library(m_path));
69-
m_factory.reset(m_library->find_symbol<create_plugin_factory_type>("create_plugin_factory")());
60+
template <class FACTORY_BASE, bool THREAD_SAFE>
61+
typename xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::factory_base_type *
62+
xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::factory() const
63+
{
64+
scoped_lock_type lock(m_mutex);
65+
if (!m_factory)
66+
{
67+
68+
m_library.reset(new xshared_library(m_path));
69+
m_factory.reset(m_library->find_symbol<create_plugin_factory_type>("create_plugin_factory")());
70+
}
71+
return m_factory.get();
7072
}
71-
return m_factory.get();
72-
}
7373

74-
template <class FACTORY_BASE, bool THREAD_SAFE>
75-
const std::filesystem::path &xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::path() const noexcept
76-
{
77-
return m_path;
78-
}
74+
template <class FACTORY_BASE, bool THREAD_SAFE>
75+
const std::filesystem::path& xlazy_shared_library_plugin_factory<FACTORY_BASE, THREAD_SAFE>::path() const noexcept
76+
{
77+
return m_path;
78+
}
7979

8080
} // namespace xp
8181

include/xplugin/xplugin_config.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010
#define XPLUGIN_CONFIG_HPP
1111

1212
#ifdef _WIN32
13-
#ifdef XPLUGIN_EXPORTS
14-
#define XPLUGIN_API __declspec(dllexport)
13+
# ifdef XPLUGIN_EXPORTS
14+
# define XPLUGIN_API __declspec(dllexport)
15+
# else
16+
# define XPLUGIN_API __declspec(dllimport)
17+
# endif
1518
#else
16-
#define XPLUGIN_API __declspec(dllimport)
17-
#endif
18-
19-
#else
20-
#define XPLUGIN_API
19+
# define XPLUGIN_API
2120
#endif
2221

2322
#define XPLUGIN_VERSION_MAJOR 0

0 commit comments

Comments
 (0)