env-var.hpp 982 B

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