A Discrete-Event Network Simulator
API
type-traits.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  */
18 
19 #ifndef TYPE_TRAITS_H
20 #define TYPE_TRAITS_H
21 
22 #include "ptr.h"
23 
30 namespace ns3
31 {
32 
38 template <typename T>
39 struct TypeTraits
40 {
41  private:
43  struct NullType
44  {
45  };
46 
51  template <typename U>
52  struct UnConst
53  {
54  typedef U Result;
55  };
56 
61  template <typename U>
62  struct UnConst<const U>
63  {
64  typedef U Result;
65  };
66 
71  template <typename U>
73  {
75  enum
76  {
77  IsReference = 0
78  };
79 
80  typedef U ReferencedType;
81  };
82 
87  template <typename U>
88  struct ReferenceTraits<U&>
89  {
91  enum
92  {
93  IsReference = 1
94  };
95 
96  typedef U ReferencedType;
97  };
98 
103  template <typename U>
105  {
107  enum
108  {
109  IsPointer = 0,
110  IsPtr = 0
111  };
112 
113  typedef U PointeeType;
114  };
115 
120  template <typename U>
121  struct PointerTraits<U*>
122  {
124  enum
125  {
126  IsPointer = 1,
127  IsPtr = 0
128  };
129 
130  typedef U PointeeType;
131  };
132 
137  template <typename U>
138  struct PointerTraits<ns3::Ptr<U>>
139  {
141  enum
142  {
143  IsPointer = 0,
144  IsPtr = 1
145  };
146 
147  typedef U PointeeType;
148  };
149 
154  template <typename U>
155  struct Base
156  {
157  typedef U Type;
158  };
159 
164  template <typename U>
165  struct Base<U&>
166  {
167  typedef typename Base<U>::Type Type;
168  };
169 
174  template <typename U>
175  struct Base<U*>
176  {
177  typedef typename Base<U>::Type Type;
178  };
179 
184  template <typename U>
185  struct Base<const U>
186  {
187  typedef typename Base<U>::Type Type;
188  };
189 
194  template <typename U>
195  struct PtrBase
196  {
197  typedef U Type;
198  };
199 
204  template <typename U>
205  struct PtrBase<ns3::Ptr<U>>
206  {
207  typedef U Type;
208  };
209 
214  template <typename U>
216  {
218  enum
219  {
220  IsFunctionPointer = 0
221  };
222 
224  };
225 
230  template <typename U>
231  struct FunctionPtrTraits<U (*)()>
232  {
234  enum
235  {
236  IsFunctionPointer = 1
237  };
238  enum
240  {
241  nArgs = 0
242  };
243 
244  typedef U ReturnType;
245  };
246 
252  template <typename U, typename V1>
253  struct FunctionPtrTraits<U (*)(V1)>
254  {
256  enum
257  {
258  IsFunctionPointer = 1
259  };
260  enum
262  {
263  nArgs = 1
264  };
265 
266  typedef U ReturnType;
267  typedef V1 Arg1Type;
268  };
269 
276  template <typename U, typename V1, typename V2>
277  struct FunctionPtrTraits<U (*)(V1, V2)>
278  {
280  enum
281  {
282  IsFunctionPointer = 1
283  };
284  enum
286  {
287  nArgs = 2
288  };
289 
290  typedef U ReturnType;
291  typedef V1 Arg1Type;
292  typedef V2 Arg2Type;
293  };
294 
302  template <typename U, typename V1, typename V2, typename V3>
303  struct FunctionPtrTraits<U (*)(V1, V2, V3)>
304  {
306  enum
307  {
308  IsFunctionPointer = 1
309  };
310  enum
312  {
313  nArgs = 3
314  };
315 
316  typedef U ReturnType;
317  typedef V1 Arg1Type;
318  typedef V2 Arg2Type;
319  typedef V3 Arg3Type;
320  };
321 
330  template <typename U, typename V1, typename V2, typename V3, typename V4>
331  struct FunctionPtrTraits<U (*)(V1, V2, V3, V4)>
332  {
334  enum
335  {
336  IsFunctionPointer = 1
337  };
338  enum
340  {
341  nArgs = 4
342  };
343 
344  typedef U ReturnType;
345  typedef V1 Arg1Type;
346  typedef V2 Arg2Type;
347  typedef V3 Arg3Type;
348  typedef V4 Arg4Type;
349  };
350 
360  template <typename U, typename V1, typename V2, typename V3, typename V4, typename V5>
361  struct FunctionPtrTraits<U (*)(V1, V2, V3, V4, V5)>
362  {
364  enum
365  {
366  IsFunctionPointer = 1
367  };
368  enum
370  {
371  nArgs = 5
372  };
373 
374  typedef U ReturnType;
375  typedef V1 Arg1Type;
376  typedef V2 Arg2Type;
377  typedef V3 Arg3Type;
378  typedef V4 Arg4Type;
379  typedef V5 Arg5Type;
380  };
381 
392  template <typename U,
393  typename V1,
394  typename V2,
395  typename V3,
396  typename V4,
397  typename V5,
398  typename V6>
399  struct FunctionPtrTraits<U (*)(V1, V2, V3, V4, V5, V6)>
400  {
402  enum
403  {
404  IsFunctionPointer = 1
405  };
406  enum
408  {
409  nArgs = 6
410  };
411 
412  typedef U ReturnType;
413  typedef V1 Arg1Type;
414  typedef V2 Arg2Type;
415  typedef V3 Arg3Type;
416  typedef V4 Arg4Type;
417  typedef V5 Arg5Type;
418  typedef V6 Arg6Type;
419  };
420 
425  template <typename U>
427  {
429  enum
430  {
431  IsPointerToMember = 0
432  };
433  };
434 
440  template <typename U, typename V>
441  struct PtrToMemberTraits<U (V::*)()>
442  {
444  enum
445  {
446  IsPointerToMember = 1
447  };
448  enum
450  {
451  nArgs = 0
452  };
453 
454  typedef U ReturnType;
455  };
456 
462  template <typename U, typename V>
463  struct PtrToMemberTraits<U (V::*)() const>
464  {
466  enum
467  {
468  IsPointerToMember = 1
469  };
470  enum
472  {
473  nArgs = 0
474  };
475 
476  typedef U ReturnType;
477  };
478 
485  template <typename U, typename V, typename W1>
486  struct PtrToMemberTraits<U (V::*)(W1)>
487  {
489  enum
490  {
491  IsPointerToMember = 1
492  };
493  enum
495  {
496  nArgs = 1
497  };
498 
499  typedef U ReturnType;
500  typedef W1 Arg1Type;
501  };
502 
509  template <typename U, typename V, typename W1>
510  struct PtrToMemberTraits<U (V::*)(W1) const>
511  {
513  enum
514  {
515  IsPointerToMember = 1
516  };
517  enum
519  {
520  nArgs = 1
521  };
522 
523  typedef U ReturnType;
524  typedef W1 Arg1Type;
525  };
526 
534  template <typename U, typename V, typename W1, typename W2>
535  struct PtrToMemberTraits<U (V::*)(W1, W2)>
536  {
538  enum
539  {
540  IsPointerToMember = 1
541  };
542  enum
544  {
545  nArgs = 2
546  };
547 
548  typedef U ReturnType;
549  typedef W1 Arg1Type;
550  typedef W2 Arg2Type;
551  };
552 
560  template <typename U, typename V, typename W1, typename W2>
561  struct PtrToMemberTraits<U (V::*)(W1, W2) const>
562  {
564  enum
565  {
566  IsPointerToMember = 1
567  };
568  enum
570  {
571  nArgs = 2
572  };
573 
574  typedef U ReturnType;
575  typedef W1 Arg1Type;
576  typedef W2 Arg2Type;
577  };
578 
587  template <typename U, typename V, typename W1, typename W2, typename W3>
588  struct PtrToMemberTraits<U (V::*)(W1, W2, W3)>
589  {
591  enum
592  {
593  IsPointerToMember = 1
594  };
595  enum
597  {
598  nArgs = 3
599  };
600 
601  typedef U ReturnType;
602  typedef W1 Arg1Type;
603  typedef W2 Arg2Type;
604  typedef W3 Arg3Type;
605  };
606 
615  template <typename U, typename V, typename W1, typename W2, typename W3>
616  struct PtrToMemberTraits<U (V::*)(W1, W2, W3) const>
617  {
619  enum
620  {
621  IsPointerToMember = 1
622  };
623  enum
625  {
626  nArgs = 3
627  };
628 
629  typedef U ReturnType;
630  typedef W1 Arg1Type;
631  typedef W2 Arg2Type;
632  typedef W3 Arg3Type;
633  };
634 
644  template <typename U, typename V, typename W1, typename W2, typename W3, typename W4>
645  struct PtrToMemberTraits<U (V::*)(W1, W2, W3, W4)>
646  {
648  enum
649  {
650  IsPointerToMember = 1
651  };
652  enum
654  {
655  nArgs = 4
656  };
657 
658  typedef U ReturnType;
659  typedef W1 Arg1Type;
660  typedef W2 Arg2Type;
661  typedef W3 Arg3Type;
662  typedef W4 Arg4Type;
663  };
664 
674  template <typename U, typename V, typename W1, typename W2, typename W3, typename W4>
675  struct PtrToMemberTraits<U (V::*)(W1, W2, W3, W4) const>
676  {
678  enum
679  {
680  IsPointerToMember = 1
681  };
682  enum
684  {
685  nArgs = 4
686  };
687 
688  typedef U ReturnType;
689  typedef W1 Arg1Type;
690  typedef W2 Arg2Type;
691  typedef W3 Arg3Type;
692  typedef W4 Arg4Type;
693  };
694 
705  template <typename U,
706  typename V,
707  typename W1,
708  typename W2,
709  typename W3,
710  typename W4,
711  typename W5>
712  struct PtrToMemberTraits<U (V::*)(W1, W2, W3, W4, W5)>
713  {
715  enum
716  {
717  IsPointerToMember = 1
718  };
719  enum
721  {
722  nArgs = 5
723  };
724 
725  typedef U ReturnType;
726  typedef W1 Arg1Type;
727  typedef W2 Arg2Type;
728  typedef W3 Arg3Type;
729  typedef W4 Arg4Type;
730  typedef W5 Arg5Type;
731  };
732 
743  template <typename U,
744  typename V,
745  typename W1,
746  typename W2,
747  typename W3,
748  typename W4,
749  typename W5>
750  struct PtrToMemberTraits<U (V::*)(W1, W2, W3, W4, W5) const>
751  {
753  enum
754  {
755  IsPointerToMember = 1
756  };
757  enum
759  {
760  nArgs = 5
761  };
762 
763  typedef U ReturnType;
764  typedef W1 Arg1Type;
765  typedef W2 Arg2Type;
766  typedef W3 Arg3Type;
767  typedef W4 Arg4Type;
768  typedef W5 Arg5Type;
769  };
770 
782  template <typename U,
783  typename V,
784  typename W1,
785  typename W2,
786  typename W3,
787  typename W4,
788  typename W5,
789  typename W6>
790  struct PtrToMemberTraits<U (V::*)(W1, W2, W3, W4, W5, W6)>
791  {
793  enum
794  {
795  IsPointerToMember = 1
796  };
797  enum
799  {
800  nArgs = 6
801  };
802 
803  typedef U ReturnType;
804  typedef W1 Arg1Type;
805  typedef W2 Arg2Type;
806  typedef W3 Arg3Type;
807  typedef W4 Arg4Type;
808  typedef W5 Arg5Type;
809  typedef W6 Arg6Type;
810  };
811 
823  template <typename U,
824  typename V,
825  typename W1,
826  typename W2,
827  typename W3,
828  typename W4,
829  typename W5,
830  typename W6>
831  struct PtrToMemberTraits<U (V::*)(W1, W2, W3, W4, W5, W6) const>
832  {
834  enum
835  {
836  IsPointerToMember = 1
837  };
838  enum
840  {
841  nArgs = 6
842  };
843 
844  typedef U ReturnType;
845  typedef W1 Arg1Type;
846  typedef W2 Arg2Type;
847  typedef W3 Arg3Type;
848  typedef W4 Arg4Type;
849  typedef W5 Arg5Type;
850  typedef W6 Arg6Type;
851  };
852 
853  public:
861  typedef typename Base<T>::Type BaseType;
863  typedef typename PtrBase<T>::Type PtrBaseType;
864 
866  enum
867  {
878  };
879 
884 };
885 
886 } // namespace ns3
887 
888 #endif /* TYPE_TRAITS_H */
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Ptr smart pointer declaration and implementation.
Base< U >::Type Type
Base type.
Definition: type-traits.h:177
Base< U >::Type Type
Base type.
Definition: type-traits.h:167
Base< U >::Type Type
Base type.
Definition: type-traits.h:187
Base type, after removing &, * and const.
Definition: type-traits.h:156
Not a function pointer type.
Definition: type-traits.h:216
NullType ReturnType
Return type.
Definition: type-traits.h:223
@ IsFunctionPointer
Not a function pointer.
Definition: type-traits.h:220
Null value type traits.
Definition: type-traits.h:44
@ IsPointer
Not a pointer type.
Definition: type-traits.h:109
Base type of a Ptr.
Definition: type-traits.h:196
Not a pointer to member type.
Definition: type-traits.h:427
@ IsPointerToMember
Not a pointer to member.
Definition: type-traits.h:431
Not a reference type.
Definition: type-traits.h:73
@ IsReference
Not a reference type.
Definition: type-traits.h:77
Not a const type.
Definition: type-traits.h:53
U Result
Non-const type.
Definition: type-traits.h:54
Inspect a type to deduce its features.
Definition: type-traits.h:40
ReferenceTraits< T >::ReferencedType ReferencedType
Referenced type.
Definition: type-traits.h:857
PtrToMemberTraits< T > PointerToMemberTraits
Pointer to member traits type.
Definition: type-traits.h:881
PtrBase< T >::Type PtrBaseType
Ptr base type.
Definition: type-traits.h:863
FunctionPtrTraits< T > FunctionPointerTraits
Function pointer traits.
Definition: type-traits.h:883
@ IsPtr
Ptr predicate.
Definition: type-traits.h:873
@ IsFunctionPointer
Function pointer predicate.
Definition: type-traits.h:877
@ IsPointerToMember
Pointer to member predicate.
Definition: type-traits.h:869
@ IsReference
Reference predicate.
Definition: type-traits.h:875
@ IsPointer
Pointer predicate.
Definition: type-traits.h:871
Base< T >::Type BaseType
Base type, after removing &, * and const.
Definition: type-traits.h:861
PointerTraits< T >::PointeeType PointeeType
Pointee type.
Definition: type-traits.h:859
UnConst< T >::Result NonConstType
Not a const type.
Definition: type-traits.h:855