blob: 63dcffdf9a520a01140df9816b6683e87fd032ab [file] [log] [blame]
Alexander Afanasyev30cb1172012-07-06 10:47:39 -07001/* -*- 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 Afanasyeve77db792012-08-09 11:10:58 -070026namespace ns3
27{
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070028namespace ndnSIM
29{
30namespace detail
31{
32
33template<class BaseHook, class ValueType, int N>
34struct FunctorHook
35{
36 typedef typename BaseHook::template index<N>::type hook_type;
37 typedef hook_type* hook_ptr;
38 typedef const hook_type* const_hook_ptr;
39
40 typedef ValueType value_type;
41 typedef value_type* pointer;
42 typedef const value_type* const_pointer;
43
44 //Required static functions
45 static hook_ptr to_hook_ptr (value_type &value)
46 { return &value.policy_hook_.template get<N> (); }
47
48 static const_hook_ptr to_hook_ptr(const value_type &value)
49 { return &value.policy_hook_.template get<N> (); }
50
51 static pointer to_value_ptr(hook_ptr n)
52 {
53 return
54 boost::intrusive::get_parent_from_member<value_type>
55 (static_cast<BaseHook*> (boost::intrusive::get_parent_from_member< wrap<hook_type> >(n, &wrap<hook_type>::value_)),
56 &value_type::policy_hook_);
57 }
58 static const_pointer to_value_ptr(const_hook_ptr n)
59 {
60 return
61 boost::intrusive::get_parent_from_member<value_type>
62 (static_cast<const BaseHook*> (boost::intrusive::get_parent_from_member< wrap<hook_type> >(n, &wrap<hook_type>::value_)),
63 &value_type::policy_hook_);
64 }
65};
66
67} // detail
68} // ndnSIM
Alexander Afanasyeve77db792012-08-09 11:10:58 -070069} // ns3
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070070
71#endif // FUNCTOR_HOOK_H_