blob: f34969cd07ef91b1c65287ab83d1385b2a9f2945 [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 Afanasyev2b4c9472012-08-09 15:00:38 -070026namespace ns3 {
27namespace ndn {
28namespace ndnSIM {
29namespace detail {
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070030
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
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070067} // ndn
Alexander Afanasyeve77db792012-08-09 11:10:58 -070068} // ns3
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070069
70#endif // FUNCTOR_HOOK_H_