00001 #ifndef GRAL_GB_SEQUENCE_SEQUENCE_IO_H
00002 #define GRAL_GB_SEQUENCE_SEQUENCE_IO_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "Utility/ref-ptr.h"
00019
00020 #include <iostream>
00021
00022 namespace GrAL {
00023
00050 \endcode
00051 */
00052
00061 template<class C>
00062 class sequence_io_helper {
00063 private:
00064 GrAL::ref_ptr<C> cont;
00065 public:
00066 sequence_io_helper() {}
00067 sequence_io_helper(C & c) : cont(c) {}
00068 sequence_io_helper(GrAL::ref_ptr<C> c) : cont(c) {}
00069
00070 void read(std::istream& in) {
00071 int n;
00072 in >> n;
00073 for(int i = 0; i < n; ++i) {
00074 typename C::value_type t;
00075 bool good = (in >> t);
00076 REQUIRE_ALWAYS(good, "could not read item " << i << " of " << n, 1);
00077 cont->push_back(t);
00078 }
00079 }
00080 void write(std::ostream& out) {
00081 out << cont->size();
00082 for(typename C::const_iterator i = cont->begin(); i != cont->end(); ++i)
00083 out << " " << *i;
00084 }
00085 };
00086
00091 template<class C>
00092 inline std::istream& operator>>(std::istream& in, sequence_io_helper<C> s)
00093 { s.read(in); return in;}
00094
00098 template<class C>
00099 inline std::ostream& operator<<(std::ostream& out, sequence_io_helper<C> s)
00100 { s.write(out); return out;}
00101
00105 template<class C>
00106 inline sequence_io_helper<C> sequence_io(C & c) { return sequence_io_helper<C>(c);}
00110 template<class C>
00111 inline sequence_io_helper<C> sequence_io(ref_ptr<C> c) { return sequence_io_helper<C>(c);}
00112
00113 }
00114
00115
00116
00117 #endif
00118