nx_metadata_sdk 1.0 Metadata SDK

lib_context.h
1 // Copyright 2018-present Network Optix, Inc. Licensed under MPL 2.0: www.mozilla.org/MPL/2.0/
2
3 #pragma once
4
5 #include <string>
6 #include <memory>
7
8 #include <nx/sdk/helpers/i_ref_countable_registry.h>
9
10 namespace nx {
11 namespace sdk {
12
17 class ILibContext
18 {
19 public:
20 virtual ~ILibContext() = default;
21
22 virtual void setName(const char* name) = 0;
23 virtual void setRefCountableRegistry(IRefCountableRegistry* refCountableRegistry) = 0;
24 };
25
32 class LibContext final: public ILibContext
33 {
34 public:
39 virtual void setName(const char* name) override;
40
46 virtual void setRefCountableRegistry(IRefCountableRegistry* refCountableRegistry) override;
47
48 const std::string& name() const { return m_name; }
49
51 IRefCountableRegistry* refCountableRegistry() const { return m_refCountableRegistry.get(); }
52
53 private:
54 std::string m_name = "unnamed_lib_context";
55 std::unique_ptr<IRefCountableRegistry> m_refCountableRegistry;
56 };
57
58 //-------------------------------------------------------------------------------------------------
59
64 LibContext& libContext();
65
66 static constexpr const char* kNxLibContextFuncName = "nxLibContext";
67 typedef ILibContext* (*NxLibContextFunc)();
68
69 #if !defined(NX_SDK_API)
70 #if !defined(NX_PLUGIN_API)
71 #error "Either NX_SDK_API or NX_PLUGIN_API macro should be defined to export a function."
72 #endif
73 #define NX_SDK_API NX_PLUGIN_API
74 #endif
75
83 extern "C" NX_SDK_API ILibContext* nxLibContext();
84
85 } // namespace sdk
86 } // namespace nx
nx::sdk::LibContext::setRefCountableRegistry
virtual void setRefCountableRegistry(IRefCountableRegistry *refCountableRegistry) override
Definition: lib_context.cpp:18
nx::sdk::IRefCountableRegistry
Definition: i_ref_countable_registry.h:24
nx::sdk::LibContext::setName
virtual void setName(const char *name) override
Definition: lib_context.cpp:11
nx
Definition: apple_utils.h:6
nx::sdk::LibContext
Definition: lib_context.h:32
nx::sdk::LibContext::refCountableRegistry
IRefCountableRegistry * refCountableRegistry() const
Definition: lib_context.h:51
nx::sdk::ILibContext
Definition: lib_context.h:17