env-var.hpp 1.2 KB

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