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_WRITEUTILS_H_UTC20050626084021_DEFINED
00036 #define GROOVX_IO_WRITEUTILS_H_UTC20050626084021_DEFINED
00037
00038 #include "io/writer.h"
00039
00040 #include "nub/ref.h"
00041
00042 #include "rutz/debug.h"
00043 GVX_DBG_REGISTER
00044
00045 namespace io
00046 {
00048 namespace write_utils
00049 {
00050
00051 rutz::fstring make_element_name(const rutz::fstring& seq_name,
00052 int element_num);
00053
00054 rutz::fstring make_seq_length_name(const rutz::fstring& seq_name);
00055
00058 template <class Itr>
00059 void write_value_seq(io::writer& writer, const rutz::fstring& name,
00060 Itr begin, Itr end, bool skip_count=false)
00061 {
00062 if (!skip_count)
00063 {
00064 writer.write_value(make_seq_length_name(name).c_str(),
00065 compute_seq_length(begin, end));
00066 }
00067
00068 int count = 0;
00069
00070 while (begin != end)
00071 {
00072 writer.write_value(make_element_name(name, count).c_str(),
00073 *begin);
00074 ++begin;
00075 ++count;
00076 }
00077 }
00078
00081 template <class Itr>
00082 void write_value_obj_seq(io::writer& writer, const rutz::fstring& name,
00083 Itr begin, Itr end, bool skip_count=false)
00084 {
00085 if (!skip_count)
00086 {
00087 writer.write_value(make_seq_length_name(name).c_str(),
00088 compute_seq_length(begin, end));
00089 }
00090
00091 int count = 0;
00092
00093 while (begin != end)
00094 {
00095 writer.write_value_obj(make_element_name(name, count).c_str(),
00096 *begin);
00097 ++begin;
00098 ++count;
00099 }
00100 }
00101
00103 template <class Itr>
00104 void write_object_seq(io::writer& writer, const rutz::fstring& name,
00105 Itr begin, Itr end, bool skip_count=false)
00106 {
00107 if (!skip_count)
00108 {
00109 writer.write_value(make_seq_length_name(name).c_str(),
00110 compute_seq_length(begin, end));
00111 }
00112
00113 int count = 0;
00114
00115 while (begin != end)
00116 {
00117 dbg_eval(4, count); dbg_eval_nl(4, (*begin)->id());
00118
00119 writer.write_object(make_element_name(name, count).c_str(),
00120 nub::soft_ref<const io::serializable>(*begin));
00121 ++begin;
00122 ++count;
00123 }
00124 }
00125
00126 template <class Itr>
00127 int compute_seq_length(Itr begin, Itr end)
00128 {
00129 int count = 0;
00130 while (begin != end) { ++count; ++begin; }
00131 return count;
00132 }
00133
00134 }}
00135
00136 static const char __attribute__((used)) vcid_groovx_io_writeutils_h_utc20050626084021[] = "$Id: writeutils.h 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00137 #endif // !GROOVX_IO_WRITEUTILS_H_UTC20050626084021_DEFINED