MCPcopy Create free account
hub / github.com/RoboMaster/RoboRTS / AlgorithmRegister

Class AlgorithmRegister

roborts_common/include/alg_factory/algorithm_factory.h:118–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116
117template<typename AlgorithmBase, typename Algorithm, typename... Args>
118class AlgorithmRegister{
119 public:
120 /**
121 * @brief Constructor function of AlgorithmRegister class.
122 * @param algorithm_name Algorithm name, which must be the same with the variable defined in ".prototxt" file.
123 */
124 explicit AlgorithmRegister(std::string algorithm_name) {
125 Register(algorithm_name, make_int_sequence<sizeof...(Args)>{});
126 }
127 /**
128 * @brief Create an unique_ptr pointer of Algorithm corresponding to the algorithm name.
129 * @param data Parameter pack
130 * @return The base class unique_ptr that point to Algorithm corresponding to the algorithm name.
131 */
132 static std::unique_ptr<Algorithm> create(Args&&... data)
133 {
134 return std::make_unique<Algorithm>(std::forward<Args>(data)...);
135 }
136
137 private:
138 /**
139 * @brief Using std::bind to create a std::function, than pass it to Register function befined in AlgorithmnFactory
140 * class
141 * @tparam Is Parameter pack
142 * @param algorithm_name Algorithm name, which must be the same with the variable defined in ".prototxt" file.
143 */
144 template <int... Is>
145 void Register(std::string algorithm_name, int_sequence<Is...>) {
146 auto function = std::bind(&AlgorithmRegister<AlgorithmBase, Algorithm, Args...>::create,
147 std::placeholder_template<Is>{}...);
148 AlgorithmFactory<AlgorithmBase, Args...>::Register(algorithm_name, function);
149 }
150};
151/**
152 * @brief It is convenient to register specific algorithm using this Macro.
153 * @example

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected