env.cpp 691 Bytes
Newer Older
Paul's avatar
Paul committed
1
2
3
4
5
#include <migraph/env.hpp>
#include <migraph/ranges.hpp>
#include <cstdlib>

namespace migraph {
6
namespace MIGRAPH_INLINE_NS {
Paul's avatar
Paul committed
7

Paul's avatar
Paul committed
8
bool enabled(const char* name)
Paul's avatar
Paul committed
9
10
11
12
13
14
15
{
    auto e = env(name);
    if(e.empty())
        return false;
    return contains({"1", "enable", "enabled", "yes", "true"}, e.front());
}

Paul's avatar
Paul committed
16
bool disabled(const char* name)
Paul's avatar
Paul committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{
    auto e = env(name);
    if(e.empty())
        return false;
    return contains({"0", "disable", "disabled", "no", "false"}, e.front());
}

std::vector<std::string> env(const char* name)
{
    auto p = std::getenv(name);
    if(p == nullptr)
        return {};
    else
        return {{p}};
}

33
} // namespace MIGRAPH_INLINE_N
Paul's avatar
Paul committed
34
} // namespace migraph