VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
PublishedInterfaces.cpp
Go to the documentation of this file.
1
#include "
Host/Plugins/PublishedInterfaces.hpp
"
2
3
#include <algorithm>
4
#include <utility>
5
6
namespace
VoltMod
7
{
8
9
void
PublishedInterfaces::Publish
(
OwnerId
owner
, std::string_view name,
void
*
implementation
)
10
{
11
if
(name.empty() ||
implementation
==
nullptr
)
12
{
13
return
;
14
}
15
16
const
auto
held
= std::ranges::find(_services, name, &Service::Name);
17
if
(
held
== _services.end())
18
{
19
_services.push_back({.Name = std::string(name), .Implementation =
implementation
, .Owner =
owner
});
20
}
21
else
if
(
held
->Owner ==
owner
)
22
{
23
held
->Implementation =
implementation
;
24
}
25
}
26
27
void
PublishedInterfaces::Unpublish
(
OwnerId
owner
, std::string_view name)
28
{
29
const
auto
held
= std::ranges::find(_services, name, &Service::Name);
30
if
(
held
== _services.end() ||
held
->Owner !=
owner
)
31
{
32
return
;
33
}
34
35
_services.erase(
held
);
36
}
37
38
void
*
PublishedInterfaces::Find
(std::string_view name)
const
39
{
40
const
auto
held
= std::ranges::find(_services, name, &Service::Name);
41
return
held
!= _services.end() ?
held
->Implementation :
nullptr
;
42
}
43
44
std::vector<std::string>
PublishedInterfaces::RemoveAll
(
OwnerId
owner
)
45
{
46
std::vector<std::string>
withdrawn
;
47
for
(
const
Service&
service
: _services)
48
{
49
if
(
service
.Owner ==
owner
)
50
{
51
withdrawn
.push_back(
service
.Name);
52
}
53
}
54
55
std::erase_if(_services, [
owner
](
const
Service&
service
) {
return
service
.Owner ==
owner
; });
56
57
return
withdrawn
;
58
}
59
60
}
// namespace VoltMod
PublishedInterfaces.hpp
VoltMod::PublishedInterfaces::Publish
void Publish(OwnerId owner, std::string_view name, void *implementation)
Definition
PublishedInterfaces.cpp:9
VoltMod::PublishedInterfaces::Find
void * Find(std::string_view name) const
Definition
PublishedInterfaces.cpp:38
VoltMod::PublishedInterfaces::OwnerId
const void * OwnerId
Definition
PublishedInterfaces.hpp:15
VoltMod::PublishedInterfaces::RemoveAll
std::vector< std::string > RemoveAll(OwnerId owner)
Definition
PublishedInterfaces.cpp:44
VoltMod::PublishedInterfaces::Unpublish
void Unpublish(OwnerId owner, std::string_view name)
Definition
PublishedInterfaces.cpp:27
VoltMod
Definition
Options.hpp:13
VoltMod::ReadFile
static std::string ReadFile(const std::filesystem::path &path)
Definition
Loader.cpp:56
src
Host
Plugins
PublishedInterfaces.cpp
Generated by
1.9.8