// file : xml/serializer.ixx // copyright : Copyright (c) 2013-2014 Code Synthesis Tools CC // license : MIT; see accompanying LICENSE file #include namespace xml { inline void serializer:: start_element (const qname_type& qname) { start_element (qname.namespace_ (), qname.name ()); } inline void serializer:: start_element (const std::string& name) { start_element (std::string (), name); } inline void serializer:: end_element (const qname_type& qname) { end_element (qname.namespace_ (), qname.name ()); } inline void serializer:: end_element (const std::string& name) { end_element (std::string (), name); } inline void serializer:: element (const std::string& v) { if (!v.empty ()) characters (v); end_element (); } template inline void serializer:: element (const T& v) { element (value_traits::serialize (v, *this)); } inline void serializer:: element (const std::string& n, const std::string& v) { element (std::string (), n, v); } template inline void serializer:: element (const std::string& n, const T& v) { element (n, value_traits::serialize (v, *this)); } inline void serializer:: element (const qname_type& qn, const std::string& v) { element (qn.namespace_ (), qn.name (), v); } template inline void serializer:: element (const qname_type& qn, const T& v) { element (qn, value_traits::serialize (v, *this)); } template inline void serializer:: element (const std::string& ns, const std::string& n, const T& v) { element (ns, n, value_traits::serialize (v, *this)); } inline void serializer:: start_attribute (const qname_type& qname) { start_attribute (qname.namespace_ (), qname.name ()); } inline void serializer:: start_attribute (const std::string& name) { start_attribute (std::string (), name); } inline void serializer:: end_attribute (const qname_type& qname) { end_attribute (qname.namespace_ (), qname.name ()); } inline void serializer:: end_attribute (const std::string& name) { end_attribute (std::string (), name); } inline void serializer:: attribute (const qname_type& qname, const std::string& value) { attribute (qname.namespace_ (), qname.name (), value); } template inline void serializer:: attribute (const qname_type& qname, const T& value) { attribute (qname, value_traits::serialize (value, *this)); } inline void serializer:: attribute (const std::string& name, const std::string& value) { attribute (std::string (), name, value); } template inline void serializer:: attribute (const std::string& name, const T& value) { attribute (name, value_traits::serialize (value, *this)); } template inline void serializer:: attribute (const std::string& ns, const std::string& name, const T& value) { attribute (ns, name, value_traits::serialize (value, *this)); } template inline void serializer:: characters (const T& value) { characters (value_traits::serialize (value, *this)); } // operator<< // inline serializer& operator<< (serializer& s, void (*func) (serializer&)) { func (s); return s; } namespace details { // Detect whether T defines void operator(A) const. // template struct is_functor { typedef char no[1]; typedef char yes[2]; template struct check; template static no& test (...); template static yes& test (check*); static const bool value = sizeof (test (0)) == sizeof (yes); }; template ::value> struct inserter; template struct inserter { static void insert (serializer& s, const T& f) {f (s);} }; template struct inserter { static void insert (serializer& s, const T& v) {s.characters (v);} }; } template inline serializer& operator<< (serializer& s, const T& value) { details::inserter::insert (s, value); return s; } }