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