env-var.h 1.3 KB

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