blob: d4971c46320743f802ba25aa9b5da85388e90821 [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) 2011 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 MULTI_TYPE_CONTAINER_H_
22#define MULTI_TYPE_CONTAINER_H_
23
24#include <boost/mpl/inherit_linearly.hpp>
25#include <boost/mpl/inherit.hpp>
26#include <boost/mpl/at.hpp>
27
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070028namespace ns3 {
29namespace ndn {
30namespace ndnSIM {
31namespace detail {
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070032
33template <class T>
34struct wrap
35{
36 T value_;
37};
38
39template< class Vector >
40struct multi_type_container
41 : public boost::mpl::inherit_linearly< Vector, boost::mpl::inherit<wrap<boost::mpl::_2>, boost::mpl::_1 >
42 >::type
43{
44 template<int N>
45 struct index
46 {
47 typedef typename boost::mpl::at_c<Vector, N>::type type;
48 };
49
50 template<class T>
51 T &
52 get ()
53 {
54 return static_cast< wrap<T> &> (*this).value_;
55 }
56
57 template<class T>
58 const T &
59 get () const
60 {
61 return static_cast< const wrap<T> &> (*this).value_;
62 }
63
64 template<int N>
65 typename boost::mpl::at_c<Vector, N>::type &
66 get ()
67 {
68 typedef typename boost::mpl::at_c<Vector, N>::type T;
69 return static_cast< wrap<T> &> (*this).value_;
70 }
71
72 template<int N>
73 const typename boost::mpl::at_c<Vector, N>::type &
74 get () const
75 {
76 typedef typename boost::mpl::at_c<Vector, N>::type T;
77 return static_cast< const wrap<T> &> (*this).value_;
78 }
79};
80
81} // detail
82} // ndnSIM
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070083} // ndn
Alexander Afanasyeve77db792012-08-09 11:10:58 -070084} // ns3
Alexander Afanasyev30cb1172012-07-06 10:47:39 -070085
86#endif // MULTI_TYPE_CONTAINER_H_