From 0bfda486167432a9da8eec62b4578a22592a9275 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 11 Mar 2009 17:32:01 +0200 Subject: Add generation of detach functions New option: --generate-detach. Also added detach/attach functionality to var_seq, non-STL str_seq, and string_base. --- documentation/cxx/hybrid/guide/index.xhtml | 64 ++++++++++++++++++++++-------- documentation/xsde.1 | 5 +++ documentation/xsde.xhtml | 6 +++ 3 files changed, 58 insertions(+), 17 deletions(-) (limited to 'documentation') diff --git a/documentation/cxx/hybrid/guide/index.xhtml b/documentation/cxx/hybrid/guide/index.xhtml index f9ffccb..2aa9a19 100644 --- a/documentation/cxx/hybrid/guide/index.xhtml +++ b/documentation/cxx/hybrid/guide/index.xhtml @@ -1712,7 +1712,10 @@ private: variable-length type, the object model assumes ownership of the pointed to object. It expects you to allocate the object with operator new and will eventually delete it - with operator delete. As an example, let us extend + with operator delete. You can also request generation + of detach functions with the --generate-detach compiler + option. These functions allow you to detach a variable-length + object from the object model. As an example, let us extend our people.xsd schema with the following type:

@@ -1724,8 +1727,8 @@ private:
 </xs:complexType>
   
-

If we compile it with XSD/e, we will get the following C++ - class:

+

If we compile it with XSD/e and specify the --generate-detach + option, we will get the following C++ class:

 // staff (variable-length)
@@ -1751,6 +1754,9 @@ public:
   void
   permanent (people*);
 
+  people*
+  permanent_detach ();
+
   // contract
   //
   const people&
@@ -1762,6 +1768,9 @@ public:
   void
   contract (people*);
 
+  people*
+  contract_detach ();
+
 private:
   ...
 };
@@ -2135,31 +2144,43 @@ public:
   clear ();
 
   void
-  pop_back ();
+  push_back (T*);
 
   iterator
-  erase (iterator);
+  insert (iterator, T*);
 
   void
-  push_back (T*);
+  pop_back ();
 
   iterator
-  insert (iterator, T*);
+  erase (iterator);
 
-  error
+  void
   reserve (size_t);
+
+  T*
+  detach (iterator);
+
+  void
+  attach (iterator, T*);
 };
   

Most of this interface is identical to the fixed-length type - version except for the push_back() and + version except for the push_back(), and insert() functions. Similar to the modifier functions for elements and attributes of variable-length types, these two functions expect a pointer to the dynamically-allocated instance of the type and assume ownership of the passed object. To simplify error handling, these two functions delete the passed object if the reallocation - of the underlying sequence buffer fails.

+ of the underlying sequence buffer fails. The var_sequence + interface also provides the detach() and attach() + functions. The detach() function allows you to detach + the contained object at the specified position. A detached object + should eventually be deallocated with operator delete. + Similarly, the attach() function allows you to attach + a new object at the specified position.

When C++ exceptions are disabled, the push_back(), insert(), and reserve() functions @@ -2295,12 +2316,11 @@ namespace xml_schema void reserve (size_t); - // Detach a string from the sequence at a given position. - // The string pointer at this position in the sequence is - // set to 0. - // char* detach (iterator); + + void + attach (iterator, char*); }; } @@ -2313,8 +2333,13 @@ namespace xml_schema free the passed string if the reallocation of the underlying sequence buffer fails. The push_back_copy() function makes a copy of the passed string. - If you detach the underlying element string, then it should - eventually be deallocated with operator delete[].

+ The string_sequence interface also provides the + detach() and attach() functions. + The detach() function allows you to detach + the contained string at the specified position. A detached string + should eventually be deallocated with operator delete[]. + Similarly, the attach() function allows you to attach + a new string at the specified position.

When C++ exceptions are disabled, the signatures of the push_back(), push_back_copy(), @@ -3714,6 +3739,9 @@ namespace xml_schema void base_value (char* x); + char* + base_value_detach (); + operator const char* () const; operator char* (); }; @@ -3722,7 +3750,9 @@ namespace xml_schema

Note that the string_base object assumes ownership of the strings passed to the assignment operator and the - base_value() modifier.

+ base_value() modifier. If you detach the + string value then it should eventually be deallocated with + operator delete[].

5.1 Mapping for QName

diff --git a/documentation/xsde.1 b/documentation/xsde.1 index 3947beb..e66dcaa 100644 --- a/documentation/xsde.1 +++ b/documentation/xsde.1 @@ -944,6 +944,11 @@ Suppress the generation of validation code in parser. .IP "\fB\--suppress-serializer-val\fR" Suppress the generation of validation code in serializer. +.IP "\fB\--generate-detach\fR" +Generate detach functions for elements and attributes of variable-length +types. These functions, for example, allow you to move sub-trees in the +object model either within the same tree or between different trees. + .IP "\fB\--generate-insertion \fIos\fR" Generate data representation stream insertion operators for the .I os diff --git a/documentation/xsde.xhtml b/documentation/xsde.xhtml index 2af5983..330bb96 100644 --- a/documentation/xsde.xhtml +++ b/documentation/xsde.xhtml @@ -816,6 +816,12 @@
--suppress-serializer-val
Suppress the generation of validation code in serializer.
+
--generate-detach
+
Generate detach functions for elements and attributes of + variable-length types. These functions, for example, allow + you to move sub-trees in the object model either within the + same tree or between different trees.
+
--generate-insertion os
Generate data representation stream insertion operators for the os output stream type. Repeat this -- cgit v1.1