All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
components_replace.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2013 Piotr Wygocki
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
15 #ifndef PAAL_COMPONENTS_REPLACE_HPP
16 #define PAAL_COMPONENTS_REPLACE_HPP
17 
19 
20 namespace paal {
21 namespace data_structures {
22 
30 template <typename Name, typename NewType, typename components>
32 
43 template <typename Name, typename NewType, typename Names, typename Types>
44 class replaced_type<Name, NewType, detail::components<Names, Types>> {
45  static const int p = pos<Name, Names>::value; // position to insert
46  typedef typename replace_at_pos<p, NewType, Types>::type TypesReplace;
47 
48  public:
50 };
51 
52 namespace detail {
53 
59 template <typename Comp> struct get_types;
60 
68 template <typename Names, typename Types>
69 struct get_types<components<Names, Types>> {
70  typedef Types type;
71 };
72 
83 template <typename Name, typename NewType, typename Names, typename Types>
86  typedef typename replaced_type<Name, NewType, Comps>::type Replaced;
87  typedef typename detail::get_types<Replaced>::type NewTypes;
88 
89  public:
90  temp_replaced_components(const Comps &comps, const NewType &comp)
91  : m_comps(comps), m_comp(comp) {}
92 
93  template <typename ComponentName>
94  const typename detail::type_for_name<ComponentName, Names, NewTypes>::type &
95  get() const {
97  }
98 
99  private:
100 
101  template <typename ComponentName>
102  auto get(detail::wrap_to_constructable<ComponentName>) const->decltype(
103  std::declval<const Comps>().template get<ComponentName>()) {
104  return m_comps.template get<ComponentName>();
105  }
106 
107  const NewType &get(detail::wrap_to_constructable<Name>) const {
108  return m_comp;
109  }
110 
111  const Comps &m_comps;
112  const NewType &m_comp;
113 };
114 }
115 
137 template <typename Name, typename NewType, typename Names, typename Types>
140  typedef detail::components<Names, Types> Comps;
141  typedef typename replaced_type<Name, NewType, Comps>::type Replaced;
142 
143  return Replaced(
145  components, comp),
146  copy_tag());
147 }
148 
149 } // data_structures
150 } // paal
151 
152 #endif // PAAL_COMPONENTS_REPLACE_HPP
replaced_type< Name, NewType, detail::components< Names, Types > >::type replace(NewType comp, detail::components< Names, Types > components)
This function, for a specific Name, replaces compoonent in the components class. The comonent should ...
replace element at pos to NewType
returns pos of the element in the TypesVector
Indicates that components constructor is in fact a Copy/Move Constructor.
Definition: components.hpp:39
Generic version of replaced_type.