NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
multi-type-container.h
1 /* -*- 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 
28 namespace ns3 {
29 namespace ndn {
30 namespace ndnSIM {
31 namespace detail {
32 
33 template <class T>
34 struct wrap
35 {
36  T value_;
37 };
38 
39 template< class Vector >
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
83 } // ndn
84 } // ns3
85 
86 #endif // MULTI_TYPE_CONTAINER_H_