env.h 894 B

12345678910111213141516171819202122232425262728293031
  1. #pragma once
  2. #include <c10/macros/Export.h>
  3. #include <optional>
  4. #include <string>
  5. namespace c10::utils {
  6. // Set an environment variable.
  7. C10_API void set_env(
  8. const char* name,
  9. const char* value,
  10. bool overwrite = true);
  11. // Checks an environment variable is set.
  12. C10_API bool has_env(const char* name) noexcept;
  13. // Reads an environment variable and returns
  14. // - std::optional<true>, if set equal to "1"
  15. // - std::optional<false>, if set equal to "0"
  16. // - nullopt, otherwise
  17. //
  18. // NB:
  19. // Issues a warning if the value of the environment variable is not 0 or 1.
  20. C10_API std::optional<bool> check_env(const char* name);
  21. // Reads the value of an environment variable if it is set.
  22. // However, check_env should be used if the value is assumed to be a flag.
  23. C10_API std::optional<std::string> get_env(const char* name) noexcept;
  24. } // namespace c10::utils