env-var.hpp 1009 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #ifndef AFUN_ENV_VAR_HPP
  2. #define AFUN_ENV_VAR_HPP
  3. #include "tool.hpp"
  4. #include "aFunCoreExport.h"
  5. namespace aFuncore {
  6. static const size_t ENV_VAR_HASH_SIZE = 100; // 环境变量哈希表大小
  7. class EnvVarSpace { // 环境变量
  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. EnvVarSpace();
  19. ~EnvVarSpace();
  20. [[nodiscard]] size_t getCount() const {return count;}
  21. bool findString(const std::string &name, std::string &str) const;
  22. bool findNumber(const std::string &name, int32_t &num) const;
  23. void setString(const std::string &name, const std::string &str);
  24. void setNumber(const std::string &name, int32_t num);
  25. };
  26. }
  27. #endif //AFUN_ENV_VAR_HPP