registration.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  1. /************************************************************************************
  2. * *
  3. * Copyright (c) 2014 - 2018 Axel Menzel <info@rttr.org> *
  4. * *
  5. * This file is part of RTTR (Run Time Type Reflection) *
  6. * License: MIT License *
  7. * *
  8. * Permission is hereby granted, free of charge, to any person obtaining *
  9. * a copy of this software and associated documentation files (the "Software"), *
  10. * to deal in the Software without restriction, including without limitation *
  11. * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
  12. * and/or sell copies of the Software, and to permit persons to whom the *
  13. * Software is furnished to do so, subject to the following conditions: *
  14. * *
  15. * The above copyright notice and this permission notice shall be included in *
  16. * all copies or substantial portions of the Software. *
  17. * *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
  24. * SOFTWARE. *
  25. * *
  26. *************************************************************************************/
  27. #ifndef RTTR_REGISTRATION_H_
  28. #define RTTR_REGISTRATION_H_
  29. #include "rttr/detail/base/core_prerequisites.h"
  30. #include "rttr/policy.h"
  31. #include "rttr/access_levels.h"
  32. #include "rttr/detail/registration/bind_types.h"
  33. #include "rttr/detail/registration/registration_executer.h"
  34. #include "rttr/detail/default_arguments/default_arguments.h"
  35. #include "rttr/detail/parameter_info/parameter_names.h"
  36. #include "rttr/variant.h"
  37. #include "rttr/detail/visitor/visitor_registration.h"
  38. namespace rttr
  39. {
  40. namespace detail
  41. {
  42. class metadata;
  43. template<typename Enum_Type>
  44. class enum_data;
  45. struct public_access {};
  46. struct protected_access {};
  47. struct private_access {};
  48. using access_levels_list = type_list<public_access, protected_access, private_access>;
  49. }
  50. /*!
  51. * The \ref registration class is the entry point for the manual registration of reflection information
  52. * to the type system. It is possible to register *constructors*, *properties*, *methods* and *enumerations*.
  53. *
  54. * See following example for a typical usage:
  55. *
  56. * Put the \ref RTTR_ENABLE() macro inside the class declaration, when you will inherit from this class,
  57. * otherwise you can omit the macro.
  58. * \code{.cpp}
  59. * #include <rttr/type>
  60. * struct Mesh
  61. * {
  62. * Mesh();
  63. * Mesh(const std::string& name)
  64. * Vector3d getPosition() const;
  65. * void setPosition(const Vector3d& pos);
  66. * enum E_TransformSpace
  67. * {
  68. * TS_LOCAL,
  69. * TS_PARENT,
  70. * TS_WORLD
  71. * };
  72. *
  73. * void setDirection(const Vector3 &vec, E_TransformSpace ts = TS_LOCAL);
  74. * RTTR_ENABLE()
  75. * private:
  76. * Vector3d _pos;
  77. * };
  78. * \endcode
  79. *
  80. * Then in a cpp file, register the constructors, properties and methods of the class \p Mesh.
  81. *
  82. * \code{.cpp}
  83. * #include "Mesh.cpp"
  84. * #include <rttr/registration>
  85. * using namespace rttr;
  86. *
  87. * // register the class Mesh before main is called
  88. * RTTR_REGISTRATION
  89. * {
  90. * using namespace rttr;
  91. * registration::class_<Mesh>("Mesh")
  92. * .constructor<>()
  93. * .constructor<const string&>()
  94. * .enumeration<E_TransformSpace>("E_TransformSpace")
  95. * (
  96. * value("TS_LOCAL", TS_LOCAL),
  97. * value("TS_PARENT", TS_PARENT),
  98. * value("TS_WORLD", TS_WORLD),
  99. *
  100. * metadata("GUI_DESCR", "This enum describes the transformation.")
  101. * )
  102. * .property("pos", &Mesh::getPosition, &Mesh::setPosition)
  103. * (
  104. * metadata("GUI_LABEL", "Position."),
  105. * metadata("GUI_DESCR", "The position of the mesh."),
  106. * )
  107. * .method("setDirection", &Mesh::setDirection);
  108. * }
  109. * \endcode
  110. *
  111. * \remark See the usage of `()` operator to add additional \ref rttr::metadata(variant, variant) "meta data", \ref policy "policies" or
  112. * \ref rttr::value "enum values".
  113. *
  114. */
  115. class RTTR_API registration
  116. {
  117. public:
  118. template<typename...T>
  119. class bind;
  120. /*!
  121. * The \ref class_ is used to register classes to RTTR.
  122. */
  123. template<typename Class_Type, typename Visitor_List = READ_TL(rttr_visitor_list)>
  124. class class_
  125. {
  126. public:
  127. /*!
  128. * \brief Construct a class_ object with the given name \p name.
  129. *
  130. * \param name The name of the class as string literal. Can be retrieved later via type::get_name().
  131. *
  132. */
  133. class_(string_view name);
  134. ~class_();
  135. /*!
  136. * \brief The bracket operator can be used to add additional meta data to the class type.
  137. *
  138. */
  139. template<typename...Args>
  140. class_<Class_Type, Visitor_List>& operator()(Args&&...args);
  141. /*!
  142. * \brief Register a constructor for this class type with or without arguments.
  143. *
  144. * \param level The access level of the constructor; default is: registration::public_access.<br>
  145. * (can be also: registration::protected_access or registration::private_access)
  146. *
  147. * \remark The default constructor create policy is: \ref policy::ctor::as_std_shared_ptr.
  148. *
  149. * \see constructor, type::get_constructor(), type::create()
  150. *
  151. * \return A \ref bind object, in order to chain more calls.
  152. */
  153. template<typename... Args, typename acc_level = detail::public_access, typename Tp = typename std::enable_if<detail::contains<acc_level, detail::access_levels_list>::value>::type>
  154. bind<detail::ctor, Class_Type, acc_level, Visitor_List, Args...> constructor(acc_level level = acc_level());
  155. /*!
  156. * \brief Register a constructor for this class type which uses a function \p F.
  157. *
  158. * \param func A function which creates an instance of \p Class_Type;
  159. * This can be a pointer to a function or a std::function.
  160. * \param level The access level of the constructor; default is: registration::public_access.<br>
  161. * (can be also: registration::protected_access or registration::private_access)
  162. *
  163. * \see constructor, type::get_constructor(), type::create()
  164. *
  165. * \return A \ref bind object, in order to chain more calls.
  166. */
  167. template<typename F, typename acc_level = detail::public_access, typename Tp = typename std::enable_if<!detail::contains<F, detail::access_levels_list>::value>::type>
  168. bind<detail::ctor_func, Class_Type, F, acc_level, Visitor_List> constructor(F func, acc_level level = acc_level());
  169. /*!
  170. * \brief Register a property to this class.
  171. *
  172. * \param name The name of the property.
  173. * \param acc The accessor to the property; this can be a pointer to a member or a pointer to a variable.
  174. * \param level The access level of the property; default is: registration::public_access.<br>
  175. * (can be also: registration::protected_access or registration::private_access)
  176. *
  177. * \remark The name of the property has to be unique for this class, otherwise it will not be registered.
  178. *
  179. * \see property, type::get_property(), type::get_property_value(), type::set_property_value()
  180. *
  181. * \return A \ref bind object, in order to chain more calls.
  182. */
  183. template<typename A, typename acc_level = detail::public_access, typename Tp = typename std::enable_if<detail::contains<acc_level, detail::access_levels_list>::value>::type>
  184. bind<detail::prop, Class_Type, A, acc_level, Visitor_List> property(string_view name, A acc, acc_level level = acc_level());
  185. /*!
  186. * \brief Register a read only property to this class.
  187. *
  188. * \param name The name of the property.
  189. * \param acc The accessor to the property; this can be a pointer to a member, a pointer to a variable,
  190. * a pointer to a member function, a pointer to a function or a std::function.
  191. * \param level The access level of the read only property; default is: registration::public_access.<br>
  192. * (can be: registration::protected_access or registration::private_access)
  193. *
  194. * \remark The name of the property has to be unique for this class, otherwise it will not be registered.
  195. *
  196. * \see property, type::get_property(), type::get_property_value(), type::set_property_value()
  197. *
  198. * \return A \ref bind object, in order to chain more calls.
  199. */
  200. template<typename A, typename acc_level = detail::public_access, typename Tp = typename std::enable_if<detail::contains<acc_level, detail::access_levels_list>::value>::type>
  201. bind<detail::prop_readonly, Class_Type, A, acc_level, Visitor_List> property_readonly(string_view name, A acc, acc_level level = acc_level());
  202. /*!
  203. * \brief Register a property to this class.
  204. *
  205. * \param name The name of the property.
  206. * \param getter The getter accessor to the property; this can be a pointer to a member function,
  207. * a pointer to a function or a std::function.
  208. * \param setter The setter accessor to the property; this can be a pointer to a member function,
  209. * a pointer to a function or a std::function.
  210. * \param level The access level of the property; default is: registration::public_access.<br>
  211. * (can be also: registration::protected_access or registration::private_access)
  212. *
  213. * \remark The name of the property has to be unique for this class, otherwise it will not be registered.
  214. *
  215. * \see property, type::get_property(), type::get_property_value(), type::set_property_value()
  216. *
  217. * \return A \ref bind object, in order to chain more calls.
  218. */
  219. template<typename A1, typename A2, typename acc_level = detail::public_access, typename Tp = typename std::enable_if<!detail::contains<A2, detail::access_levels_list>::value>::type>
  220. bind<detail::prop, Class_Type, A1, A2, acc_level, Visitor_List> property(string_view name, A1 getter, A2 setter, acc_level level = acc_level());
  221. /*!
  222. * \brief Register a method to this class.
  223. *
  224. * \param name The name of the method.
  225. * \param function The function accessor to this method; this can be a member function, a function or an std::function.
  226. * \param level The access level of the method; default is: registration::public_access.<br>
  227. * (can be also: registration::protected_access or registration::private_access)
  228. *
  229. * \remark The method name does not have to be unique for this class.
  230. *
  231. * \see method, type::get_method(), type::invoke()
  232. *
  233. * \return A \ref bind object, in order to chain more calls.
  234. */
  235. template<typename F, typename acc_level = detail::public_access>
  236. bind<detail::meth, Class_Type, F, acc_level, Visitor_List> method(string_view name, F f, acc_level level = acc_level());
  237. /*!
  238. * \brief Register a nested enumeration of type \p Enum_Type
  239. *
  240. * \param name The name of the enumeration.
  241. *
  242. * \see enumeration, type::get_enumeration()
  243. *
  244. * \return A \ref bind object, in order to chain more calls.
  245. */
  246. template<typename Enum_Type>
  247. bind<detail::enum_, Class_Type, Enum_Type> enumeration(string_view name);
  248. private:
  249. class_(const std::shared_ptr<detail::registration_executer>& reg_exec);
  250. class_(const class_& other);
  251. class_& operator=(const class_& other);
  252. private:
  253. std::shared_ptr<detail::registration_executer> m_reg_exec;
  254. template<typename...T>
  255. friend class bind;
  256. };
  257. /*!
  258. * \brief Register a global property with read write access.
  259. *
  260. * \param name The name of the property.
  261. * \param acc The accessor to the property; a pointer to a variable.
  262. *
  263. * \remark The name of the property has to be unique, otherwise it will not be registered.
  264. *
  265. * \see property, type::get_global_property(),
  266. * \ref type::get_property_value(string_view) "type::get_property_value()",
  267. * \ref type::set_property_value(string_view, argument) "type::set_property_value"
  268. *
  269. * \return A \ref bind object, in order to chain more calls.
  270. */
  271. template<typename A, typename Visitor_List = READ_TL(rttr_visitor_list)>
  272. static bind<detail::prop, detail::invalid_type, A, detail::public_access, Visitor_List> property(string_view name, A acc);
  273. /*!
  274. * \brief Register a global read only property.
  275. *
  276. * \param name The name of the property.
  277. * \param acc The accessor to the property; this can be a pointer to a variable,
  278. * a pointer to a function or a std::function.
  279. *
  280. * \remark The name of the property has to be unique, otherwise it will not be registered.
  281. *
  282. * \see property, type::get_global_property(),
  283. * \ref type::get_property_value(string_view) "type::get_property_value()",
  284. * \ref type::set_property_value(string_view, argument) "type::set_property_value"
  285. *
  286. * \return A \ref bind object, in order to chain more calls.
  287. */
  288. template<typename A, typename Visitor_List = READ_TL(rttr_visitor_list)>
  289. static bind<detail::prop_readonly, detail::invalid_type, A, detail::public_access, Visitor_List> property_readonly(string_view name, A acc);
  290. /*!
  291. * \brief Register a property to this class.
  292. *
  293. * \param name The name of the property.
  294. * \param getter The getter accessor to the property; this can be a pointer to a function or a std::function.
  295. * \param setter The setter accessor to the property; this can be a pointer to a function or a std::function.
  296. *
  297. * \remark The name of the property has to be unique, otherwise it will not be registered.
  298. *
  299. * \see property, type::get_global_property(),
  300. * \ref type::get_property_value(string_view) "type::get_property_value()",
  301. * \ref type::set_property_value(string_view, argument) "type::set_property_value"
  302. *
  303. * \return A \ref bind object, in order to chain more calls.
  304. */
  305. template<typename A1, typename A2, typename Visitor_List = READ_TL(rttr_visitor_list)>
  306. static bind<detail::prop, detail::invalid_type, A1, A2, detail::public_access, Visitor_List> property(string_view name, A1 getter, A2 setter);
  307. /*!
  308. * \brief Register a method to this class.
  309. *
  310. * \param name The name of the method.
  311. * \param function The function accessor to this method; this can be a member function, a function or a std::function.
  312. *
  313. * \remark The method name does *not* have to be unique.
  314. *
  315. * \see method, type::get_global_method(),
  316. * \ref type::invoke(string_view, std::vector<argument>) "type::invoke()"
  317. *
  318. * \return A \ref bind object, in order to chain more calls.
  319. */
  320. template<typename F, typename Visitor_List = READ_TL(rttr_visitor_list)>
  321. static bind<detail::meth, detail::invalid_type, F, detail::public_access, Visitor_List> method(string_view name, F f);
  322. /*!
  323. * \brief Register a global enumeration of type \p Enum_Type
  324. *
  325. * \param name The name of the enumeration.
  326. *
  327. * \remark The name of the enumeration has to be unique, otherwise it will not be registered.
  328. *
  329. * \see enumeration, type::get_enumeration()
  330. *
  331. * \return A \ref bind object, in order to chain more calls.
  332. */
  333. template<typename Enum_Type>
  334. static bind<detail::enum_, detail::invalid_type, Enum_Type> enumeration(string_view name);
  335. /////////////////////////////////////////////////////////////////////////////////////
  336. /*!
  337. * This variable can be used to specify during registration of a class member
  338. * the access level: `public`.
  339. *
  340. * See following example code:
  341. * \code{.cpp}
  342. * using namespace rttr;
  343. * struct Foo
  344. * {
  345. * void func() {}
  346. * };
  347. *
  348. * RTTR_REGISTRATION
  349. * {
  350. * registration::class_<Foo>("Foo")
  351. * .method("func", &Foo::func, registration::public_access);
  352. * }
  353. * \endcode
  354. *
  355. * \see access_levels
  356. */
  357. static const detail::public_access public_access;
  358. /*!
  359. * This variable can be used to specify during registration of a class member
  360. * the access level: `protected`.
  361. *
  362. * See following example code:
  363. * \code{.cpp}
  364. * using namespace rttr;
  365. * struct Foo
  366. * {
  367. * protected:
  368. * void func() {}
  369. *
  370. * RTTR_REGISTRATION_FRIEND
  371. * };
  372. *
  373. * RTTR_REGISTRATION
  374. * {
  375. * registration::class_<Foo>("Foo")
  376. * .method("func", &Foo::func, registration::protected_access);
  377. * }
  378. * \endcode
  379. *
  380. * \see access_levels
  381. */
  382. static const detail::protected_access protected_access;
  383. /*!
  384. * This variable can be used to specify during registration of a class member
  385. * the access level: `private`.
  386. *
  387. * See following example code:
  388. * \code{.cpp}
  389. * using namespace rttr;
  390. * struct Foo
  391. * {
  392. * private:
  393. * void func() {}
  394. *
  395. * RTTR_REGISTRATION_FRIEND
  396. * };
  397. *
  398. * RTTR_REGISTRATION
  399. * {
  400. * registration::class_<Foo>("Foo")
  401. * .method("func", &Foo::func, registration::private_access);
  402. * }
  403. * \endcode
  404. *
  405. * \see access_levels
  406. */
  407. static const detail::private_access private_access;
  408. private:
  409. registration() {}
  410. registration(const std::shared_ptr<detail::registration_executer>& reg_exec) : m_reg_exec(reg_exec) { }
  411. registration(const registration& other);
  412. registration& operator=(const registration& other);
  413. private:
  414. std::shared_ptr<detail::registration_executer> m_reg_exec;
  415. template<typename...T>
  416. friend class bind;
  417. };
  418. /////////////////////////////////////////////////////////////////////////////////////////
  419. /////////////////////////////////////////////////////////////////////////////////////////
  420. /////////////////////////////////////////////////////////////////////////////////////////
  421. /*!
  422. * \brief This is a helper function to register overloaded functions.
  423. *
  424. * Use it like following:
  425. * \code{.cpp}
  426. *
  427. * #include <rttr/registration>
  428. * #include <cmath>
  429. * using namespace rttr;
  430. *
  431. * RTTR_REGISTRATION
  432. * {
  433. * registration::method("pow", select_overload<float(float, float)>(&pow));
  434. * }
  435. * \endcode
  436. *
  437. * \remark The method **cannot** be used with *MSVC x86* compiler, because of the different calling convention for global- and member-functions.
  438. * As workaround you have to explicitly cast to the function pointer:
  439. *
  440. * \code{.cpp}
  441. *
  442. * RTTR_REGISTRATION
  443. * {
  444. * registration::method("pow", static_cast<float(*)(float, float)>(&pow));
  445. * }
  446. * \endcode
  447. *
  448. */
  449. template<typename Signature>
  450. Signature* select_overload(Signature* func)
  451. {
  452. return func;
  453. }
  454. /*!
  455. * \brief This is a helper function to register overloaded member functions.
  456. *
  457. * Use it like following:
  458. * \code{.cpp}
  459. *
  460. * #include <rttr/registration>
  461. * #include <cmath>
  462. * using namespace rttr;
  463. *
  464. * struct Foo
  465. * {
  466. * void func(int) {}
  467. * void func(int, int) {}
  468. * };
  469. *
  470. * RTTR_REGISTRATION
  471. * {
  472. * registration::class_<Foo>("Foo")
  473. * .method("func", select_overload<void(int)>(&Foo::func))
  474. * .method("func", select_overload<void(int, int)>(&Foo::func));
  475. * }
  476. * \endcode
  477. *
  478. * \remark The method **cannot** be used with *MSVC x86* compiler, because of the different calling convention for global- and member-functions.
  479. * As workaround you have to explicitly cast to the member function pointer:
  480. *
  481. * \code{.cpp}
  482. *
  483. * RTTR_REGISTRATION
  484. * {
  485. * registration::class_<Foo>("Foo")
  486. * .method("func", static_cast<void(Foo::*)(int)>(&Foo::func))
  487. * .method("func", static_cast<void(Foo::*)(int, int)>(&Foo::func));
  488. * }
  489. * \endcode
  490. */
  491. template<typename Signature, typename ClassType>
  492. auto select_overload(Signature (ClassType::*func)) -> decltype(func)
  493. {
  494. return func;
  495. }
  496. /*!
  497. * \brief This is a helper function to register overloaded const member functions.
  498. *
  499. * Use it like following:
  500. * \code{.cpp}
  501. *
  502. * #include <rttr/registration>
  503. * using namespace rttr;
  504. * struct Foo
  505. * {
  506. * void func() {}
  507. * void func() const {}
  508. * };
  509. *
  510. * RTTR_REGISTRATION
  511. * {
  512. * registration::class_<Foo>("Foo")
  513. * .method("func", select_non_const(&Foo::func))
  514. * .method("func", select_const(&Foo::func));
  515. * }
  516. * \endcode
  517. *
  518. * \remark The method **cannot** be used with *MSVC x86* compiler, because of the different calling convention for global- and member-functions.
  519. * As workaround you have to explicitly cast to the member function pointer:
  520. *
  521. * \code{.cpp}
  522. *
  523. * RTTR_REGISTRATION
  524. * {
  525. * registration::class_<Foo>("Foo")
  526. * .method("func", static_cast<void(Foo::*)()>(&Foo::func))
  527. * .method("func", static_cast<void(Foo::*)()const>(&Foo::func));
  528. * }
  529. * \endcode
  530. */
  531. template<typename ClassType, typename ReturnType, typename... Args>
  532. auto select_const(ReturnType (ClassType::*func)(Args...) const) -> decltype(func)
  533. {
  534. return func;
  535. }
  536. #ifndef RTTR_NO_CXX17_NOEXCEPT_FUNC_TYPE
  537. /*!
  538. * \brief Overload with `noexcept` function type.
  539. *
  540. * \see select_const
  541. */
  542. template<typename ClassType, typename ReturnType, typename... Args>
  543. auto select_const(ReturnType (ClassType::*func)(Args...) const noexcept) -> decltype(func)
  544. {
  545. return func;
  546. }
  547. #endif
  548. /*!
  549. * \brief This is a helper function to register overloaded const member functions.
  550. *
  551. * Use it like following:
  552. * \code{.cpp}
  553. *
  554. * #include <rttr/registration>
  555. * using namespace rttr;
  556. * struct Foo
  557. * {
  558. * void func() {}
  559. * void func() const {}
  560. * };
  561. *
  562. * RTTR_REGISTRATION
  563. * {
  564. * registration::class<Foo>("Foo")
  565. * .method("func", select_non_const(&Foo::func))
  566. * .method("func", select_const(&Foo::func));
  567. * }
  568. * \endcode
  569. *
  570. * \remark The method **cannot** be used with *MSVC x86* compiler, because of the different calling convention for global- and member-functions.
  571. * As workaround you have to explicitly cast to the member function pointer:
  572. *
  573. * \code{.cpp}
  574. *
  575. * RTTR_REGISTRATION
  576. * {
  577. * registration::class_<Foo>("Foo")
  578. * .method("func", static_cast<void(Foo::*)()>(&Foo::func))
  579. * .method("func", static_cast<void(Foo::*)()const>(&Foo::func));
  580. * }
  581. * \endcode
  582. *
  583. */
  584. template<typename ClassType, typename ReturnType, typename... Args>
  585. auto select_non_const(ReturnType(ClassType::*func)(Args...)) -> decltype(func)
  586. {
  587. return func;
  588. }
  589. #ifndef RTTR_NO_CXX17_NOEXCEPT_FUNC_TYPE
  590. /*!
  591. * \brief Overload with `noexcept` function type.
  592. *
  593. * \see select_const
  594. */
  595. template<typename ClassType, typename ReturnType, typename... Args>
  596. auto select_non_const(ReturnType(ClassType::*func)(Args...) noexcept) -> decltype(func)
  597. {
  598. return func;
  599. }
  600. #endif
  601. /*!
  602. * The \ref metadata function can be used to add additional meta data information during the
  603. * registration process of reflection information. Use it in the `()` operator of the returned
  604. * \ref bind object.
  605. */
  606. RTTR_INLINE detail::metadata metadata(variant key, variant value);
  607. /*!
  608. * The \ref value function should be used to add a mapping from enum `name` to `value`
  609. * during the registration process of reflection information. Use it in the `()` operator of the returned
  610. * \ref bind object.
  611. *
  612. * \see \ref registration::enumeration
  613. */
  614. template<typename Enum_Type>
  615. RTTR_INLINE detail::enum_data<Enum_Type> value(string_view, Enum_Type value);
  616. /*!
  617. * The \ref default_arguments function should be used add default arguments,
  618. * for \ref constructor "constructors" or a \ref method "methods" during the registration process of reflection information.
  619. * Use it in the `()` operator of the returned \ref bind object.
  620. *
  621. * The given arguments must match the signature from the starting position to the right most argument.
  622. *
  623. * See following example code:
  624. * \code{.cpp}
  625. *
  626. * void my_function(int a, bool b, const std::string& text);
  627. *
  628. * RTTR_REGISTRATION
  629. * {
  630. * using namespace rttr;
  631. *
  632. * registration::method("my_function", &my_function)
  633. * (
  634. * default_arguments(true, std::string("default text"))
  635. * );
  636. *
  637. * // however setting default arguments like this, will raise a compile time error
  638. * registration::method("my_function2", &my_function)
  639. * (
  640. * default_arguments(true) // does not work!!!; default value for the last argument is missing...
  641. * );
  642. * }
  643. *
  644. * \endcode
  645. *
  646. */
  647. template<typename...TArgs>
  648. RTTR_INLINE detail::default_args<TArgs...> default_arguments(TArgs&&...args);
  649. /*!
  650. * The \ref parameter_names function should be used add human-readable names of the parameters,
  651. * for \ref constructor "constructors" or a \ref method "methods" during the registration process of reflection information.
  652. * Use it in the `()` operator of the returned \ref bind object.
  653. *
  654. * The names must be provided as string literals (i.e. const char*) arguments.
  655. *
  656. * See following example code:
  657. * \code{.cpp}
  658. * using namespace rttr;
  659. *
  660. * void set_window_geometry(const char* name, int w, int h) {...}
  661. *
  662. * RTTR_REGISTRATION
  663. * {
  664. * registration::method("set_window_geometry", &set_window_geometry)
  665. * (
  666. * parameter_names("window name", "width", "height")
  667. * );
  668. * }
  669. * \endcode
  670. *
  671. * \see \ref parameter_info
  672. *
  673. */
  674. template<typename...TArgs>
  675. RTTR_INLINE detail::parameter_names<detail::decay_t<TArgs>...> parameter_names(TArgs&&...args);
  676. /////////////////////////////////////////////////////////////////////////////////////////
  677. /////////////////////////////////////////////////////////////////////////////////////////
  678. /////////////////////////////////////////////////////////////////////////////////////////
  679. #ifdef DOXYGEN
  680. /*!
  681. * \brief Use this macro to automatically register your reflection information to RTTR before `main` is called.
  682. *
  683. * Use it in following way:
  684. * \code{.cpp}
  685. * RTTR_REGISTRATION
  686. * {
  687. * rttr::registration::method("foo", &foo);
  688. * }
  689. * \endcode
  690. *
  691. * Just place the macro in global scope in a cpp file.
  692. *
  693. * \remark It is not possible to place the macro multiple times in one cpp file.
  694. *
  695. */
  696. #define RTTR_REGISTRATION
  697. /*!
  698. * \brief Use this macro to automatically register your reflection information inside a plugin to RTTR.
  699. *
  700. * Use it in following way:
  701. * \code{.cpp}
  702. *
  703. * int some_method() { return 42; }
  704. *
  705. * RTTR_PLUGIN_REGISTRATION
  706. * {
  707. * rttr::registration::method("some_method", &some_method);
  708. * }
  709. * \endcode
  710. *
  711. * Just place the macro in global scope in a cpp file.
  712. *
  713. * \remark It is not possible to place the macro multiple times in one cpp file.
  714. * When you compile your plugin with the `gcc` toolchain, make sure you use the compiler option: `-fno-gnu-unique`.
  715. * otherwise the unregistration will not work properly.
  716. *
  717. * \see library
  718. */
  719. #define RTTR_PLUGIN_REGISTRATION
  720. /*!
  721. * \brief Place this macro inside a class, when you need to reflect properties,
  722. * methods or constructors which are declared in `protected` or `private` scope of the class.
  723. *
  724. \code{.cpp}
  725. class Foo
  726. {
  727. private:
  728. int m_value;
  729. RTTR_REGISTRATION_FRIEND
  730. };
  731. \endcode
  732. \code{.cpp}
  733. RTTR_REGISTRATION
  734. {
  735. rttr::registration::class_<Foo>()
  736. .property("value", &Foo::m_value);
  737. }
  738. \endcode
  739. */
  740. #define RTTR_REGISTRATION_FRIEND
  741. /*!
  742. * The \ref bind class is used to chain registration calls.
  743. *
  744. * The class should not be instantiate directly, because it will be created automatically,
  745. * when a *constructor*, *property*, *method* or *enumeration* is registered.
  746. *
  747. * Additionally, the class has implemented the bracket operator `()` as variadic function template.
  748. * Use it to forward \ref rttr::metadata() "metadata()" or \ref policy "policies" to the previous registered item.
  749. *
  750. * \remark Do not instantiate this class directly!
  751. */
  752. template<typename...T>
  753. class registration::bind : public detail::base_class
  754. {
  755. public:
  756. /*!
  757. * \brief The bracket operator can be used to add additional meta data or policies.
  758. */
  759. template<typename... Args>
  760. base_class operator()(Args&&... arg);
  761. };
  762. #endif
  763. } // end namespace rttr
  764. #include "rttr/detail/registration/registration_impl.h"
  765. #endif // RTTR_REGISTRATION_H_