writeutils.h

Go to the documentation of this file.
00001 
00004 
00005 //
00006 // Copyright (c) 1999-2004 California Institute of Technology
00007 // Copyright (c) 2004-2007 University of Southern California
00008 // Rob Peters <rjpeters at usc dot edu>
00009 //
00010 // created: Tue Nov 16 14:18:36 1999
00011 // commit: $Id: writeutils.h 10065 2007-04-12 05:54:56Z rjpeters $
00012 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/io/writeutils.h $
00013 //
00014 // --------------------------------------------------------------------
00015 //
00016 // This file is part of GroovX.
00017 //   [http://ilab.usc.edu/rjpeters/groovx/]
00018 //
00019 // GroovX is free software; you can redistribute it and/or modify it
00020 // under the terms of the GNU General Public License as published by
00021 // the Free Software Foundation; either version 2 of the License, or
00022 // (at your option) any later version.
00023 //
00024 // GroovX is distributed in the hope that it will be useful, but
00025 // WITHOUT ANY WARRANTY; without even the implied warranty of
00026 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00027 // General Public License for more details.
00028 //
00029 // You should have received a copy of the GNU General Public License
00030 // along with GroovX; if not, write to the Free Software Foundation,
00031 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
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 }} // end namespace io::write_utils
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

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:49:39 2008 by Doxygen version 1.5.5.