00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #ifndef XIMOL_TRAITS_HPP_
00046 #define XIMOL_TRAITS_HPP_
00047
00048 #include <iosfwd>
00049
00050
00051 XIMOL_BEGIN_NAMESPACE
00052
00053 namespace private_detail_about_traits
00054 {
00055 typedef char yes;
00056 struct no { char dummy[2]; };
00057
00058 template <typename T>
00059 struct make { static T& type(); };
00060
00061 template <typename U>
00062 struct is
00063 {
00064 static no type(...);
00065 static yes type(U);
00066 };
00067
00068 struct does_not_exist { char dummy[17]; };
00069 template < typename T, typename U> does_not_exist operator<<(T&,U&);
00070 template < typename T, typename U> does_not_exist operator>>(T&,U&);
00071 template<typename T>
00072 T& insert_in_nslookup(T&,does_not_exist&);
00073
00074 template < typename T, typename U>
00075 struct has_inserter
00076 {
00077 enum { value= (sizeof(is<does_not_exist>::type(operator<<(insert_in_nslookup(make<T>::type(),make<does_not_exist>::type()),make<U>::type()))) == sizeof(no)) };
00078 };
00079
00080 template < typename T, typename U>
00081 struct has_extractor
00082 {
00083 enum { value= (sizeof(is<does_not_exist>::type(operator>>(insert_in_nslookup(make<T>::type(),make<does_not_exist>::type()),make<U>::type()))) == sizeof(no)) };
00084 };
00085 };
00086
00087 template < typename Stream, typename Object >
00088 struct stream_and_object_traits
00089 {
00090 enum { is_extractible = private_detail_about_traits::has_extractor<Stream,Object>::value };
00091 enum { is_insertible = private_detail_about_traits::has_inserter<Stream,Object>::value };
00092 };
00093
00094 #define XIMOL_TRAITS_STANDARD_OSTREAM(type) template <> struct stream_and_object_traits< ::std::ostream, type> { enum { is_extractible = false }; enum { is_insertible = true }; };
00095 #define XIMOL_TRAITS_STANDARD_WOSTREAM(type) template <> struct stream_and_object_traits< ::std::wostream, type> { enum { is_extractible = false }; enum { is_insertible = true }; };
00096 #define XIMOL_TRAITS_STANDARD_ISTREAM(type) template <> struct stream_and_object_traits< ::std::istream, type> { enum { is_extractible = true }; enum { is_insertible = false }; };
00097 #define XIMOL_TRAITS_STANDARD_WISTREAM(type) template <> struct stream_and_object_traits< ::std::wistream, type> { enum { is_extractible = true }; enum { is_insertible = false }; };
00098
00099 #define XIMOL_TRAITS_STANDARD(type) XIMOL_TRAITS_STANDARD_OSTREAM(type) XIMOL_TRAITS_STANDARD_WOSTREAM(type) XIMOL_TRAITS_STANDARD_ISTREAM(type) XIMOL_TRAITS_STANDARD_WISTREAM(type)
00100
00101 XIMOL_TRAITS_STANDARD(bool )
00102 XIMOL_TRAITS_STANDARD(short )
00103 XIMOL_TRAITS_STANDARD(long )
00104 XIMOL_TRAITS_STANDARD(unsigned long )
00105 XIMOL_TRAITS_STANDARD(int )
00106 XIMOL_TRAITS_STANDARD(unsigned int )
00107 XIMOL_TRAITS_STANDARD(float )
00108 XIMOL_TRAITS_STANDARD(double )
00109 XIMOL_TRAITS_STANDARD(long double )
00110
00111 XIMOL_END_NAMESPACE
00112
00113 #endif // #ifndef XIMOL_TRAITS_HPP_