diff options
25 files changed, 201 insertions, 68 deletions
@@ -52,6 +52,14 @@ Version 3.1.0 sequences of fundamental types (e.g., int, float, etc.) is implemented in terms of memcpy(). + C++/Serializer + + * Support for XML pretty-printing. The serialize() functions in the + xml_schema::document_simpl class now have the flags argument (defaults + to 0). Your can pass the xml_schema::document_simpl::pretty_print flag + for this argument to turn on pretty-printing. See the examples and + documentation for details. + Version 3.0.0 * The new Embedded C++/Hybrid mapping provides a light-weight, tree- diff --git a/documentation/cxx/hybrid/guide/index.xhtml b/documentation/cxx/hybrid/guide/index.xhtml index d497a14..d2cc1ef 100644 --- a/documentation/cxx/hybrid/guide/index.xhtml +++ b/documentation/cxx/hybrid/guide/index.xhtml @@ -870,7 +870,7 @@ main (int argc, char* argv[]) xml_schema::document_simpl doc_s (hello_s.root_serializer (), hello_s.root_name ()); hello_s.pre (*h); - doc_s.serialize (cout); + doc_s.serialize (cout, xml_schema::document_simpl::pretty_print); hello_s.post (); delete h; @@ -893,15 +893,21 @@ main (int argc, char* argv[]) object model as in the previous example. Then it changes the greeting string and adds another entry to the list of names. Finally, it creates a document serializer and serializes the - object model back to XML. The resulting XML is written to - the standard output (<code>cout</code>) for us to inspect. - We could have also written the result to a file or memory - buffer by creating an instance of <code>std::ofstream</code> + object model back to XML. The <code>hello_saggr</code> class + is the serializer aggregate class we discussed earlier.</p> + + <p>The resulting XML is written to the standard output (<code>cout</code>) + for us to inspect. We could have also written the result to a + file or memory buffer by creating an instance of <code>std::ofstream</code> or <code>std::ostringstream</code> and passing it to <code>serialize()</code> instead of <code>cout</code>. - The <code>hello_saggr</code> class is the serializer aggregate - class we discussed earlier. Serialization is covered in more - detail in <a href="#6">Chapter 6, "Parsing and Serialization"</a>.</p> + The second argument in the call to + <code>serialize()</code> is a flag that requests pretty-printing + of the resulting XML document. You would normally specify this flag + during testing to obtain easily-readable XML and remove it + in production to get faster serialization and smaller documents. + Serialization is covered in more detail in <a href="#6">Chapter 6, + "Parsing and Serialization"</a>.</p> <p>If we now compile and run this application (don't forget to compile and link <code>hello-sskel.cxx</code> and @@ -971,7 +977,7 @@ main (int argc, char* argv[]) ostringstream ostr; hello_s.pre (*h); - doc_s.serialize (ostr); + doc_s.serialize (ostr, xml_schema::document_simpl::pretty_print); hello_s.post (); delete h; @@ -1195,7 +1201,7 @@ main (int argc, char* argv[]) if (se = hello_s._error ()) break; - doc_s.serialize (w); + doc_s.serialize (w, xml_schema::document_simpl::pretty_print); if (se = doc_s._error ()) break; @@ -3248,7 +3254,7 @@ main () xml_schema::document_simpl doc_s (people_s.root_serializer (), people_s.root_name ()); people_s.pre (*ppl); - doc_s.serialize (cout); + doc_s.serialize (cout, xml_schema::document_simpl::pretty_print); people_s.post (); } </pre> @@ -3360,7 +3366,7 @@ main () xml_schema::document_simpl doc_s (people_s.root_serializer (), people_s.root_name ()); people_s.pre (ppl); - doc_s.serialize (cout); + doc_s.serialize (cout, xml_schema::document_simpl::pretty_print); people_s.post (); } </pre> @@ -3988,7 +3994,7 @@ xml_schema::document_simpl doc_s ( doc_s.add_no_namespace_schema ("supermen.xsd"); supermen_s.pre (*sm); -doc_s.serialize (cout); +doc_s.serialize (cout, xml_schema::document_simpl::pretty_print); supermen_s.post (); </pre> @@ -5566,7 +5572,7 @@ hello_saggr hello_s; xml_schema::document_simpl doc_s (hello_s.root_serializer (), hello_s.root_name ()); hello_s.pre (*h); -doc_s.serialize (std::cout); +doc_s.serialize (std::cout, xml_schema::document_simpl::pretty_print); hello_s.post (); </pre> @@ -5818,7 +5824,7 @@ main (int argc, char* argv[]) xml_schema::document_simpl doc_s (root_s, people_s.root_name ()); people_s.pre (*ppl); - doc_s.serialize (cout); + doc_s.serialize (cout, xml_schema::document_simpl::pretty_print); people_s.post (); } </pre> diff --git a/documentation/cxx/serializer/guide/index.xhtml b/documentation/cxx/serializer/guide/index.xhtml index bd681cc..dd3a8f3 100644 --- a/documentation/cxx/serializer/guide/index.xhtml +++ b/documentation/cxx/serializer/guide/index.xhtml @@ -757,7 +757,7 @@ main () xml_schema::document_simpl doc_s (hello_s, "hello"); hello_s.pre (); - doc_s.serialize (cout); + doc_s.serialize (cout, xml_schema::document_simpl::pretty_print); hello_s.post (); } catch (const xml_schema::serializer_exception& e) @@ -789,10 +789,14 @@ main () <p>The final piece is the calls to <code>pre()</code>, <code>serialize()</code>, and <code>post()</code>. The call to <code>serialize()</code> performs the actual XML serialization - with the result written to <code>std::cout</code>. The calls - to <code>pre()</code> and <code>post()</code> make sure that - the serializer for the root element can perform proper - initialization and cleanup.</p> + with the result written to <code>std::cout</code>. The second + argument in this call is a flag that requests pretty-printing + of the resulting XML document. You would normally specify this flag + during testing to obtain easily-readable XML and remove it + in production to get faster serialization and smaller documents. + The calls to <code>pre()</code> and + <code>post()</code> make sure that the serializer for the + root element can perform proper initialization and cleanup.</p> <p>While our serializer implementation and test driver are pretty small and easy to write by hand, for bigger XML vocabularies it can be a @@ -1338,7 +1342,7 @@ xml_schema::document_simpl doc_s (people_s, "people"); std::ostringstream os; people_s.pre (); -doc_s.serialize (os); +doc_s.serialize (os, xml_schema::document_simpl::pretty_print); people_s.post (); cout << os.str (); @@ -1371,8 +1375,11 @@ namespace xml_schema const std::string& root_element_namespace, const std::string& root_element_name); + typedef unsigned short flags; + static const flags pretty_print; + void - serialize (std::ostream&); + serialize (std::ostream&, flags = 0); }; } </pre> @@ -2003,7 +2010,7 @@ main () xml_schema::document_simpl doc_s (people_s, "people"); people_s.pre (ppl); - doc_s.serialize (cout); + doc_s.serialize (cout, xml_schema::document_simpl::pretty_print); people_s.post (); } </pre> @@ -2652,7 +2659,7 @@ public: <pre class="c++"> void -serialize (std::ostream&); +serialize (std::ostream&, flags); </pre> <p>See <a href="#8.1">Section 8.1, "Document Serializer"</a> @@ -3345,7 +3352,7 @@ main () xml_schema::document_simpl doc_s (supermen_s, "supermen", true); supermen_s.pre (sm); - doc_s.serialize (std::cout); + doc_s.serialize (std::cout, xml_schema::document_simpl::pretty_print); supermen_s.post (); } </pre> @@ -3856,7 +3863,7 @@ main () if (e = people_s._error ()) break; - doc_s.serialize (w); + doc_s.serialize (w, xml_schema::document_simpl::pretty_print); if (e = doc_s._error ()) break; @@ -5696,20 +5703,27 @@ namespace xml_schema add_no_namespace_schema (const std::string& location); public: + // Serialization flags. + // + typedef unsigned short flags; + + static const flags pretty_print; + + public: // Serialize to std::ostream. The std::ios_base::failure // exception is used to report io errors (badbit and failbit) // if C++ exceptions are enabled. Otherwise error codes are // used. // void - serialize (std::ostream&); + serialize (std::ostream&, flags = 0); public: // Serialize by calling writer::write() and writer::flush() to // output XML. // void - serialize (writer&); + serialize (writer&, flags = 0); // Serialize by calling the write and flush functions. If the // unbounded write function is not provided, the bounded version @@ -5722,11 +5736,17 @@ namespace xml_schema typedef void (*flush_func) (void*); void - serialize (write_bound_func, flush_func, void* user_data); + serialize (write_bound_func, + flush_func, + void* user_data, + flags = 0); void - serialize (write_func, write_bound_func, flush_func, void* user_data); - + serialize (write_func, + write_bound_func, + flush_func, + void* user_data, + flags = 0); public: // Low-level, genx-specific serialization. With this method // it is your responsibility to call genxStartDoc*() and diff --git a/examples/cxx/hybrid/binary/cdr/driver.cxx b/examples/cxx/hybrid/binary/cdr/driver.cxx index 18848eb..9eb4231 100644 --- a/examples/cxx/hybrid/binary/cdr/driver.cxx +++ b/examples/cxx/hybrid/binary/cdr/driver.cxx @@ -99,7 +99,7 @@ main (int argc, char* argv[]) doc_s.add_schema ("http://www.codesynthesis.com/library", "library.xsd"); catalog_s.pre (*c); - doc_s.serialize (std::cout); + doc_s.serialize (std::cout, xml_schema::document_simpl::pretty_print); catalog_s.post (); } catch (const xml_schema::cdr_exception&) diff --git a/examples/cxx/hybrid/binary/custom/driver.cxx b/examples/cxx/hybrid/binary/custom/driver.cxx index e453a37..cfc525b 100644 --- a/examples/cxx/hybrid/binary/custom/driver.cxx +++ b/examples/cxx/hybrid/binary/custom/driver.cxx @@ -78,7 +78,7 @@ main (int argc, char* argv[]) doc_s.add_schema ("http://www.codesynthesis.com/library", "library.xsd"); catalog_s.pre (*c); - doc_s.serialize (std::cout); + doc_s.serialize (std::cout, xml_schema::document_simpl::pretty_print); catalog_s.post (); } catch (const raw_exception&) diff --git a/examples/cxx/hybrid/binary/xdr/driver.cxx b/examples/cxx/hybrid/binary/xdr/driver.cxx index d587817..02717be 100644 --- a/examples/cxx/hybrid/binary/xdr/driver.cxx +++ b/examples/cxx/hybrid/binary/xdr/driver.cxx @@ -131,7 +131,7 @@ main (int argc, char* argv[]) doc_s.add_schema ("http://www.codesynthesis.com/library", "library.xsd"); catalog_s.pre (*c); - doc_s.serialize (std::cout); + doc_s.serialize (std::cout, xml_schema::document_simpl::pretty_print); catalog_s.post (); } catch (const xml_schema::xdr_exception&) diff --git a/examples/cxx/hybrid/custom/wildcard/driver.cxx b/examples/cxx/hybrid/custom/wildcard/driver.cxx index f5b05ee..b4b1e7c 100644 --- a/examples/cxx/hybrid/custom/wildcard/driver.cxx +++ b/examples/cxx/hybrid/custom/wildcard/driver.cxx @@ -160,7 +160,7 @@ main (int argc, char* argv[]) doc_s.add_schema ("http://www.codesynthesis.com/email", "email.xsd"); message_s.pre (*reply); - doc_s.serialize (cout); + doc_s.serialize (cout, xml_schema::document_simpl::pretty_print); message_s.post (); } catch (const xml_schema::parser_exception& e) diff --git a/examples/cxx/hybrid/filter/driver.cxx b/examples/cxx/hybrid/filter/driver.cxx index 5c15cef..67efb60 100644 --- a/examples/cxx/hybrid/filter/driver.cxx +++ b/examples/cxx/hybrid/filter/driver.cxx @@ -73,7 +73,7 @@ main (int argc, char* argv[]) xml_schema::document_simpl doc_s (root_s, people_s.root_name ()); people_s.pre (*ppl); - doc_s.serialize (cout); + doc_s.serialize (cout, xml_schema::document_simpl::pretty_print); people_s.post (); } catch (const xml_schema::parser_exception& e) diff --git a/examples/cxx/hybrid/library/driver.cxx b/examples/cxx/hybrid/library/driver.cxx index 628831a..7b010ab 100644 --- a/examples/cxx/hybrid/library/driver.cxx +++ b/examples/cxx/hybrid/library/driver.cxx @@ -134,7 +134,7 @@ main (int argc, char* argv[]) doc_s.add_schema ("http://www.codesynthesis.com/library", "library.xsd"); catalog_s.pre (*c); - doc_s.serialize (cout); + doc_s.serialize (cout, xml_schema::document_simpl::pretty_print); catalog_s.post (); } catch (const xml_schema::parser_exception& e) diff --git a/examples/cxx/hybrid/minimal/driver.cxx b/examples/cxx/hybrid/minimal/driver.cxx index e8e8312..f1a43af 100644 --- a/examples/cxx/hybrid/minimal/driver.cxx +++ b/examples/cxx/hybrid/minimal/driver.cxx @@ -212,7 +212,7 @@ main (int argc, char* argv[]) if (se = people_s._error ()) break; - doc_s.serialize (w); + doc_s.serialize (w, xml_schema::document_simpl::pretty_print); if (se = doc_s._error ()) break; diff --git a/examples/cxx/hybrid/polymorphism/driver.cxx b/examples/cxx/hybrid/polymorphism/driver.cxx index 926bb91..81d2e95 100644 --- a/examples/cxx/hybrid/polymorphism/driver.cxx +++ b/examples/cxx/hybrid/polymorphism/driver.cxx @@ -115,7 +115,7 @@ main (int argc, char* argv[]) doc_s.add_no_namespace_schema ("supermen.xsd"); supermen_s.pre (*sm); - doc_s.serialize (cout); + doc_s.serialize (cout, xml_schema::document_simpl::pretty_print); supermen_s.post (); } catch (const xml_schema::parser_exception& e) diff --git a/examples/cxx/hybrid/polyroot/driver.cxx b/examples/cxx/hybrid/polyroot/driver.cxx index f41422c..c673182 100644 --- a/examples/cxx/hybrid/polyroot/driver.cxx +++ b/examples/cxx/hybrid/polyroot/driver.cxx @@ -235,7 +235,7 @@ main (int argc, char* argv[]) doc_s.add_no_namespace_schema ("supermen.xsd"); ps->pre (*p); - doc_s.serialize (std::cout); + doc_s.serialize (std::cout, xml_schema::document_simpl::pretty_print); ps->post (); } catch (const xml_schema::parser_exception& e) diff --git a/examples/cxx/hybrid/streaming/driver.cxx b/examples/cxx/hybrid/streaming/driver.cxx index 86d0b87..0488d70 100644 --- a/examples/cxx/hybrid/streaming/driver.cxx +++ b/examples/cxx/hybrid/streaming/driver.cxx @@ -58,7 +58,7 @@ main (int argc, char* argv[]) obj.id (456); object_s.pre (obj); - doc_s.serialize (cout); + doc_s.serialize (cout, xml_schema::document_simpl::pretty_print); object_s.post (); } catch (const xml_schema::parser_exception& e) diff --git a/examples/cxx/hybrid/wildcard/driver.cxx b/examples/cxx/hybrid/wildcard/driver.cxx index 69b6e67..c96e303 100644 --- a/examples/cxx/hybrid/wildcard/driver.cxx +++ b/examples/cxx/hybrid/wildcard/driver.cxx @@ -163,7 +163,7 @@ main (int argc, char* argv[]) doc_s.add_schema ("http://www.codesynthesis.com/email", "email.xsd"); message_s.pre (*reply); - doc_s.serialize (cout); + doc_s.serialize (cout, xml_schema::document_simpl::pretty_print); message_s.post (); } catch (const xml_schema::parser_exception& e) diff --git a/examples/cxx/serializer/hello/driver.cxx b/examples/cxx/serializer/hello/driver.cxx index e895add..c3eba63 100644 --- a/examples/cxx/serializer/hello/driver.cxx +++ b/examples/cxx/serializer/hello/driver.cxx @@ -72,7 +72,7 @@ main () doc_s.add_no_namespace_schema ("hello.xsd"); hello_s.pre (); - doc_s.serialize (cout); + doc_s.serialize (cout, xml_schema::document_simpl::pretty_print); hello_s.post (); } catch (const xml_schema::serializer_exception& e) diff --git a/examples/cxx/serializer/library/driver.cxx b/examples/cxx/serializer/library/driver.cxx index 2790028..01e7deb 100644 --- a/examples/cxx/serializer/library/driver.cxx +++ b/examples/cxx/serializer/library/driver.cxx @@ -122,7 +122,7 @@ main () doc_s.add_schema ("http://www.codesynthesis.com/library", "library.xsd"); catalog_s.pre (cat); - doc_s.serialize (std::cout); + doc_s.serialize (std::cout, xml_schema::document_simpl::pretty_print); catalog_s.post (); } catch (const xml_schema::serializer_exception& e) diff --git a/examples/cxx/serializer/minimal/driver.cxx b/examples/cxx/serializer/minimal/driver.cxx index df8d7f0..05e7de4 100644 --- a/examples/cxx/serializer/minimal/driver.cxx +++ b/examples/cxx/serializer/minimal/driver.cxx @@ -87,7 +87,7 @@ main () if (e = people_s._error ()) break; - doc_s.serialize (w); + doc_s.serialize (w, xml_schema::document_simpl::pretty_print); if (e = doc_s._error ()) break; diff --git a/examples/cxx/serializer/polymorphism/driver.cxx b/examples/cxx/serializer/polymorphism/driver.cxx index 3015133..fc91b06 100644 --- a/examples/cxx/serializer/polymorphism/driver.cxx +++ b/examples/cxx/serializer/polymorphism/driver.cxx @@ -102,7 +102,7 @@ main () doc_s.add_no_namespace_schema ("supermen.xsd"); supermen_s.pre (sm); - doc_s.serialize (std::cout); + doc_s.serialize (std::cout, xml_schema::document_simpl::pretty_print); supermen_s.post (); } catch (const xml_schema::serializer_exception& e) diff --git a/examples/cxx/serializer/polyroot/driver.cxx b/examples/cxx/serializer/polyroot/driver.cxx index d404d15..7558618 100644 --- a/examples/cxx/serializer/polyroot/driver.cxx +++ b/examples/cxx/serializer/polyroot/driver.cxx @@ -120,7 +120,7 @@ main () doc_s.add_no_namespace_schema ("supermen.xsd"); ps->pre (p); - doc_s.serialize (std::cout); + doc_s.serialize (std::cout, xml_schema::document_simpl::pretty_print); ps->post (); std::cout << endl diff --git a/examples/cxx/serializer/wildcard/driver.cxx b/examples/cxx/serializer/wildcard/driver.cxx index 7feb13a..876f47b 100644 --- a/examples/cxx/serializer/wildcard/driver.cxx +++ b/examples/cxx/serializer/wildcard/driver.cxx @@ -392,7 +392,7 @@ main () doc_s.add_schema ("http://www.codesynthesis.com/email", "email.xsd"); envelope_s.pre (env); - doc_s.serialize (cout); + doc_s.serialize (cout, xml_schema::document_simpl::pretty_print); envelope_s.post (); } catch (const xml_schema::serializer_exception& e) diff --git a/libxsde/xsde/c/genx/genx.c b/libxsde/xsde/c/genx/genx.c index 1ce0527..f838f42 100644 --- a/libxsde/xsde/c/genx/genx.c +++ b/libxsde/xsde/c/genx/genx.c @@ -126,6 +126,11 @@ struct genxWriter_rec char * etext[100]; void * (* alloc)(void * userData, int bytes); void (* dealloc)(void * userData, void * data); + + /* Pretty-printing state */ + int ppIndent; + int ppDepth; + Boolean ppSimple; }; /******************************* @@ -590,6 +595,8 @@ genxWriter genxNew(void * (* alloc)(void * userData, int bytes), xml->declCount = 1; xml->declaration = xml->defaultDecl; + w->ppIndent = 0; /* Pretty-printing is disabled by default. */ + return w; } @@ -630,6 +637,24 @@ void * genxGetUserData(genxWriter w) } /* + * get/set pretty-printing + */ +genxStatus genxSetPrettyPrint(genxWriter w, int ind) +{ + if (w->sequence == SEQUENCE_NO_DOC) + w->ppIndent = ind; + else + w->status = GENX_SEQUENCE_ERROR; + + return w->status; +} + +int genxGetPrettyPrint(genxWriter w) +{ + return w->ppIndent; +} + +/* * get/set allocator */ void genxSetAlloc(genxWriter w, void * (* alloc)(void * userData, int bytes)) @@ -1142,6 +1167,13 @@ genxStatus genxStartDocFile(genxWriter w, FILE * file) w->sequence = SEQUENCE_PRE_DOC; w->file = file; w->sender = NULL; + + if (w->ppIndent) + { + w->ppSimple = True; + w->ppDepth = 0; + } + return GENX_SUCCESS; } @@ -1153,10 +1185,32 @@ genxStatus genxStartDocSender(genxWriter w, genxSender * sender) w->sequence = SEQUENCE_PRE_DOC; w->file = NULL; w->sender = sender; + + if (w->ppIndent) + { + w->ppSimple = True; + w->ppDepth = 0; + } + return GENX_SUCCESS; } /* + * Output new line and indentation. + */ +static genxStatus writeIndentation(genxWriter w) +{ + int i, n; + SendCheck(w, "\n"); + n = w->ppDepth * w->ppIndent; + + for (i = 0; i < n; i++) + SendCheck(w, " "); + + return w->status; +} + +/* * Write out the attributes we've been gathering up for an element. We save * them until we've gathered them all so they can be writen in canonical * order. @@ -1167,7 +1221,7 @@ genxStatus genxStartDocSender(genxWriter w, genxSender * sender) */ static genxStatus writeStartTag(genxWriter w) { - int i; + int i, n; genxAttribute * aa = (genxAttribute *) w->attributes.pointers; genxElement e = w->nowStarting; @@ -1181,6 +1235,16 @@ static genxStatus writeStartTag(genxWriter w) unsetDefaultNamespace(w); w->status = GENX_SUCCESS; + if (w->ppIndent) + { + if (w->ppDepth) + if (writeIndentation (w) != GENX_SUCCESS) + return w->status; + + w->ppDepth++; + w->ppSimple = True; + } + SendCheck(w, "<"); if (e->ns && (e->ns->declaration != w->xmlnsEquals)) { @@ -1596,7 +1660,7 @@ genxStatus genxEndAttribute(genxWriter w) genxStatus genxEndElement(genxWriter w) { genxElement e; - int i; + int i, n; switch (w->sequence) { @@ -1624,6 +1688,17 @@ genxStatus genxEndElement(genxWriter w) ; e = (genxElement) w->stack.pointers[--i]; + if (w->ppIndent) + { + w->ppDepth--; + + if (!w->ppSimple) + if (writeIndentation (w) != GENX_SUCCESS) + return w->status; + + w->ppSimple = False; + } + SendCheck(w, "</"); if (e->ns && e->ns->declaration != w->xmlnsEquals) { @@ -2115,4 +2190,3 @@ char * genxGetVersion() { return GENX_VERSION; } - diff --git a/libxsde/xsde/c/genx/genx.h b/libxsde/xsde/c/genx/genx.h index da9f9b7..1a1ea22 100644 --- a/libxsde/xsde/c/genx/genx.h +++ b/libxsde/xsde/c/genx/genx.h @@ -1,4 +1,3 @@ - /* * genx - C-callable library for generating XML documents */ @@ -105,6 +104,13 @@ void genxSetUserData(genxWriter w, void * userData); void * genxGetUserData(genxWriter w); /* + * Set/get pretty-printing. If indentation is set to 0, then no pretty- + * printing is performed. + */ +genxStatus genxSetPrettyPrint(genxWriter w, int indentation); +int genxGetPrettyPrint(genxWriter w); + +/* * User-provided memory allocator, if desired. For example, if you were * in an Apache module, you could arrange for genx to use ap_palloc by * making the pool accessible via the userData call. @@ -235,7 +241,7 @@ genxStatus genxEndAttribute(genxWriter w); /* * add a namespace declaration */ -genxStatus genxAddNamespaceLiteral(genxWriter w, +genxStatus genxAddNamespaceLiteral(genxWriter w, constUtf8 uri, constUtf8 prefix); /* diff --git a/libxsde/xsde/cxx/serializer/genx/document.cxx b/libxsde/xsde/cxx/serializer/genx/document.cxx index bba4b26..d30a106 100644 --- a/libxsde/xsde/cxx/serializer/genx/document.cxx +++ b/libxsde/xsde/cxx/serializer/genx/document.cxx @@ -64,6 +64,7 @@ namespace xsde // document_simpl // + const document_simpl::flags document_simpl::pretty_print = 0x01; document_simpl:: ~document_simpl () @@ -304,9 +305,9 @@ namespace xsde #endif void document_simpl:: - serialize (std::ostream& os) + serialize (std::ostream& os, flags f) { - serialize (&ostream_write, &ostream_flush, &os); + serialize (&ostream_write, &ostream_flush, &os, f); } #endif // XSDE_IOSTREAM @@ -351,9 +352,9 @@ namespace xsde #endif void document_simpl:: - serialize (writer& w) + serialize (writer& w, flags f) { - serialize (&write_thunk, &write_bound_thunk, &flush_thunk, &w); + serialize (&write_thunk, &write_bound_thunk, &flush_thunk, &w, f); } // Genx write functions. @@ -427,8 +428,8 @@ namespace xsde } void document_simpl:: - serialize (write_func w, write_bound_func wb, flush_func f, - void* user_data) + serialize (write_func wf, write_bound_func wbf, flush_func ff, + void* user_data, flags f) { if (xml_serializer_ == 0) { @@ -447,12 +448,15 @@ namespace xsde writer_info wi; wi.user_data = user_data; - wi.write = w; - wi.write_bound = wb; - wi.flush = f; + wi.write = wf; + wi.write_bound = wbf; + wi.flush = ff; genxSetUserData (xml_serializer_, &wi); + if (f & pretty_print) + genxSetPrettyPrint (xml_serializer_, 2); + genxSender sender; sender.send = &genx_write; sender.sendBounded = &genx_write_bound; diff --git a/libxsde/xsde/cxx/serializer/genx/document.hxx b/libxsde/xsde/cxx/serializer/genx/document.hxx index 19117d6..ee06795 100644 --- a/libxsde/xsde/cxx/serializer/genx/document.hxx +++ b/libxsde/xsde/cxx/serializer/genx/document.hxx @@ -189,6 +189,13 @@ namespace xsde void reset (); + public: + // Serialization flags. + // + typedef unsigned short flags; + + static const flags pretty_print; + #ifdef XSDE_IOSTREAM public: // Serialize to std::ostream. The std::ios_base::failure @@ -197,7 +204,7 @@ namespace xsde // used. // void - serialize (std::ostream&); + serialize (std::ostream&, flags = 0); #endif public: @@ -205,7 +212,7 @@ namespace xsde // output XML. // void - serialize (writer&); + serialize (writer&, flags = 0); // Serialize by calling the write and flush functions. If the // unbounded write function is not provided, the bounded version @@ -226,10 +233,17 @@ namespace xsde #endif void - serialize (write_bound_func, flush_func, void* user_data); + serialize (write_bound_func, + flush_func, + void* user_data, + flags = 0); void - serialize (write_func, write_bound_func, flush_func, void* user_data); + serialize (write_func, + write_bound_func, + flush_func, + void* user_data, + flags = 0); public: // Low-level, genx-specific serialization. With this method diff --git a/libxsde/xsde/cxx/serializer/genx/document.ixx b/libxsde/xsde/cxx/serializer/genx/document.ixx index 7269fa6..7001ece 100644 --- a/libxsde/xsde/cxx/serializer/genx/document.ixx +++ b/libxsde/xsde/cxx/serializer/genx/document.ixx @@ -66,9 +66,10 @@ namespace xsde #endif inline void document_simpl:: - serialize (write_bound_func wb, flush_func f, void* user_data) + serialize (write_bound_func wbf, flush_func ff, + void* user_data, flags f) { - serialize (0, wb, f, user_data); + serialize (0, wbf, ff, user_data, f); } #ifndef XSDE_EXCEPTIONS |