Alexander Afanasyev | 30cb117 | 2012-07-06 10:47:39 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #ifndef FUNCTOR_HOOK_H_ |
| 22 | #define FUNCTOR_HOOK_H_ |
| 23 | |
| 24 | #include <boost/intrusive/parent_from_member.hpp> |
| 25 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 26 | namespace ns3 { |
| 27 | namespace ndn { |
| 28 | namespace ndnSIM { |
| 29 | namespace detail { |
Alexander Afanasyev | 30cb117 | 2012-07-06 10:47:39 -0700 | [diff] [blame] | 30 | |
| 31 | template<class BaseHook, class ValueType, int N> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 32 | struct FunctorHook { |
Alexander Afanasyev | 30cb117 | 2012-07-06 10:47:39 -0700 | [diff] [blame] | 33 | typedef typename BaseHook::template index<N>::type hook_type; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 34 | typedef hook_type* hook_ptr; |
| 35 | typedef const hook_type* const_hook_ptr; |
| 36 | |
| 37 | typedef ValueType value_type; |
| 38 | typedef value_type* pointer; |
| 39 | typedef const value_type* const_pointer; |
| 40 | |
| 41 | // Required static functions |
| 42 | static hook_ptr |
| 43 | to_hook_ptr(value_type& value) |
Alexander Afanasyev | 30cb117 | 2012-07-06 10:47:39 -0700 | [diff] [blame] | 44 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 45 | return &value.policy_hook_.template get<N>(); |
Alexander Afanasyev | 30cb117 | 2012-07-06 10:47:39 -0700 | [diff] [blame] | 46 | } |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 47 | |
| 48 | static const_hook_ptr |
| 49 | to_hook_ptr(const value_type& value) |
Alexander Afanasyev | 30cb117 | 2012-07-06 10:47:39 -0700 | [diff] [blame] | 50 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 51 | return &value.policy_hook_.template get<N>(); |
| 52 | } |
| 53 | |
| 54 | static pointer |
| 55 | to_value_ptr(hook_ptr n) |
| 56 | { |
| 57 | return boost::intrusive::get_parent_from_member<value_type>( |
| 58 | static_cast<BaseHook*>( |
| 59 | boost::intrusive::get_parent_from_member<wrap<hook_type>>(n, &wrap<hook_type>::value_)), |
| 60 | &value_type::policy_hook_); |
| 61 | } |
| 62 | static const_pointer |
| 63 | to_value_ptr(const_hook_ptr n) |
| 64 | { |
| 65 | return boost::intrusive::get_parent_from_member<value_type>( |
| 66 | static_cast<const BaseHook*>( |
| 67 | boost::intrusive::get_parent_from_member<wrap<hook_type>>(n, &wrap<hook_type>::value_)), |
| 68 | &value_type::policy_hook_); |
Alexander Afanasyev | 30cb117 | 2012-07-06 10:47:39 -0700 | [diff] [blame] | 69 | } |
| 70 | }; |
| 71 | |
| 72 | } // detail |
| 73 | } // ndnSIM |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 74 | } // ndn |
Alexander Afanasyev | e77db79 | 2012-08-09 11:10:58 -0700 | [diff] [blame] | 75 | } // ns3 |
Alexander Afanasyev | 30cb117 | 2012-07-06 10:47:39 -0700 | [diff] [blame] | 76 | |
| 77 | #endif // FUNCTOR_HOOK_H_ |