dvmysql.h

Go to the documentation of this file.
00001 #ifndef DVXML_DVMYSQL_H
00002 #define DVXML_DVMYSQL_H
00003 // $Id: dvmysql.h,v 1.5 2007/06/12 07:39:31 dvermeir Exp $
00004 #include <dvxml/node.h>
00005 #include <dvmysql/object.h>
00006 
00007 namespace Dv {
00008   namespace Sql {
00009     /** Generate an Xml node of the form
00010      * @code
00011      * <table_name column_name="column_value" ... />
00012      * @endcode
00013      * for a Dv::Sql::Object object.
00014      * @param o object to generate XML representation for
00015      * @param label of XML node (default is name of table corresponding to object)
00016      * @return an XML representation of this object
00017      * @warning Dv::Xml::iso2utf8 is applied to all attribute values
00018      */
00019     Dv::Xml::Node xml(const Dv::Sql::Object& o, const std::string& label="");
00020 
00021     /** Add an XML representation of each object in a set to a given
00022      * XML node.
00023      * @param parent node to which children will be added
00024      * @param s set of objects for each of which an XML
00025      *   representation will be added as a child to parent
00026      * @param label to use for the new child nodes
00027      * @return reference to parent
00028      * @warning the XML representation of a child is computed using Dv::Sql::xml(child,label)
00029      */
00030     template<typename T>
00031       Dv::Xml::Node& xml_add(Dv::Xml::Node& parent, const Dv::Sql::Set<T>& s, const std::string& label="") {
00032         for (typename Dv::Sql::Set<T>::const_iterator i=s.begin(); i!=s.end(); ++i) {
00033           parent.add(xml(**i, label));
00034         }
00035         return parent;
00036       }
00037 
00038     /** Add an XML representation of each object in a set to a given
00039      * XML node.
00040      * @param parent node to which children will be added
00041      * @param s set of objects for each of which an XML representation will be
00042      *   added as a child to parent
00043      * @param label to use for the new child nodes
00044      * @return reference to parent
00045      * @warning the XML representation of a child is computed using child.xml(label)
00046      */
00047     template<typename T>
00048       Dv::Xml::Node& xml_add_member(Dv::Xml::Node& parent, const Dv::Sql::Set<T>& s, const std::string& label) {
00049         for (typename Dv::Sql::Set<T>::const_iterator i=s.begin(); i!=s.end(); ++i) {
00050           parent.add((*i)->xml(label));
00051         }
00052         return parent;
00053       }
00054 
00055     /** Add an XML representation of each object in a set to a given
00056      * XML node.
00057      * @param parent node to which children will be added
00058      * @param s set of objects for each of which an XML representation will be
00059      *   added as a child to parent
00060      * @param label to use for the new child nodes
00061      * @param xml pointer to member function (of template parameter
00062      *   type T) that will be used to generate an XML presentation of
00063      *   each object in @c s
00064      * @return reference to parent
00065      */
00066     template<typename T>
00067       Dv::Xml::Node& xml_add_member(Dv::Xml::Node& parent, const Dv::Sql::Set<T>& s,
00068           const std::string& label, Dv::Xml::Node (T::*xml)(const std::string&)) {
00069         for (typename Dv::Sql::Set<T>::const_iterator i=s.begin(); i!=s.end(); ++i) {
00070           parent.add(((**i).*xml)(label));
00071         }
00072         return parent;
00073       }
00074 
00075   }
00076 }
00077 #endif

dvxml-0.1.7 [ 7 January, 2008]