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>
33  class Factory,
34  template <class>
35  class Pointer,
36  class BaseParameter>
37 struct DynamicCastFactory<Factory, Pointer, BaseParameter, common::type_list<>>
38 {
39  template <class... Parameters>
40  static std::nullptr_t create(
41  typename Pointer<BaseParameter>::type /* unused */,
42  Parameters&&... /* unused */)
43  {
44  return nullptr;
45  }
46 };
47 
48 //==============================================================================
49 template <
50  template <class>
51  class Factory,
52  template <class>
53  class Pointer,
54  class BaseParameter,
55  class Arg,
56  class... Args>
58  Factory,
59  Pointer,
60  BaseParameter,
61  common::type_list<Arg, Args...>>
62 {
63  template <class... Parameters>
64  static auto create(
65  typename Pointer<BaseParameter>::type _base, Parameters&&... _params)
66  -> decltype(Factory<Arg>::create(
67  Pointer<BaseParameter>::template cast<Arg>(_base),
68  std::forward<Parameters>(_params)...))
69  {
70  if (auto derived = Pointer<BaseParameter>::template cast<Arg>(_base))
71  {
72  return Factory<Arg>::create(
73  std::move(derived), std::forward<Parameters>(_params)...);
74  }
75  else
76  {
77  return DynamicCastFactory<
78  Factory,
79  Pointer,
80  BaseParameter,
81  common::type_list<Args...>>::
82  create(std::move(_base), std::forward<Parameters>(_params)...);
83  }
84  }
85 };
86 
87 } // namespace common
88 } // 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:40
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:49
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:64