mirror of
https://github.com/NekoX-Dev/NekoX.git
synced 2024-12-14 16:59:43 +01:00
59 lines
1.3 KiB
C++
59 lines
1.3 KiB
C++
#include "Instance.h"
|
|
|
|
#include <algorithm>
|
|
#include <stdarg.h>
|
|
|
|
namespace tgcalls {
|
|
namespace {
|
|
|
|
std::function<void(std::string const &)> globalLoggingFunction;
|
|
|
|
std::map<std::string, std::shared_ptr<Meta>> &MetaMap() {
|
|
static auto result = std::map<std::string, std::shared_ptr<Meta>>();
|
|
return result;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
std::vector<std::string> Meta::Versions() {
|
|
auto &map = MetaMap();
|
|
auto result = std::vector<std::string>();
|
|
result.reserve(map.size());
|
|
for (const auto &entry : map) {
|
|
result.push_back(entry.first);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
int Meta::MaxLayer() {
|
|
auto result = 0;
|
|
for (const auto &entry : MetaMap()) {
|
|
result = std::max(result, entry.second->connectionMaxLayer());
|
|
}
|
|
return result;
|
|
}
|
|
|
|
std::unique_ptr<Instance> Meta::Create(
|
|
const std::string &version,
|
|
Descriptor &&descriptor) {
|
|
const auto i = MetaMap().find(version);
|
|
return (i != MetaMap().end())
|
|
? i->second->construct(std::move(descriptor))
|
|
: nullptr;
|
|
}
|
|
|
|
void Meta::RegisterOne(std::shared_ptr<Meta> meta) {
|
|
if (meta) {
|
|
const auto versions = meta->versions();
|
|
for (auto &it : versions) {
|
|
MetaMap().emplace(it, meta);
|
|
}
|
|
}
|
|
}
|
|
|
|
void SetLoggingFunction(std::function<void(std::string const &)> loggingFunction) {
|
|
globalLoggingFunction = loggingFunction;
|
|
}
|
|
|
|
} // namespace tgcalls
|