type_traits.hpp

Go to the documentation of this file.
00001 #ifndef s11n_net_S11N_TYPE_INFO_HPP_INCLUDED
00002 #define s11n_net_S11N_TYPE_INFO_HPP_INCLUDED
00003 ////////////////////////////////////////////////////////////////////////
00004 // type_info.hpp
00005 // A very basic set of typeinfo traits types.
00006 // Author: stephan@s11n.net, based off of much prior art
00007 // License: Public Domain
00008 ////////////////////////////////////////////////////////////////////////
00009 
00010 namespace s11n
00011 {
00012 
00013     /**
00014        A base type for type_traits. No code should use this class
00015        directly, except to subclass it.
00016     */
00017     template < typename T, bool IsConst, bool IsPointer, bool IsReference >
00018     struct type_traits_base
00019     {
00020         /** Same as (T). */
00021         typedef T type;
00022         /** Same as (T*). **/
00023         typedef T * pointer;
00024         /** Same as (T&). **/
00025         typedef T & reference;
00026         /** True if T is a const type, else false. */
00027         static const bool is_const_type = IsConst;
00028         /** True if T is a pointer type, else false. */
00029         static const bool is_pointer_type = IsPointer;
00030         /** True if T is a reference type, else false. */
00031         static const bool is_reference_type = IsReference;
00032     };
00033 
00034 
00035     /**
00036        A simple type traits container. All of its typedefs are
00037        documented in the parent type.
00038     */
00039     template < typename T >
00040     struct type_traits : public type_traits_base<T,false,false,false>
00041     {
00042         typedef T type;
00043         typedef T * pointer;
00044         typedef T & reference;
00045     };
00046 
00047 
00048     /** Specialization for (const T). */
00049     template < typename T >
00050     struct type_traits< const T > : public type_traits_base<T,true,false,false>
00051     {
00052         typedef T type;
00053         typedef T * pointer;
00054         typedef T & reference;
00055     };
00056 
00057 
00058 
00059     /** Specialization for (T &). */
00060     template < typename T >
00061     struct type_traits< T & > : public type_traits_base<T,false,false,true>
00062     {
00063         typedef T type;
00064         typedef T * pointer;
00065         typedef T & reference;
00066     };
00067 
00068     /** Specialization for (const T &). */
00069     template < typename T >
00070     struct type_traits< const T & > : public type_traits_base<T,true,false,true>
00071     {
00072         typedef T type;
00073         typedef T * pointer;
00074         typedef T & reference;
00075     };
00076 
00077 
00078     /** Specialization for (T *). */
00079     template < typename T >
00080     struct type_traits< T * > : public type_traits_base<T,false,true,false>
00081     {
00082         typedef T type;
00083         typedef T * pointer;
00084         typedef T & reference;
00085     };
00086 
00087 
00088     /** Specialization for (const T *). */
00089     template < typename T >
00090     struct type_traits< const T * > : public type_traits_base<T,true,true,false>
00091     {
00092         typedef T type;
00093         typedef T * pointer;
00094         typedef T & reference;
00095     };
00096 
00097 } // namespace
00098 
00099 #endif // s11n_net_S11N_TYPE_INFO_HPP_INCLUDED
00100 

Generated on Thu Feb 8 10:25:27 2007 for libs11n-1.2.5 by  doxygen 1.5.0