VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
CommandNames.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <string_view>
5#include <vector>
6
7namespace VoltMod
8{
9
10/** Which plugin owns each console command name, so two plugins cannot register the same one. */
12{
13public:
14 /** The opaque pointer the host identifies a plugin by. */
15 using OwnerId = const void*;
16
17 /** False when another owner already has @p name. @p ownerName is what OwnerOf answers with. */
18 bool Register(OwnerId owner, std::string_view ownerName, std::string_view name);
19
20 /** Keep @p name for the host's own console commands. */
21 void Reserve(std::string_view name);
22
23 /** The owner's name, "the host" for the host's own, empty while @p name is free. */
24 std::string_view OwnerOf(std::string_view name) const;
25
26 /** Remove every name @p owner registered. A plugin has no other way to give one back. */
28
29private:
30 struct Entry
31 {
32 std::string Name;
33 OwnerId Owner = nullptr; ///< nullptr is the host
34 std::string OwnerName;
35 };
36
37 std::vector<Entry> _entries;
38};
39
40} // namespace VoltMod
void RemoveAll(OwnerId owner)
bool Register(OwnerId owner, std::string_view ownerName, std::string_view name)
void Reserve(std::string_view name)
std::string_view OwnerOf(std::string_view name) const
constexpr std::string_view Name(E value) noexcept
Definition EnumNames.hpp:33
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56