#ifndef BAIDU_PADDLE_SERVING_PREDICTOR_OP_REPOSITORY_H #define BAIDU_PADDLE_SERVING_PREDICTOR_OP_REPOSITORY_H #include "common/inner_common.h" namespace baidu { namespace paddle_serving { namespace predictor { #define REGISTER_OP(op) \ ::baidu::paddle_serving::predictor::OpRepository::instance().regist_op(#op) class Op; class Factory { public: virtual Op* get_op() = 0; virtual void return_op(Op* op) = 0; }; template class OpFactory : public Factory { public: Op* get_op() { return base::get_object(); } void return_op(Op* op) { base::return_object(dynamic_cast(op)); } static OpFactory& instance() { static OpFactory ins; return ins; } }; class OpRepository { public: typedef boost::unordered_map ManagerMap; OpRepository() {} ~OpRepository() {} static OpRepository& instance() { static OpRepository repo; return repo; } template void regist_op(std::string op_type) { _repository[op_type] = &OpFactory::instance(); LOG(TRACE) << "Succ regist op: " << op_type << "!"; } Op* get_op(std::string op_type); void return_op(Op* op); void return_op(const std::string& op_type, Op* op); private: ManagerMap _repository; }; } // predictor } // paddle_serving } // baidu #endif