00001
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
00034
00035 #ifndef GROOVX_IO_READUTILS_H_UTC20050626084021_DEFINED
00036 #define GROOVX_IO_READUTILS_H_UTC20050626084021_DEFINED
00037
00038 #include "io/reader.h"
00039
00040 #include "nub/ref.h"
00041
00042 #include "rutz/error.h"
00043
00044 namespace io
00045 {
00047 namespace read_utils
00048 {
00049 rutz::fstring make_element_name(const rutz::fstring& seq_name,
00050 int element_num);
00051
00052 rutz::fstring make_seq_length_name(const rutz::fstring& seq_name);
00053
00055 inline int read_sequence_length(io::reader& reader,
00056 const rutz::fstring& seq_name)
00057 {
00058 int count = reader.read_int(make_seq_length_name(seq_name));
00059 if (0 > count)
00060 throw rutz::error("read negative value for sequence count",
00061 SRC_POS);
00062 return count;
00063 }
00064
00070 template <class T, class Inserter>
00071 inline void read_value_seq(io::reader& reader,
00072 const rutz::fstring& seq_name,
00073 Inserter inserter, int known_count = -1)
00074 {
00075 int count = (known_count == -1) ?
00076 read_sequence_length(reader, seq_name) : known_count;
00077
00078 for (int i = 0; i < count; ++i)
00079 {
00080 T temp;
00081 reader.read_value(make_element_name(seq_name, i), temp);
00082 *inserter = temp;
00083 ++inserter;
00084 }
00085 }
00086
00092 template <class T, class Inserter>
00093 inline void read_value_obj_seq(io::reader& reader,
00094 const rutz::fstring& seq_name,
00095 Inserter inserter, int known_count = -1)
00096 {
00097 int count = (known_count == -1) ?
00098 read_sequence_length(reader, seq_name) : known_count;
00099
00100 for (int i = 0; i < count; ++i)
00101 {
00102 T temp;
00103 reader.read_value_obj(make_element_name(seq_name, i), temp);
00104 *inserter = temp;
00105 ++inserter;
00106 }
00107 }
00108
00114 template <class C, class Inserter>
00115 inline void read_object_seq(io::reader& reader,
00116 const rutz::fstring& seq_name,
00117 Inserter inserter, int known_count = -1)
00118 {
00119 int count = (known_count == -1) ?
00120 read_sequence_length(reader, seq_name) : known_count;
00121
00122 for (int i = 0; i < count; ++i)
00123 {
00124 *inserter = dyn_cast<C>(
00125 reader.read_object(make_element_name(seq_name, i)));
00126
00127 ++inserter;
00128 }
00129 }
00130
00131 }}
00132
00133 static const char __attribute__((used)) vcid_groovx_io_readutils_h_utc20050626084021[] = "$Id: readutils.h 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00134 #endif // !GROOVX_IO_READUTILS_H_UTC20050626084021_DEFINED