core_env_var.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #ifndef AFUN_CORE_ENV_VAR_H
  2. #define AFUN_CORE_ENV_VAR_H
  3. #include <unordered_map>
  4. #include <thread>
  5. #include <mutex>
  6. #include "aFuntool.h"
  7. #include "aFunCoreExport.h"
  8. namespace aFuncore {
  9. class Object;
  10. class AFUN_CORE_EXPORT EnvVarSpace { // 环境变量
  11. public:
  12. EnvVarSpace() = default;
  13. ~EnvVarSpace();
  14. EnvVarSpace(const EnvVarSpace &)=delete;
  15. EnvVarSpace &operator=(const EnvVarSpace &)=delete;
  16. [[nodiscard]] AFUN_INLINE size_t getCount();
  17. bool findString(const std::string &name, std::string &str);
  18. bool findNumber(const std::string &name, int32_t &num);
  19. bool findObject(const std::string &name, Object *&obj);
  20. void setString(const std::string &name, const std::string &str);
  21. void setNumber(const std::string &name, int32_t num);
  22. void setObject(const std::string &name, Object *obj);
  23. void addString(const std::string &name, const std::string &str);
  24. void addNumber(const std::string &name, int32_t num);
  25. private:
  26. AFUN_STATIC const size_t ENV_VAR_HASH_SIZE = 100; // 环境变量哈希表大小
  27. struct EnvVar { // 环境变量
  28. std::string str;
  29. int32_t num;
  30. Object *object;
  31. };
  32. std::unordered_map<std::string, EnvVar> var;
  33. std::mutex lock;
  34. };
  35. }
  36. #include "core_env_var.inline.h"
  37. #endif //AFUN_CORE_ENV_VAR_H