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