Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Context
- {
- public:
- template<typename Property>
- void Put(typename Property::value_type& val)
- {
- m_map[typeid(Property)] = std::static_pointer_cast<void>(val);
- }
- template<typename Property>
- typename Property::value_type Get() const
- {
- typedef Property::value_type result_type;
- auto it = m_map.find(typeid(Property));
- if (it == m_map.end())
- return result_type();
- return std::static_pointer_cast<typename result_type::element_type>(it->second);
- }
- private:
- std::map<std::type_index, std::shared_ptr<void>> m_map;
- };
- struct first_bone
- {
- typedef BonePtr value_type;
- };
- void example()
- {
- Context ctx;
- BonePtr b;
- ctx.Put<first_bone>(b);
- BonePtr bb = ctx.Get<first_bone>();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement