env-var.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #ifndef AFUN_ENV_VAR_H
  2. #define AFUN_ENV_VAR_H
  3. #include "aFuntool.h"
  4. #include "aFunCoreExport.h"
  5. namespace aFuncore {
  6. AFUN_CORE_EXPORT 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. EnvVarSpace();
  19. ~EnvVarSpace();
  20. EnvVarSpace(const EnvVarSpace &)=delete;
  21. EnvVarSpace &operator=(const EnvVarSpace &)=delete;
  22. [[nodiscard]] size_t getCount() const {return count;}
  23. bool findString(const std::string &name, std::string &str) const;
  24. bool findNumber(const std::string &name, int32_t &num) const;
  25. void setString(const std::string &name, const std::string &str);
  26. void setNumber(const std::string &name, int32_t num);
  27. };
  28. }
  29. #endif //AFUN_ENV_VAR_H