- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Executives/DeductiveController/Configs/TI_DSP_BIOS/stl/type_traits.h

    00001 /*
    00002  *
    00003  * Copyright (c) 1997
    00004  * Silicon Graphics Computer Systems, Inc.
    00005  *
    00006  * Permission to use, copy, modify, distribute and sell this software
    00007  * and its documentation for any purpose is hereby granted without fee,
    00008  * provided that the above copyright notice appear in all copies and
    00009  * that both that copyright notice and this permission notice appear
    00010  * in supporting documentation.  Silicon Graphics makes no
    00011  * representations about the suitability of this software for any
    00012  * purpose.  It is provided "as is" without express or implied warranty.
    00013  */
    00014
    00015 #ifndef __TYPE_TRAITS_H
    00016 #define __TYPE_TRAITS_H
    00017
    00018 #ifndef __STL_CONFIG_H
    00019 #include <stl_config.h>
    00020 #endif
    00021
    00022 /*
    00023 This header file provides a framework for allowing compile time dispatch
    00024 based on type attributes. This is useful when writing template code.
    00025 For example, when making a copy of an array of an unknown type, it helps
    00026 to know if the type has a trivial copy constructor or not, to help decide
    00027 if a memcpy can be used.
    00028
    00029 The class template __type_traits provides a series of typedefs each of
    00030 which is either __true_type or __false_type. The argument to
    00031 __type_traits can be any type. The typedefs within this template will
    00032 attain their correct values by one of these means:
    00033     1. The general instantiation contain conservative values which work
    00034        for all types.
    00035     2. Specializations may be declared to make distinctions between types.
    00036     3. Some compilers (such as the Silicon Graphics N32 and N64 compilers)
    00037        will automatically provide the appropriate specializations for all
    00038        types.
    00039
    00040 EXAMPLE:
    00041
    00042 //Copy an array of elements which have non-trivial copy constructors
    00043 template <class T> void copy(T* source, T* destination, int n, __false_type);
    00044 //Copy an array of elements which have trivial copy constructors. Use memcpy.
    00045 template <class T> void copy(T* source, T* destination, int n, __true_type);
    00046
    00047 //Copy an array of any type by using the most efficient copy mechanism
    00048 template <class T> inline void copy(T* source,T* destination,int n) {
    00049    copy(source, destination, n,
    00050         typename __type_traits<T>::has_trivial_copy_constructor());
    00051 }
    00052 */
    00053
    00054
    00055 struct __true_type {
    00056 };
    00057
    00058 struct __false_type {
    00059 };
    00060
    00061 template <class _Tp>
    00062 struct __type_traits {
    00063    typedef __true_type     this_dummy_member_must_be_first;
    00064                    /* Do not remove this member. It informs a compiler which
    00065                       automatically specializes __type_traits that this
    00066                       __type_traits template is special. It just makes sure that
    00067                       things work if an implementation is using a template
    00068                       called __type_traits for something unrelated. */
    00069
    00070    /* The following restrictions should be observed for the sake of
    00071       compilers which automatically produce type specific specializations
    00072       of this class:
    00073           - You may reorder the members below if you wish
    00074           - You may remove any of the members below if you wish
    00075           - You must not rename members without making the corresponding
    00076             name change in the compiler
    00077           - Members you add will be treated like regular members unless
    00078             you add the appropriate support in the compiler. */
    00079
    00080
    00081    typedef __false_type    has_trivial_default_constructor;
    00082    typedef __false_type    has_trivial_copy_constructor;
    00083    typedef __false_type    has_trivial_assignment_operator;
    00084    typedef __false_type    has_trivial_destructor;
    00085    typedef __false_type    is_POD_type;
    00086 };
    00087
    00088
    00089
    00090 // Provide some specializations.  This is harmless for compilers that
    00091 //  have built-in __types_traits support, and essential for compilers
    00092 //  that don't.
    00093
    00094 #ifndef __STL_NO_BOOL
    00095
    00096 __STL_TEMPLATE_NULL struct __type_traits<bool> {
    00097    typedef __true_type    has_trivial_default_constructor;
    00098    typedef __true_type    has_trivial_copy_constructor;
    00099    typedef __true_type    has_trivial_assignment_operator;
    00100    typedef __true_type    has_trivial_destructor;
    00101    typedef __true_type    is_POD_type;
    00102 };
    00103
    00104 #endif /* __STL_NO_BOOL */
    00105
    00106 __STL_TEMPLATE_NULL struct __type_traits<char> {
    00107    typedef __true_type    has_trivial_default_constructor;
    00108    typedef __true_type    has_trivial_copy_constructor;
    00109    typedef __true_type    has_trivial_assignment_operator;
    00110    typedef __true_type    has_trivial_destructor;
    00111    typedef __true_type    is_POD_type;
    00112 };
    00113
    00114 __STL_TEMPLATE_NULL struct __type_traits<signed char> {
    00115    typedef __true_type    has_trivial_default_constructor;
    00116    typedef __true_type    has_trivial_copy_constructor;
    00117    typedef __true_type    has_trivial_assignment_operator;
    00118    typedef __true_type    has_trivial_destructor;
    00119    typedef __true_type    is_POD_type;
    00120 };
    00121
    00122 __STL_TEMPLATE_NULL struct __type_traits<unsigned char> {
    00123    typedef __true_type    has_trivial_default_constructor;
    00124    typedef __true_type    has_trivial_copy_constructor;
    00125    typedef __true_type    has_trivial_assignment_operator;
    00126    typedef __true_type    has_trivial_destructor;
    00127    typedef __true_type    is_POD_type;
    00128 };
    00129
    00130 #ifdef __STL_HAS_WCHAR_T
    00131
    00132 __STL_TEMPLATE_NULL struct __type_traits<wchar_t> {
    00133    typedef __true_type    has_trivial_default_constructor;
    00134    typedef __true_type    has_trivial_copy_constructor;
    00135    typedef __true_type    has_trivial_assignment_operator;
    00136    typedef __true_type    has_trivial_destructor;
    00137    typedef __true_type    is_POD_type;
    00138 };
    00139
    00140 #endif /* __STL_HAS_WCHAR_T */
    00141
    00142 __STL_TEMPLATE_NULL struct __type_traits<short> {
    00143    typedef __true_type    has_trivial_default_constructor;
    00144    typedef __true_type    has_trivial_copy_constructor;
    00145    typedef __true_type    has_trivial_assignment_operator;
    00146    typedef __true_type    has_trivial_destructor;
    00147    typedef __true_type    is_POD_type;
    00148 };
    00149
    00150 __STL_TEMPLATE_NULL struct __type_traits<unsigned short> {
    00151    typedef __true_type    has_trivial_default_constructor;
    00152    typedef __true_type    has_trivial_copy_constructor;
    00153    typedef __true_type    has_trivial_assignment_operator;
    00154    typedef __true_type    has_trivial_destructor;
    00155    typedef __true_type    is_POD_type;
    00156 };
    00157
    00158 __STL_TEMPLATE_NULL struct __type_traits<int> {
    00159    typedef __true_type    has_trivial_default_constructor;
    00160    typedef __true_type    has_trivial_copy_constructor;
    00161    typedef __true_type    has_trivial_assignment_operator;
    00162    typedef __true_type    has_trivial_destructor;
    00163    typedef __true_type    is_POD_type;
    00164 };
    00165
    00166 __STL_TEMPLATE_NULL struct __type_traits<unsigned int> {
    00167    typedef __true_type    has_trivial_default_constructor;
    00168    typedef __true_type    has_trivial_copy_constructor;
    00169    typedef __true_type    has_trivial_assignment_operator;
    00170    typedef __true_type    has_trivial_destructor;
    00171    typedef __true_type    is_POD_type;
    00172 };
    00173
    00174 __STL_TEMPLATE_NULL struct __type_traits<long> {
    00175    typedef __true_type    has_trivial_default_constructor;
    00176    typedef __true_type    has_trivial_copy_constructor;
    00177    typedef __true_type    has_trivial_assignment_operator;
    00178    typedef __true_type    has_trivial_destructor;
    00179    typedef __true_type    is_POD_type;
    00180 };
    00181
    00182 __STL_TEMPLATE_NULL struct __type_traits<unsigned long> {
    00183    typedef __true_type    has_trivial_default_constructor;
    00184    typedef __true_type    has_trivial_copy_constructor;
    00185    typedef __true_type    has_trivial_assignment_operator;
    00186    typedef __true_type    has_trivial_destructor;
    00187    typedef __true_type    is_POD_type;
    00188 };
    00189
    00190 #ifdef __STL_LONG_LONG
    00191
    00192 __STL_TEMPLATE_NULL struct __type_traits<long long> {
    00193    typedef __true_type    has_trivial_default_constructor;
    00194    typedef __true_type    has_trivial_copy_constructor;
    00195    typedef __true_type    has_trivial_assignment_operator;
    00196    typedef __true_type    has_trivial_destructor;
    00197    typedef __true_type    is_POD_type;
    00198 };
    00199
    00200 __STL_TEMPLATE_NULL struct __type_traits<unsigned long long> {
    00201    typedef __true_type    has_trivial_default_constructor;
    00202    typedef __true_type    has_trivial_copy_constructor;
    00203    typedef __true_type    has_trivial_assignment_operator;
    00204    typedef __true_type    has_trivial_destructor;
    00205    typedef __true_type    is_POD_type;
    00206 };
    00207
    00208 #endif /* __STL_LONG_LONG */
    00209
    00210 __STL_TEMPLATE_NULL struct __type_traits<float> {
    00211    typedef __true_type    has_trivial_default_constructor;
    00212    typedef __true_type    has_trivial_copy_constructor;
    00213    typedef __true_type    has_trivial_assignment_operator;
    00214    typedef __true_type    has_trivial_destructor;
    00215    typedef __true_type    is_POD_type;
    00216 };
    00217
    00218 __STL_TEMPLATE_NULL struct __type_traits<double> {
    00219    typedef __true_type    has_trivial_default_constructor;
    00220    typedef __true_type    has_trivial_copy_constructor;
    00221    typedef __true_type    has_trivial_assignment_operator;
    00222    typedef __true_type    has_trivial_destructor;
    00223    typedef __true_type    is_POD_type;
    00224 };
    00225
    00226 __STL_TEMPLATE_NULL struct __type_traits<long double> {
    00227    typedef __true_type    has_trivial_default_constructor;
    00228    typedef __true_type    has_trivial_copy_constructor;
    00229    typedef __true_type    has_trivial_assignment_operator;
    00230    typedef __true_type    has_trivial_destructor;
    00231    typedef __true_type    is_POD_type;
    00232 };
    00233
    00234 #ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
    00235
    00236 template <class _Tp>
    00237 struct __type_traits<_Tp*> {
    00238    typedef __true_type    has_trivial_default_constructor;
    00239    typedef __true_type    has_trivial_copy_constructor;
    00240    typedef __true_type    has_trivial_assignment_operator;
    00241    typedef __true_type    has_trivial_destructor;
    00242    typedef __true_type    is_POD_type;
    00243 };
    00244
    00245 #else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
    00246
    00247 __STL_TEMPLATE_NULL struct __type_traits<char*> {
    00248    typedef __true_type    has_trivial_default_constructor;
    00249    typedef __true_type    has_trivial_copy_constructor;
    00250    typedef __true_type    has_trivial_assignment_operator;
    00251    typedef __true_type    has_trivial_destructor;
    00252    typedef __true_type    is_POD_type;
    00253 };
    00254
    00255 __STL_TEMPLATE_NULL struct __type_traits<signed char*> {
    00256    typedef __true_type    has_trivial_default_constructor;
    00257    typedef __true_type    has_trivial_copy_constructor;
    00258    typedef __true_type    has_trivial_assignment_operator;
    00259    typedef __true_type    has_trivial_destructor;
    00260    typedef __true_type    is_POD_type;
    00261 };
    00262
    00263 __STL_TEMPLATE_NULL struct __type_traits<unsigned char*> {
    00264    typedef __true_type    has_trivial_default_constructor;
    00265    typedef __true_type    has_trivial_copy_constructor;
    00266    typedef __true_type    has_trivial_assignment_operator;
    00267    typedef __true_type    has_trivial_destructor;
    00268    typedef __true_type    is_POD_type;
    00269 };
    00270
    00271 __STL_TEMPLATE_NULL struct __type_traits<const char*> {
    00272    typedef __true_type    has_trivial_default_constructor;
    00273    typedef __true_type    has_trivial_copy_constructor;
    00274    typedef __true_type    has_trivial_assignment_operator;
    00275    typedef __true_type    has_trivial_destructor;
    00276    typedef __true_type    is_POD_type;
    00277 };
    00278
    00279 __STL_TEMPLATE_NULL struct __type_traits<const signed char*> {
    00280    typedef __true_type    has_trivial_default_constructor;
    00281    typedef __true_type    has_trivial_copy_constructor;
    00282    typedef __true_type    has_trivial_assignment_operator;
    00283    typedef __true_type    has_trivial_destructor;
    00284    typedef __true_type    is_POD_type;
    00285 };
    00286
    00287 __STL_TEMPLATE_NULL struct __type_traits<const unsigned char*> {
    00288    typedef __true_type    has_trivial_default_constructor;
    00289    typedef __true_type    has_trivial_copy_constructor;
    00290    typedef __true_type    has_trivial_assignment_operator;
    00291    typedef __true_type    has_trivial_destructor;
    00292    typedef __true_type    is_POD_type;
    00293 };
    00294
    00295 #endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
    00296
    00297
    00298 // The following could be written in terms of numeric_limits.
    00299 // We're doing it separately to reduce the number of dependencies.
    00300
    00301 template <class _Tp> struct _Is_integer {
    00302   typedef __false_type _Integral;
    00303 };
    00304
    00305 #ifndef __STL_NO_BOOL
    00306
    00307 __STL_TEMPLATE_NULL struct _Is_integer<bool> {
    00308   typedef __true_type _Integral;
    00309 };
    00310
    00311 #endif /* __STL_NO_BOOL */
    00312
    00313 __STL_TEMPLATE_NULL struct _Is_integer<char> {
    00314   typedef __true_type _Integral;
    00315 };
    00316
    00317 __STL_TEMPLATE_NULL struct _Is_integer<signed char> {
    00318   typedef __true_type _Integral;
    00319 };
    00320
    00321 __STL_TEMPLATE_NULL struct _Is_integer<unsigned char> {
    00322   typedef __true_type _Integral;
    00323 };
    00324
    00325 #ifdef __STL_HAS_WCHAR_T
    00326
    00327 __STL_TEMPLATE_NULL struct _Is_integer<wchar_t> {
    00328   typedef __true_type _Integral;
    00329 };
    00330
    00331 #endif /* __STL_HAS_WCHAR_T */
    00332
    00333 __STL_TEMPLATE_NULL struct _Is_integer<short> {
    00334   typedef __true_type _Integral;
    00335 };
    00336
    00337 __STL_TEMPLATE_NULL struct _Is_integer<unsigned short> {
    00338   typedef __true_type _Integral;
    00339 };
    00340
    00341 __STL_TEMPLATE_NULL struct _Is_integer<int> {
    00342   typedef __true_type _Integral;
    00343 };
    00344
    00345 __STL_TEMPLATE_NULL struct _Is_integer<unsigned int> {
    00346   typedef __true_type _Integral;
    00347 };
    00348
    00349 __STL_TEMPLATE_NULL struct _Is_integer<long> {
    00350   typedef __true_type _Integral;
    00351 };
    00352
    00353 __STL_TEMPLATE_NULL struct _Is_integer<unsigned long> {
    00354   typedef __true_type _Integral;
    00355 };
    00356
    00357 #ifdef __STL_LONG_LONG
    00358
    00359 __STL_TEMPLATE_NULL struct _Is_integer<long long> {
    00360   typedef __true_type _Integral;
    00361 };
    00362
    00363 __STL_TEMPLATE_NULL struct _Is_integer<unsigned long long> {
    00364   typedef __true_type _Integral;
    00365 };
    00366
    00367 #endif /* __STL_LONG_LONG */
    00368
    00369 #endif /* __TYPE_TRAITS_H */
    00370
    00371 // Local Variables:
    00372 // mode:C++
    00373 // End: