nexuslua
Loading...
Searching...
No Matches
plugin_registry.hpp
Go to the documentation of this file.
1/*
2Copyright (c) 2025 acrion innovations GmbH
3Authors: Stefan Zipproth, s.zipproth@acrion.ch
4
5This file is part of nexuslua, see https://github.com/acrion/nexuslua and https://nexuslua.org
6
7nexuslua is offered under a commercial and under the AGPL license.
8For commercial licensing, contact us at https://acrion.ch/sales. For AGPL licensing, see below.
9
10AGPL licensing:
11
12nexuslua is free software: you can redistribute it and/or modify
13it under the terms of the GNU Affero General Public License as published by
14the Free Software Foundation, either version 3 of the License, or
15(at your option) any later version.
16
17nexuslua is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20GNU Affero General Public License for more details.
21
22You should have received a copy of the GNU Affero General Public License
23along with nexuslua. If not, see <https://www.gnu.org/licenses/>.
24*/
25
26#pragma once
27
29
30#include "nexuslua_export.h"
31
32#include <cstddef>
33#include <memory>
34#include <string>
35
36namespace nexuslua
37{
38 class Agent;
39 class agents;
40
42 class NEXUSLUA_EXPORT PluginRegistry
43 {
44 struct Impl;
45 std::unique_ptr<Impl> _impl;
46
47 public:
49 struct NEXUSLUA_EXPORT Iterator
50 {
51 using iterator_category = std::input_iterator_tag;
52 using difference_type = std::ptrdiff_t;
53 using value_type = std::shared_ptr<Agent>;
55 using pointer = struct
56 {
57 Impl* impl;
58 std::size_t pos;
59 };
60
63 explicit Iterator(pointer ptr)
64 : m_ptr(ptr) {}
65
69
72 pointer operator->() { return m_ptr; }
73
76 {
77 m_ptr.pos++;
78 return *this;
79 }
80
82 const Iterator operator++(int) // NOLINT(readability-const-return-type)
83 {
84 Iterator tmp = *this;
85 ++(*this);
86 return tmp;
87 }
88
90 friend bool operator==(const Iterator& a, const Iterator& b) { return a.m_ptr.impl == b.m_ptr.impl && a.m_ptr.pos == b.m_ptr.pos; }
91
93 friend bool operator!=(const Iterator& a, const Iterator& b) { return a.m_ptr.impl != b.m_ptr.impl || a.m_ptr.pos != b.m_ptr.pos; }
94
95 private:
96 pointer m_ptr;
97 };
98
99 explicit PluginRegistry(const std::shared_ptr<nexuslua::agents>& agents);
101
102 PluginInstallResult Install(std::string name, std::string& strError);
103 std::string GetErrorMessage();
104 std::shared_ptr<Agent> Get(const std::string& agentName);
105 std::size_t Count() const;
107
110 };
111}
base class of the three types of agents
Definition agent.hpp:60
Iterator end()
required to iterator over plugins using a for loop
PluginRegistry(const std::shared_ptr< nexuslua::agents > &agents)
void RescanInstalled()
merge information about the installed plugins with the online plugins; this covers situations where a...
std::string GetErrorMessage()
return the last error message
std::shared_ptr< Agent > Get(const std::string &agentName)
return the nexuslua::Agent with the given name, provided it is installed as a plugin
PluginInstallResult Install(std::string name, std::string &strError)
install the given online plugin; store any errors in strError
std::size_t Count() const
return the current number of plugins; depending if RescanInstalled() has been called,...
Iterator begin()
required to iterator over plugins using a for loop
Functions related to agents or plugins, which are (un-)installable agents with meta data like a versi...
Definition agents.hpp:49
The nexuslua library is implemented inside this namespace.
PluginInstallResult
result values of agents::InstallPlugin
Definition plugin_install_result.hpp:34
enable iteration over plugins using an instance of PluginsOnline
Definition plugin_registry.hpp:50
pointer operator->()
arrow operator
Definition plugin_registry.hpp:72
struct { Impl * impl; std::size_t pos; } pointer
Type of the iterator's pointer-like object.
Definition plugin_registry.hpp:55
friend bool operator!=(const Iterator &a, const Iterator &b)
inequality comparison operator
Definition plugin_registry.hpp:93
std::shared_ptr< Agent > value_type
Definition plugin_registry.hpp:53
Iterator(pointer ptr)
Construct a new Iterator object.
Definition plugin_registry.hpp:63
std::ptrdiff_t difference_type
Definition plugin_registry.hpp:52
Iterator & operator++()
prefix increment
Definition plugin_registry.hpp:75
const Iterator operator++(int)
postfix increment
Definition plugin_registry.hpp:82
friend bool operator==(const Iterator &a, const Iterator &b)
equality comparison operator
Definition plugin_registry.hpp:90
value_type operator*() const
dereference operator
std::input_iterator_tag iterator_category
Definition plugin_registry.hpp:51