blob: 17542badca6830540b35a9bcf8571e34168df4a5 [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyev30cb1172012-07-06 10:47:39 -07004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyev30cb1172012-07-06 10:47:39 -07007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070019
20#ifndef FUNCTOR_HOOK_H_
21#define FUNCTOR_HOOK_H_
22
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080023/// @cond include_hidden
24
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070025#include <boost/intrusive/parent_from_member.hpp>
26
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070027namespace ns3 {
28namespace ndn {
29namespace ndnSIM {
30namespace detail {
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070031
32template<class BaseHook, class ValueType, int N>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080033struct FunctorHook {
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070034 typedef typename BaseHook::template index<N>::type hook_type;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080035 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
44 to_hook_ptr(value_type& value)
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070045 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080046 return &value.policy_hook_.template get<N>();
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070047 }
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080048
49 static const_hook_ptr
50 to_hook_ptr(const value_type& value)
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070051 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080052 return &value.policy_hook_.template get<N>();
53 }
54
55 static pointer
56 to_value_ptr(hook_ptr n)
57 {
58 return boost::intrusive::get_parent_from_member<value_type>(
59 static_cast<BaseHook*>(
60 boost::intrusive::get_parent_from_member<wrap<hook_type>>(n, &wrap<hook_type>::value_)),
61 &value_type::policy_hook_);
62 }
63 static const_pointer
64 to_value_ptr(const_hook_ptr n)
65 {
66 return boost::intrusive::get_parent_from_member<value_type>(
67 static_cast<const BaseHook*>(
68 boost::intrusive::get_parent_from_member<wrap<hook_type>>(n, &wrap<hook_type>::value_)),
69 &value_type::policy_hook_);
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070070 }
71};
72
73} // detail
74} // ndnSIM
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070075} // ndn
Alexander Afanasyeve77db792012-08-09 11:10:58 -070076} // ns3
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070077
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080078/// @endcond
79
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070080#endif // FUNCTOR_HOOK_H_