Aikido
metaprogramming-impl.hpp
Go to the documentation of this file.
1 namespace aikido {
2 namespace common {
3 
4 //==============================================================================
5 template <class Pointee>
7 {
8  using type = std::shared_ptr<Pointee>;
9 
10  template <class Derived>
11  static std::shared_ptr<Derived> cast(std::shared_ptr<Pointee> _pointer)
12  {
13  return std::dynamic_pointer_cast<Derived>(std::move(_pointer));
14  }
15 };
16 
17 //==============================================================================
18 template <class Pointee>
20 {
21  using type = Pointee*;
22 
23  template <class Derived>
24  static Derived* cast(Pointee* _pointer)
25  {
26  return dynamic_cast<Derived*>(_pointer);
27  }
28 };
29 
30 //==============================================================================
31 template <
32  template <class> class Factory,
33  template <class> class Pointer,
34  class BaseParameter>
35 struct DynamicCastFactory<Factory, Pointer, BaseParameter, common::type_list<>>
36 {
37  template <class... Parameters>
38  static std::nullptr_t create(
39  typename Pointer<BaseParameter>::type /* unused */,
40  Parameters&&... /* unused */)
41  {
42  return nullptr;
43  }
44 };
45 
46 //==============================================================================
47 template <
48  template <class> class Factory,
49  template <class> class Pointer,
50  class BaseParameter,
51  class Arg,
52  class... Args>
54  Factory,
55  Pointer,
56  BaseParameter,
57  common::type_list<Arg, Args...>>
58 {
59  template <class... Parameters>
60  static auto create(
61  typename Pointer<BaseParameter>::type _base, Parameters&&... _params)
62  -> decltype(Factory<Arg>::create(
63  Pointer<BaseParameter>::template cast<Arg>(_base),
64  std::forward<Parameters>(_params)...))
65  {
66  if (auto derived = Pointer<BaseParameter>::template cast<Arg>(_base))
67  {
68  return Factory<Arg>::create(
69  std::move(derived), std::forward<Parameters>(_params)...);
70  }
71  else
72  {
73  return DynamicCastFactory<
74  Factory,
75  Pointer,
76  BaseParameter,
77  common::type_list<Args...>>::
78  create(std::move(_base), std::forward<Parameters>(_params)...);
79  }
80  }
81 };
82 
83 } // namespace common
84 } // namespace aikido
aikido::common::DynamicCastFactory_raw_ptr::type
Pointee * type
Definition: metaprogramming-impl.hpp:21
aikido
Format of serialized trajectory in YAML.
Definition: algorithm.hpp:4
aikido::common::DynamicCastFactory_shared_ptr::cast
static std::shared_ptr< Derived > cast(std::shared_ptr< Pointee > _pointer)
Definition: metaprogramming-impl.hpp:11
aikido::common::DynamicCastFactory_shared_ptr
Helper template class necessary to use std::shared_ptr as the pointer type in DynamicCastFactory.
Definition: metaprogramming-impl.hpp:6
aikido::common::DynamicCastFactory_raw_ptr::cast
static Derived * cast(Pointee *_pointer)
Definition: metaprogramming-impl.hpp:24
aikido::common::type_list
Wrapper for a variadic template parameter pack of types.
Definition: metaprogramming.hpp:13
aikido::common::DynamicCastFactory< Factory, Pointer, BaseParameter, common::type_list<> >::create
static std::nullptr_t create(typename Pointer< BaseParameter >::type, Parameters &&...)
Definition: metaprogramming-impl.hpp:38
aikido::common::DynamicCastFactory_shared_ptr::type
std::shared_ptr< Pointee > type
Definition: metaprogramming-impl.hpp:8
aikido::common::DynamicCastFactory
Call a template factory function based on runtime type of the first argument to a function.
Definition: metaprogramming.hpp:47
aikido::common::DynamicCastFactory_raw_ptr
Helper template class necessary to use raw pointers as the pointer type in DynamicCastFactory.
Definition: metaprogramming-impl.hpp:19
aikido::common::DynamicCastFactory< Factory, Pointer, BaseParameter, common::type_list< Arg, Args... > >::create
static auto create(typename Pointer< BaseParameter >::type _base, Parameters &&... _params) -> decltype(Factory< Arg >::create(Pointer< BaseParameter >::template cast< Arg >(_base), std::forward< Parameters >(_params)...))
Definition: metaprogramming-impl.hpp:60