env-var.h 1.2 KB

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