Environment.cpp
Go to the documentation of this file.
1 #include "Environment.hpp"
2 
3 #include <spdlog/details/os.h>
4 #include <spdlog/spdlog.h>
5 
6 #include <mutex>
7 #include <unordered_map>
8 
9 // project
10 #include <utility/Logging.hpp>
11 
12 namespace dai {
13 namespace utility {
14 
15 static std::mutex mtx;
16 static std::unordered_map<std::string, std::string> map;
17 
18 std::string getEnv(const std::string& var) {
19  return getEnv(var, Logging::getInstance().logger);
20 }
21 
22 std::string getEnv(const std::string& var, spdlog::logger& logger) {
23  std::unique_lock<std::mutex> lock(mtx);
24 
25  if(map.count(var) > 0) {
26  return map.at(var);
27  }
28  auto value = spdlog::details::os::getenv(var.c_str());
29  map[var] = value;
30 
31  // Log if env variable is set
32  if(!value.empty()) {
33  logger.debug("Environment '{}' set to '{}'", var, value);
34  }
35 
36  return value;
37 }
38 
39 } // namespace utility
40 } // namespace dai
dai::utility::map
static std::unordered_map< std::string, std::string > map
Definition: Environment.cpp:16
Environment.hpp
dai::utility::getEnv
std::string getEnv(const std::string &var)
Definition: Environment.cpp:18
dai::utility::mtx
static std::mutex mtx
Definition: Environment.cpp:15
dai::Logging::getInstance
static Logging & getInstance()
Definition: Logging.hpp:32
Logging.hpp
dai
Definition: CameraExposureOffset.hpp:6


depthai
Author(s): Martin Peterlin
autogenerated on Sat Mar 22 2025 02:58:19