![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /******************************************************************************* 00002 * This file is part of openWNS (open Wireless Network Simulator) 00003 * _____________________________________________________________________________ 00004 * 00005 * Copyright (C) 2004-2007 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 5, D-52074 Aachen, Germany 00008 * phone: ++49-241-80-27910, 00009 * fax: ++49-241-80-22242 00010 * email: info@openwns.org 00011 * www: http://www.openwns.org 00012 * _____________________________________________________________________________ 00013 * 00014 * openWNS is free software; you can redistribute it and/or modify it under the 00015 * terms of the GNU Lesser General Public License version 2 as published by the 00016 * Free Software Foundation; 00017 * 00018 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00020 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00021 * details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public License 00024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00025 * 00026 ******************************************************************************/ 00027 00028 #ifndef WNS_TYPETRAITS_HPP 00029 #define WNS_TYPETRAITS_HPP 00030 00031 #include <WNS/TypeInfo.hpp> 00032 00033 namespace wns { 00037 template <typename T> 00038 class TypeTraits 00039 { 00040 private: 00041 template <class U> 00042 struct PointerTraits 00043 { 00044 enum 00045 { 00046 result = 0 00047 }; 00048 typedef NullType PointeeType; 00049 }; 00050 template <class U> 00051 struct PointerTraits<U*> 00052 { 00053 enum 00054 { 00055 result = 1 00056 }; 00057 typedef U PointeeType; 00058 }; 00059 00060 template <class U> 00061 struct ReferenceTraits 00062 { 00063 enum 00064 { 00065 result = 0 00066 }; 00067 typedef NullType ReferenceType; 00068 }; 00069 template <class U> 00070 struct ReferenceTraits<U&> 00071 { 00072 enum 00073 { 00074 result = 1 00075 }; 00076 typedef U ReferenceType; 00077 }; 00078 00079 template <class U> 00080 struct ConstTraits 00081 { 00082 enum 00083 { 00084 result = 0 00085 }; 00086 typedef NullType ConstType; 00087 }; 00088 template <class U> 00089 struct ConstTraits<const U> 00090 { 00091 enum 00092 { 00093 result = 1 00094 }; 00095 typedef U ConstType; 00096 }; 00097 00098 // The following ConstTraits shouldn't be necessary, but somehow g++ 00099 // doesn't figure out the correct type ... 00100 template <class U> 00101 struct ConstTraits<const U*> 00102 { 00103 enum 00104 { 00105 result = 1 00106 }; 00107 typedef U ConstType; 00108 }; 00109 template <class U> 00110 struct ConstTraits<U&> 00111 { 00112 enum 00113 { 00114 result = 0 00115 }; 00116 typedef U ConstType; 00117 }; 00118 template <class U> 00119 struct ConstTraits<const U&> 00120 { 00121 enum 00122 { 00123 result = 1 00124 }; 00125 typedef U ConstType; 00126 }; 00127 00128 public: 00132 enum 00133 { 00134 isPointer = PointerTraits<T>::result 00135 }; 00136 typedef typename PointerTraits<T>::PointeeType PointeeType; 00137 00141 enum 00142 { 00143 isReference = ReferenceTraits<T>::result 00144 }; 00145 typedef typename ReferenceTraits<T>::ReferenceType ReferenceType; 00146 00150 enum 00151 { 00152 isConst = ConstTraits<T>::result 00153 }; 00154 typedef typename ConstTraits<T>::ConstType ConstType; 00155 00159 enum 00160 { 00161 propNumber = 4*isPointer + 2*isReference + 1*isConst 00162 }; 00163 00167 enum 00168 { 00169 Plain = 0, 00170 Const = 1, 00171 Reference = 2, 00172 ConstReference = 3, 00173 Pointer = 4, 00174 ConstPointer = 5 00175 }; 00176 }; 00177 } 00178 00179 #endif // NOT defined WNS_TYPETRAITS_HPP
1.5.5