blob: 84e2f55e876c08e419f5b2b1a1b1c1d8612c8305 [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
23#include <boost/mpl/inherit_linearly.hpp>
24#include <boost/mpl/inherit.hpp>
25#include <boost/mpl/at.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
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080032template<class T>
33struct wrap {
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070034 T value_;
35};
36
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080037template<class Vector>
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070038struct multi_type_container
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080039 : public boost::mpl::inherit_linearly<Vector, boost::mpl::inherit<wrap<boost::mpl::_2>,
40 boost::mpl::_1>>::type {
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070041 template<int N>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080042 struct index {
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070043 typedef typename boost::mpl::at_c<Vector, N>::type type;
44 };
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080045
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070046 template<class T>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080047 T&
48 get()
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070049 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080050 return static_cast<wrap<T>&>(*this).value_;
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070051 }
52
53 template<class T>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080054 const T&
55 get() const
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070056 {
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080057 return static_cast<const wrap<T>&>(*this).value_;
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070058 }
59
60 template<int N>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080061 typename boost::mpl::at_c<Vector, N>::type&
62 get()
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070063 {
64 typedef typename boost::mpl::at_c<Vector, N>::type T;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080065 return static_cast<wrap<T>&>(*this).value_;
66 }
67
68 template<int N>
69 const typename boost::mpl::at_c<Vector, N>::type&
70 get() const
71 {
72 typedef typename boost::mpl::at_c<Vector, N>::type T;
73 return static_cast<const wrap<T>&>(*this).value_;
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070074 }
75};
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080076
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070077} // detail
78} // ndnSIM
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070079} // ndn
Alexander Afanasyeve77db792012-08-09 11:10:58 -070080} // ns3
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070081
82#endif // MULTI_TYPE_CONTAINER_H_