blob: f84f860ac76a0a2d81e19ec82008f4f426815d31 [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 MULTI_TYPE_CONTAINER_H_
21#define MULTI_TYPE_CONTAINER_H_
22
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080023/// @cond include_hidden
24
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070025#include <boost/mpl/inherit_linearly.hpp>
26#include <boost/mpl/inherit.hpp>
27#include <boost/mpl/at.hpp>
28
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070029namespace ns3 {
30namespace ndn {
31namespace ndnSIM {
32namespace detail {
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070033
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080034template<class T>
35struct wrap {
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070036 T value_;
37};
38
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080039template<class Vector>
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070040struct multi_type_container
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080041 : public boost::mpl::inherit_linearly<Vector, boost::mpl::inherit<wrap<boost::mpl::_2>,
42 boost::mpl::_1>>::type {
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070043 template<int N>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080044 struct index {
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070045 typedef typename boost::mpl::at_c<Vector, N>::type type;
46 };
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080047
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070048 template<class T>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080049 T&
50 get()
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070051 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080052 return static_cast<wrap<T>&>(*this).value_;
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070053 }
54
55 template<class T>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080056 const T&
57 get() const
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070058 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080059 return static_cast<const wrap<T>&>(*this).value_;
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070060 }
61
62 template<int N>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080063 typename boost::mpl::at_c<Vector, N>::type&
64 get()
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070065 {
66 typedef typename boost::mpl::at_c<Vector, N>::type T;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080067 return static_cast<wrap<T>&>(*this).value_;
68 }
69
70 template<int N>
71 const typename boost::mpl::at_c<Vector, N>::type&
72 get() const
73 {
74 typedef typename boost::mpl::at_c<Vector, N>::type T;
75 return static_cast<const wrap<T>&>(*this).value_;
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070076 }
77};
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080078
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070079} // detail
80} // ndnSIM
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070081} // ndn
Alexander Afanasyeve77db792012-08-09 11:10:58 -070082} // ns3
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070083
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080084/// @cond include_hidden
85
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070086#endif // MULTI_TYPE_CONTAINER_H_