00001
00002
00003 #ifndef AITOOLS_VALUE_PAIR_TRAITS_HPP
00004 #define AITOOLS_VALUE_PAIR_TRAITS_HPP
00005
00006 #include "value/pair.hpp"
00007 #include "value/value_traits.hpp"
00008
00009 namespace aitools {
00010 namespace value {
00011
00012
00013
00014
00015
00016 template <typename T1, typename T2>
00017 struct value_traits<pair<T1, T2> >
00018 {
00019 typedef pair<T1, T2> value_type;
00020 typedef uint16_t io_size_type;
00021
00022 static size_t
00023 size_of(const value_type& pair)
00024 {
00025 return
00026 value_traits<T1>::size_of(pair.e1()) +
00027 value_traits<T2>::size_of(pair.e2());
00028 }
00029
00030 static char*
00031 copy_to(const value_type& pair, char* buffer)
00032 {
00033 buffer = value_traits<T1>::copy_to(pair.e1(), buffer);
00034 return value_traits<T2>::copy_to(pair.e2(), buffer);
00035 }
00036
00037 static const char*
00038 copy_from(value_type& pair, const char* buffer)
00039 {
00040 buffer = value_traits<T1>::copy_from(pair.e1(), buffer);
00041 return value_traits<T2>::copy_from(pair.e2(), buffer);
00042 }
00043
00044 static bool
00045 write_to(const value_type& pair, FILE* file)
00046 {
00047 return
00048 value_traits<T1>::write_to(pair.e1(), file) &&
00049 value_traits<T2>::write_to(pair.e2(), file);
00050 }
00051
00052 static bool
00053 read_from(value_type& pair, FILE* file)
00054 {
00055 return
00056 value_traits<T1>::read_from(pair.e1(), file) &&
00057 value_traits<T2>::read_from(pair.e2(), file);
00058 }
00059
00060 static bool
00061 print_to(const value_type& pair, std::ostream& os)
00062 {
00063 return
00064 value_traits<T1>::print_to(pair.e1(), os) &&
00065 (os << ' ') &&
00066 value_traits<T2>::print_to(pair.e2(), os);
00067 }
00068
00069 static bool
00070 println_to(const value_type& pair, std::ostream& os)
00071 {
00072
00073 return print_to(pair, os) && (os << '\n');
00074 }
00075
00076 static bool
00077 parse_from(value_type& pair, std::istream& is)
00078 {
00079 return
00080 value_traits<T1>::parse_from(pair.e1(), is) &&
00081 value_traits<T2>::parse_from(pair.e2(), is);
00082 }
00083
00084 static std::string
00085 type_name()
00086 {
00087 std::string name("pair<");
00088 name += value_traits<T1>::type_name();
00089 name += ", ";
00090 name += value_traits<T2>::type_name();
00091 name += '>';
00092 return name;
00093 }
00094 };
00095
00096
00097
00098
00099
00100 template <typename T1, typename T2>
00101 std::ostream&
00102 operator<<(std::ostream& os, const pair<T1, T2>& value)
00103 {
00104 if (os) value_traits<pair<T1, T2> >::print_to(value, os);
00105 return os;
00106 }
00107
00108 }
00109
00110 using value::value_traits;
00111
00112 }
00113
00114 #endif // AITOOLS_VALUE_PAIR_TRAITS_HPP