env-var.hpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  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. public:
  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. private:
  16. size_t count;
  17. EnvVar *var[ENV_VAR_HASH_SIZE] {};
  18. pthread_rwlock_t lock;
  19. public:
  20. AFUN_CORE_EXPORT EnvVarSpace();
  21. AFUN_CORE_EXPORT ~EnvVarSpace();
  22. [[nodiscard]] size_t getCount() const {return count;}
  23. [[nodiscard]] EnvVar *findVar(const std::string &name);
  24. AFUN_CORE_EXPORT bool findString(const std::string &name, std::string &str) const;
  25. AFUN_CORE_EXPORT bool findNumber(const std::string &name, int32_t &num) const;
  26. AFUN_CORE_EXPORT void setString(const std::string &name, const std::string &str);
  27. AFUN_CORE_EXPORT void setNumber(const std::string &name, int32_t num);
  28. };
  29. }
  30. #endif //AFUN_ENV_VAR_HPP