1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include "utils/auto_device_class.h"
std::vector<TangoTest::detail::ClassRegistrarBase *> *TangoTest::detail::ClassRegistrarBase::registrars = nullptr;
namespace
{
std::vector<std::string> get_enabled_classes()
{
std::vector<std::string> result;
const char *maybe_env = std::getenv(TangoTest::detail::k_enabled_classes_env_var);
if(maybe_env == nullptr)
{
return result;
}
std::string env{maybe_env};
size_t pos = 0;
while(true)
{
size_t next = env.find(';', pos);
if(next == std::string::npos)
{
result.push_back(env.substr(pos));
break;
}
result.push_back(env.substr(pos, next - 1));
pos = next + 1;
}
return result;
}
bool contains(const std::vector<std::string> &haystack, const std::string &needle)
{
return std::find(haystack.begin(), haystack.end(), needle) != haystack.end();
}
} // namespace
namespace Tango
{
void DServer::class_factory()
{
std::vector<std::string> enabled = get_enabled_classes();
for(auto *registrar : *TangoTest::detail::ClassRegistrarBase::registrars)
{
if(!enabled.empty() && !contains(enabled, registrar->name))
{
continue;
}
add_class(registrar->init_class());
}
}
} // namespace Tango
|