env-var.hpp 1.1 KB

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