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