env-var.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef AFUN_ENV_VAR_H
  2. #define AFUN_ENV_VAR_H
  3. #include <unordered_map>
  4. #include "aFuntool.h"
  5. #include "aFunCoreExport.h"
  6. #include "shared_mutex"
  7. namespace aFuncore {
  8. class AFUN_CORE_EXPORT EnvVarSpace { // 环境变量
  9. public:
  10. EnvVarSpace() = default;
  11. ~EnvVarSpace() = default;
  12. EnvVarSpace(const EnvVarSpace &)=delete;
  13. EnvVarSpace &operator=(const EnvVarSpace &)=delete;
  14. [[nodiscard]] inline size_t getCount() const;
  15. bool findString(const std::string &name, std::string &str) const;
  16. bool findNumber(const std::string &name, int32_t &num) const;
  17. void setString(const std::string &name, const std::string &str);
  18. void setNumber(const std::string &name, int32_t num);
  19. void addString(const std::string &name, const std::string &str);
  20. void addNumber(const std::string &name, int32_t num);
  21. private:
  22. static const size_t ENV_VAR_HASH_SIZE = 100; // 环境变量哈希表大小
  23. struct EnvVar { // 环境变量
  24. std::string str;
  25. int32_t num; // 可以同时记录字符串和数字
  26. };
  27. std::unordered_map<std::string, EnvVar> var;
  28. std::shared_mutex lock;
  29. };
  30. }
  31. #include "env-var.inline.h"
  32. #endif //AFUN_ENV_VAR_H