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