VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
PublishedInterfaces.cpp
Go to the documentation of this file.
2
3#include <algorithm>
4#include <utility>
5
6namespace VoltMod
7{
8
9void 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
27void 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
38void* 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
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
void Publish(OwnerId owner, std::string_view name, void *implementation)
void * Find(std::string_view name) const
std::vector< std::string > RemoveAll(OwnerId owner)
void Unpublish(OwnerId owner, std::string_view name)
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56