IgANet
IgANets - Isogeometric Analysis Networks
Loading...
Searching...
No Matches
getenv.hpp
Go to the documentation of this file.
1
15#pragma once
16
17#include <sstream>
18#include <stdlib.h>
19
20namespace iganet {
21namespace utils {
22
24template <typename T> T getenv(std::string variable, const T &default_value) {
25
26 char *env_value = std::getenv(variable.c_str());
27 if (env_value != NULL)
28 if constexpr (std::is_integral_v<T>)
29 return static_cast<T>(std::atoll(env_value));
30 else if constexpr (std::is_floating_point_v<T>)
31 return static_cast<T>(std::atof(env_value));
32 else
33 return static_cast<T>(env_value);
34 else
35 return default_value;
36}
37
39template <typename T>
40std::vector<T> getenv(std::string variable,
41 std::initializer_list<T> default_value) {
42
43 char *env_value = std::getenv(variable.c_str());
44 if (env_value != NULL) {
45 std::stringstream ss(env_value);
46 std::vector<T> result;
47 std::string item;
48
49 if constexpr (std::is_integral_v<T>)
50 while (std::getline(ss, item, ','))
51 result.emplace_back(static_cast<T>(std::atoll(item.c_str())));
52 else if constexpr (std::is_floating_point_v<T>)
53 while (std::getline(ss, item, ','))
54 result.emplace_back(static_cast<T>(std::atof(item.c_str())));
55 else
56 while (std::getline(ss, item, ','))
57 result.emplace_back(static_cast<T>(item));
58 return result;
59 } else
60 return std::vector<T>{default_value};
61}
62
63} // namespace utils
64} // namespace iganet
T getenv(std::string variable, const T &default_value)
Returns the value from an environment variable.
Definition getenv.hpp:24
Definition boundary.hpp:22
constexpr bool is_SplineType_v
Alias to the value of is_SplineType.
Definition bspline.hpp:3243