1 // file : examples/cxx/tree/custom/double/double-custom.cxx 2 // copyright : not copyrighted - public domain 3 4 // Include xml-schema.hxx instead of double-custom.hxx here. 5 // 6 #include "xml-schema.hxx" 7 8 #include <limits> 9 #include <locale> 10 #include <sstream> 11 12 #include <xsd/cxx/ro-string.hxx> 13 #include <xsd/cxx/zc-istream.hxx> 14 15 using namespace std; 16 17 // Parsing. 18 // 19 namespace xsd 20 { 21 namespace cxx 22 { 23 namespace tree 24 { 25 double traits<double, char, schema_type::double_>:: create(const std::string & s,const xercesc::DOMElement *,flags,type *)26 create (const std::string& s, 27 const xercesc::DOMElement*, 28 flags, 29 type*) 30 { 31 // This type cannot have whitespaces in its values. As result we 32 // don't need to waste time collapsing whitespaces. All we need to 33 // do is trim the string representation which can be done without 34 // copying. 35 // 36 ro_string<char> tmp (s); 37 trim (tmp); 38 39 zc_istream<char> is (tmp); 40 is.imbue (locale::classic ()); 41 42 double t; 43 is >> t; 44 45 return t; 46 } 47 } 48 } 49 } 50 51 // Serialization. 52 // 53 namespace XERCES_CPP_NAMESPACE 54 { 55 void operator <<(xercesc::DOMElement & e,const xml_schema::as_double & d)56 operator<< (xercesc::DOMElement& e, const xml_schema::as_double& d) 57 { 58 ostringstream os; 59 os.imbue (locale::classic ()); 60 61 os.precision (2); 62 os << fixed << d.x; 63 64 e << os.str (); 65 } 66 67 void operator <<(xercesc::DOMAttr & a,const xml_schema::as_double & d)68 operator<< (xercesc::DOMAttr& a, const xml_schema::as_double& d) 69 { 70 ostringstream os; 71 os.imbue (locale::classic ()); 72 73 os.precision (2); 74 os << fixed << d.x; 75 76 a << os.str (); 77 } 78 } 79 80 namespace xsd 81 { 82 namespace cxx 83 { 84 namespace tree 85 { 86 void operator <<(xml_schema::list_stream & ls,const xml_schema::as_double & d)87 operator<< (xml_schema::list_stream& ls, 88 const xml_schema::as_double& d) 89 { 90 ls.os_.imbue (locale::classic ()); 91 ls.os_.precision (2); 92 ls.os_ << fixed << d.x; 93 } 94 } 95 } 96 } 97