sophiar_obj.hpp 812 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifndef SOPHIAR2_SOPHIAR_OBJ_HPP
  2. #define SOPHIAR2_SOPHIAR_OBJ_HPP
  3. #include "core/sophiar_manager.h"
  4. #include <boost/asio/io_context.hpp>
  5. #include <nlohmann/json.hpp>
  6. namespace sophiar {
  7. extern boost::asio::io_context global_context;
  8. class sophiar_obj {
  9. public:
  10. virtual ~sophiar_obj() = default;
  11. // 加载初始化配置
  12. [[deprecated]] virtual void load_construct_config(const nlohmann::json &config) {};
  13. static constexpr auto &get_context() {
  14. return global_context;
  15. }
  16. static constexpr auto &get_manager() {
  17. return global_sophiar_manager;
  18. }
  19. };
  20. #define DEFAULT_NEW_INSTANCE(DerivedT) \
  21. static sophiar_obj *new_instance() { \
  22. return new DerivedT{}; \
  23. }
  24. }
  25. #endif //SOPHIAR2_SOPHIAR_OBJ_HPP