neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
plugin.hpp
Go to the documentation of this file.
1/*
2 plugin.hpp
3
4 Copyright (c) 2021 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neolib/neolib.hpp>
26
27namespace neolib
28{
29 template <typename T>
30 class plugin : public neolib::reference_counted<neolib::i_plugin>
31 {
32 public:
33 typedef T value_type;
34 typedef typename value_type::abstract_type abstract_value_type;
35 public:
37 neolib::i_application& aApplication,
38 const neolib::uuid& aId = value_type::plugin_id(),
39 std::string const& aName = value_type::plugin_name(),
40 std::string const& aDescription = value_type::plugin_description(),
41 const neolib::version& aVersion = value_type::plugin_version(),
42 std::string const& aCopyright = value_type::plugin_copyright()) :
43 iApplication{ aApplication },
44 iId{ aId },
45 iName{ aName },
46 iDescription{ aDescription },
47 iVersion{ aVersion },
48 iCopyright{ aCopyright },
49 iLoaded{ false }
50 {
51 }
52 public:
53 bool discover(const neolib::uuid& aId, void*& aObject) override
54 {
55 if (aId == abstract_value_type::iid())
56 {
57 if (!iContents)
58 iContents = neolib::make_ref<value_type>(iApplication, "file:///" + boost::dll::this_line_location().string());
59 aObject = &*iContents;
60 return true;
61 }
62 return false;
63 }
64 public:
65 const neolib::uuid& id() const override
66 {
67 return iId;
68 }
69 const neolib::i_string& name() const override
70 {
71 return iName;
72 }
73 const neolib::i_string& description() const override
74 {
75 return iDescription;
76 }
77 const neolib::i_version& version() const override
78 {
79 return iVersion;
80 }
81 const neolib::i_string& copyright() const override
82 {
83 return iCopyright;
84 }
85 bool load() override
86 {
87 iLoaded = true;
88 return true;
89 }
90 bool unload() override
91 {
92 iContents.reset();
93 iLoaded = false;
94 return true;
95 }
96 bool loaded() const override
97 {
98 return iLoaded;
99 }
100 bool open_uri(const neolib::i_string& aUri) override
101 {
102 return false;
103 }
104 private:
105 neolib::i_application& iApplication;
106 neolib::uuid iId;
107 neolib::string iName;
108 neolib::string iDescription;
109 neolib::version iVersion;
110 neolib::string iCopyright;
111 bool iLoaded;
112 ref_ptr<value_type> iContents;
113 };
114}
const neolib::i_string & copyright() const override
Definition plugin.hpp:81
bool loaded() const override
Definition plugin.hpp:96
bool open_uri(const neolib::i_string &aUri) override
Definition plugin.hpp:100
bool unload() override
Definition plugin.hpp:90
bool load() override
Definition plugin.hpp:85
const neolib::i_version & version() const override
Definition plugin.hpp:77
const neolib::uuid & id() const override
Definition plugin.hpp:65
const neolib::i_string & description() const override
Definition plugin.hpp:73
const neolib::i_string & name() const override
Definition plugin.hpp:69
plugin(neolib::i_application &aApplication, const neolib::uuid &aId=value_type::plugin_id(), std::string const &aName=value_type::plugin_name(), std::string const &aDescription=value_type::plugin_description(), const neolib::version &aVersion=value_type::plugin_version(), std::string const &aCopyright=value_type::plugin_copyright())
Definition plugin.hpp:36
bool discover(const neolib::uuid &aId, void *&aObject) override
Definition plugin.hpp:53
value_type::abstract_type abstract_value_type
Definition plugin.hpp:34
void reset() override
ref_ptr< ConcreteType > make_ref(Args &&... args)