A Discrete-Event Network Simulator
API
type-traits.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 INRIA
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  */
19 
20 #ifndef TYPE_TRAITS_H
21 #define TYPE_TRAITS_H
22 
23 #include "ptr.h"
24 
31 namespace ns3 {
32 
38 template <typename T>
39 struct TypeTraits
40 {
41 private:
43  struct NullType {};
48  template <typename U> struct UnConst
49  {
50  typedef U Result;
51  };
56  template <typename U> struct UnConst<const U>
57  {
58  typedef U Result;
59  };
64  template <typename U> struct ReferenceTraits
65  { enum { IsReference = 0 };
67  typedef U ReferencedType;
68  };
73  template <typename U> struct ReferenceTraits<U&>
74  { enum { IsReference = 1 };
76  typedef U ReferencedType;
77  };
82  template <typename U> struct PointerTraits
83  { enum { IsPointer = 0,
85  IsPtr = 0 };
86  typedef U PointeeType;
87  };
92  template <typename U> struct PointerTraits<U *>
93  { enum { IsPointer = 1,
95  IsPtr = 0 };
96  typedef U PointeeType;
97  };
102  template <typename U> struct PointerTraits<ns3::Ptr<U> >
103  { enum { IsPointer = 0,
105  IsPtr = 1 };
106  typedef U PointeeType;
107  };
112  template <typename U> struct Base
113  {
114  typedef U Type;
115  };
120  template <typename U> struct Base <U &>
121  {
122  typedef typename Base<U>::Type Type;
123  };
128  template <typename U> struct Base <U *>
129  {
130  typedef typename Base<U>::Type Type;
131  };
136  template <typename U> struct Base <const U >
137  {
138  typedef typename Base<U>::Type Type;
139  };
144  template <typename U> struct PtrBase
145  {
146  typedef U Type;
147  };
152  template <typename U> struct PtrBase <ns3::Ptr<U> >
153  {
154  typedef U Type;
155  };
160  template <typename U> struct FunctionPtrTraits
161  { enum { IsFunctionPointer = 0 };
164  };
169  template <typename U>
170  struct FunctionPtrTraits <U (*)(void)>
171  { enum { IsFunctionPointer = 1 }; enum { nArgs = 0 };
174  typedef U ReturnType;
175  };
181  template <typename U,
182  typename V1>
183  struct FunctionPtrTraits <U (*)(V1)>
184  { enum { IsFunctionPointer = 1 }; enum { nArgs = 1 };
187  typedef U ReturnType;
188  typedef V1 Arg1Type;
189  };
196  template <typename U,
197  typename V1, typename V2>
198  struct FunctionPtrTraits <U (*)(V1,V2)>
199  { enum { IsFunctionPointer = 1 }; enum { nArgs = 2 };
202  typedef U ReturnType;
203  typedef V1 Arg1Type;
204  typedef V2 Arg2Type;
205  };
213  template <typename U,
214  typename V1, typename V2, typename V3>
215  struct FunctionPtrTraits <U (*)(V1,V2,V3)>
216  { enum { IsFunctionPointer = 1 }; enum { nArgs = 3 };
219  typedef U ReturnType;
220  typedef V1 Arg1Type;
221  typedef V2 Arg2Type;
222  typedef V3 Arg3Type;
223  };
232  template <typename U,
233  typename V1, typename V2, typename V3,
234  typename V4>
235  struct FunctionPtrTraits <U (*)(V1,V2,V3,V4)>
236  { enum { IsFunctionPointer = 1 }; enum { nArgs = 4 };
239  typedef U ReturnType;
240  typedef V1 Arg1Type;
241  typedef V2 Arg2Type;
242  typedef V3 Arg3Type;
243  typedef V4 Arg4Type;
244  };
254  template <typename U,
255  typename V1, typename V2, typename V3,
256  typename V4, typename V5>
257  struct FunctionPtrTraits <U (*)(V1,V2,V3,V4,V5)>
258  { enum { IsFunctionPointer = 1 }; enum { nArgs = 5 };
261  typedef U ReturnType;
262  typedef V1 Arg1Type;
263  typedef V2 Arg2Type;
264  typedef V3 Arg3Type;
265  typedef V4 Arg4Type;
266  typedef V5 Arg5Type;
267  };
278  template <typename U,
279  typename V1, typename V2, typename V3,
280  typename V4, typename V5, typename V6>
281  struct FunctionPtrTraits <U (*)(V1,V2,V3,V4,V5,V6)>
282  { enum { IsFunctionPointer = 1 }; enum { nArgs = 6 };
285  typedef U ReturnType;
286  typedef V1 Arg1Type;
287  typedef V2 Arg2Type;
288  typedef V3 Arg3Type;
289  typedef V4 Arg4Type;
290  typedef V5 Arg5Type;
291  typedef V6 Arg6Type;
292  };
297  template <typename U> struct PtrToMemberTraits
298  { enum { IsPointerToMember = 0 };
300  };
306  template <typename U, typename V>
307  struct PtrToMemberTraits <U (V::*) (void)>
308  { enum { IsPointerToMember = 1 }; enum { nArgs = 0 };
311  typedef U ReturnType;
312  };
318  template <typename U, typename V>
319  struct PtrToMemberTraits <U (V::*) (void) const>
320  { enum { IsPointerToMember = 1 }; enum { nArgs = 0 };
323  typedef U ReturnType;
324  };
331  template <typename U, typename V,
332  typename W1>
333  struct PtrToMemberTraits <U (V::*) (W1)>
334  { enum { IsPointerToMember = 1 }; enum { nArgs = 1 };
337  typedef U ReturnType;
338  typedef W1 Arg1Type;
339  };
346  template <typename U, typename V,
347  typename W1>
348  struct PtrToMemberTraits <U (V::*) (W1) const>
349  { enum { IsPointerToMember = 1 }; enum { nArgs = 1 };
352  typedef U ReturnType;
353  typedef W1 Arg1Type;
354  };
362  template <typename U, typename V,
363  typename W1, typename W2>
364  struct PtrToMemberTraits <U (V::*) (W1,W2)>
365  { enum { IsPointerToMember = 1 }; enum { nArgs = 2 };
368  typedef U ReturnType;
369  typedef W1 Arg1Type;
370  typedef W2 Arg2Type;
371  };
379  template <typename U, typename V,
380  typename W1, typename W2>
381  struct PtrToMemberTraits <U (V::*) (W1,W2) const>
382  { enum { IsPointerToMember = 1 }; enum { nArgs = 2 };
385  typedef U ReturnType;
386  typedef W1 Arg1Type;
387  typedef W2 Arg2Type;
388  };
397  template <typename U, typename V,
398  typename W1, typename W2, typename W3>
399  struct PtrToMemberTraits <U (V::*) (W1,W2,W3)>
400  { enum { IsPointerToMember = 1 }; enum { nArgs = 3 };
403  typedef U ReturnType;
404  typedef W1 Arg1Type;
405  typedef W2 Arg2Type;
406  typedef W3 Arg3Type;
407  };
416  template <typename U, typename V,
417  typename W1, typename W2, typename W3>
418  struct PtrToMemberTraits <U (V::*) (W1,W2,W3) const>
419  { enum { IsPointerToMember = 1 }; enum { nArgs = 3 };
422  typedef U ReturnType;
423  typedef W1 Arg1Type;
424  typedef W2 Arg2Type;
425  typedef W3 Arg3Type;
426  };
436  template <typename U, typename V,
437  typename W1, typename W2, typename W3,
438  typename W4>
439  struct PtrToMemberTraits <U (V::*) (W1,W2,W3,W4)>
440  { enum { IsPointerToMember = 1 }; enum { nArgs = 4 };
443  typedef U ReturnType;
444  typedef W1 Arg1Type;
445  typedef W2 Arg2Type;
446  typedef W3 Arg3Type;
447  typedef W4 Arg4Type;
448  };
458  template <typename U, typename V,
459  typename W1, typename W2, typename W3,
460  typename W4>
461  struct PtrToMemberTraits <U (V::*) (W1,W2,W3,W4) const>
462  { enum { IsPointerToMember = 1 }; enum { nArgs = 4 };
465  typedef U ReturnType;
466  typedef W1 Arg1Type;
467  typedef W2 Arg2Type;
468  typedef W3 Arg3Type;
469  typedef W4 Arg4Type;
470  };
481  template <typename U, typename V,
482  typename W1, typename W2, typename W3,
483  typename W4, typename W5>
484  struct PtrToMemberTraits <U (V::*) (W1,W2,W3,W4,W5)>
485  { enum { IsPointerToMember = 1 }; enum { nArgs = 5 };
488  typedef U ReturnType;
489  typedef W1 Arg1Type;
490  typedef W2 Arg2Type;
491  typedef W3 Arg3Type;
492  typedef W4 Arg4Type;
493  typedef W5 Arg5Type;
494  };
505  template <typename U, typename V,
506  typename W1, typename W2, typename W3,
507  typename W4, typename W5>
508  struct PtrToMemberTraits <U (V::*) (W1,W2,W3,W4,W5) const>
509  { enum { IsPointerToMember = 1 }; enum { nArgs = 5 };
512  typedef U ReturnType;
513  typedef W1 Arg1Type;
514  typedef W2 Arg2Type;
515  typedef W3 Arg3Type;
516  typedef W4 Arg4Type;
517  typedef W5 Arg5Type;
518  };
530  template <typename U, typename V,
531  typename W1, typename W2, typename W3,
532  typename W4, typename W5, typename W6>
533  struct PtrToMemberTraits <U (V::*) (W1,W2,W3,W4,W5,W6)>
534  { enum { IsPointerToMember = 1 }; enum { nArgs = 6 };
537  typedef U ReturnType;
538  typedef W1 Arg1Type;
539  typedef W2 Arg2Type;
540  typedef W3 Arg3Type;
541  typedef W4 Arg4Type;
542  typedef W5 Arg5Type;
543  typedef W6 Arg6Type;
544  };
556  template <typename U, typename V,
557  typename W1, typename W2, typename W3,
558  typename W4, typename W5, typename W6>
559  struct PtrToMemberTraits <U (V::*) (W1,W2,W3,W4,W5,W6) const>
560  { enum { IsPointerToMember = 1 }; enum { nArgs = 6 };
563  typedef U ReturnType;
564  typedef W1 Arg1Type;
565  typedef W2 Arg2Type;
566  typedef W3 Arg3Type;
567  typedef W4 Arg4Type;
568  typedef W5 Arg5Type;
569  typedef W6 Arg6Type;
570  };
571 
572 public:
580  typedef typename Base<T>::Type BaseType;
582  typedef typename PtrBase<T>::Type PtrBaseType;
584  enum {
595  };
597  typedef PtrToMemberTraits<T> PointerToMemberTraits;
599  typedef FunctionPtrTraits<T> FunctionPointerTraits;
600 };
601 
602 } // namespace ns3
603 
604 #endif /* TYPE_TRAITS_H */
PointerTraits< T >::PointeeType PointeeType
Pointee type.
Definition: type-traits.h:578
Base< U >::Type Type
Base type.
Definition: type-traits.h:122
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Ptr predicate.
Definition: type-traits.h:590
ns3::Ptr smart pointer declaration and implementation.
Not a const type.
Definition: type-traits.h:48
PtrBase< T >::Type PtrBaseType
Ptr base type.
Definition: type-traits.h:582
ReferenceTraits< T >::ReferencedType ReferencedType
Referenced type.
Definition: type-traits.h:576
Base< T >::Type BaseType
Base type, after removing &, * and const.
Definition: type-traits.h:580
Pointer predicate.
Definition: type-traits.h:588
NullType ReturnType
Return type.
Definition: type-traits.h:163
Base< U >::Type Type
Base type.
Definition: type-traits.h:130
Not a pointer type.
Definition: type-traits.h:82
Null value type traits.
Definition: type-traits.h:43
Reference predicate.
Definition: type-traits.h:592
Base< U >::Type Type
Base type.
Definition: type-traits.h:138
Not a function pointer type.
Definition: type-traits.h:160
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Pointer to member predicate.
Definition: type-traits.h:586
Base type, after removing &, * and const.
Definition: type-traits.h:112
Not a reference type.
Definition: type-traits.h:64
Base type of a Ptr.
Definition: type-traits.h:144
UnConst< T >::Result NonConstType
Not a const type.
Definition: type-traits.h:574
FunctionPtrTraits< T > FunctionPointerTraits
Function pointer traits.
Definition: type-traits.h:599
Inspect a type to deduce its features.
Definition: type-traits.h:39
Function pointer predicate.
Definition: type-traits.h:594
U Result
Non-const type.
Definition: type-traits.h:50
PtrToMemberTraits< T > PointerToMemberTraits
Pointer to member traits type.
Definition: type-traits.h:597
Not a pointer to member type.
Definition: type-traits.h:297