CVS difference for ais/ai-00260.txt

Differences between 1.1 and version 1.2
Log of other versions for file ais/ai-00260.txt

--- ais/ai-00260.txt	2001/02/13 22:29:23	1.1
+++ ais/ai-00260.txt	2001/03/22 22:24:53	1.2
@@ -94,3 +94,184 @@
 some head-scratching.
 
 ****************************************************************
+
+From: Pascal Obry
+Sent: Saturday, March 17, 2001 2:57 PM
+
+Hello,
+
+Please have a look at this first proposal. I have tried to write something but
+this is the very first time I do something like that. I'm not sure the wording
+is correct, not talking about my english :) Can you told me if this all this
+makes sense to you or if it is just not the right way to approach the
+problem. I have tried to follow current AI structure.
+
+<<
+!summary
+
+The stream input/output attributes are not flexible enough. The problem is for
+the tag handling of tagged object. With the current implementation it is not
+possible for example to redefine the 'Read and 'Write to have the object
+streamed as an XML object. We propose a solution to solve this problem.
+
+!problem
+
+The problem is for the tag handling of tagged object. With the current
+implementation it is not possible for example to redefine the 'Read and 'Write
+to have the object streamed as an XML object. Indeed the tag is defined as a
+string. It is possible to change the tag string value by using Ada.Tags
+facilities. But the tag will always be a string : an unbounded object. Each
+time the tagged object will be streamed the tag string value will be written
+preceded by the string bound which are binary data. There is no way to avoid
+these binary data to be sent. In other word, there is no way to stream an
+object with a plain text representation.
+
+!proposal
+
+Have the possibility to set the way the 'Class'Output and 'Class'Input handle
+the tag with the new attribute 'Tag_Format. Values for this attributes is of
+type Ada.Tags.Tag_Output:
+
+   type Tag_Ouput is (Constrained, Unconstrained);
+
+'Tag_Format
+   is set to Unconstrained by default. This is the current behavior. In this
+   mode 'Class'Output will call String'Output on the tag string to output the
+   tag. And 'Class'Input will call String'Input to read the tag. So with
+   Unconstrained the tag's bounds are used. If it is set to Constrained then
+   the tag will be written using String'Write (and read using String'Read). In
+   this case the tag's bounds are not used.
+
+The definition for S'Class'Input and S'Class'Output must be changed
+accordingly.
+
+!discussion
+
+We could find some other ways to implement this feature. This is certainly the
+lightest one as it requires only one new attributes on tagged record. Another
+solution would have been to define two new attributes 'Read_Tag and 'Write_Tag
+for reading and writing a tag value. These attributes would have the current
+default and could have been overridden by users. It would have been possible to
+solve the problem described here with this mechanism. Something like:
+
+   procedure Write_Tag (S : access Streams.Root_Stream_Type'Class; O : Object);
+   for Object'Write_Tag use Write_Tag;
+
+   procedure Read_Tag (S : access Streams.Root_Stream_Type'Class; O : Object);
+   for Object'Read_Tag use Read_Tag;
+
+!example
+
+Here is an example that show the problem. Let's say that we want to stream an
+object with an XML encoding:
+
+with Ada.Streams;
+
+package Class is
+
+   use Ada;
+
+   type Object is tagged record
+      V : Integer := 2;
+   end record;
+
+   procedure Write (S : access Streams.Root_Stream_Type'Class; O : Object);
+   for Object'Write use Write;
+
+   for Object'External_Tag use "<object>";
+
+end Class;
+
+package body Class is
+
+   procedure Write (S : access Streams.Root_Stream_Type'Class; O : Object) is
+   begin
+      String'Write (S, "<v>");
+      String'Write (S, Integer'Image (O.V));
+      String'Write (S, "</v>");
+      String'Write (S, "</object>");
+   end Write;
+
+end Class;
+
+
+with Ada.Text_IO.Text_Streams;
+with Class;
+
+procedure Main is
+   use Ada;
+
+   O : Class.Object;
+begin
+   Class.Object'Class'Output
+     (Text_IO.Text_Streams.Stream (Text_IO.Current_Output), O);
+end Main;
+
+This program output will be something like:
+
+   ^A^@^@^@^H^@^@^@<object><v> 2</v></object>
+
+The 8 first characters are binary representation for the tag bound. This is no
+way to bypass that, so there is no way to stream an object with an XML
+representation.
+
+Using the new 'Tag_Format attributes it is possible to control the tag
+output. By changing the Class spec to read:
+
+with Ada.Streams;
+
+package Class is
+
+   use Ada;
+
+   type Object is tagged record
+      V : Integer := 2;
+   end record;
+
+   procedure Write (S : access Streams.Root_Stream_Type'Class; O : Object);
+   for Object'Write use Write;
+
+   for Object'External_Tag use "<object>";
+   for Object'Tag_Format use Constrained;
+
+end Class;
+
+We now have the following output:
+
+   <object><v> 2</v></object>
+>>
+
+I hope to hear from you soon,
+Pascal.
+
+****************************************************************
+
+From: Pascal Obry
+Sent: Sunday, March 18, 2001 3:19 PM
+
+Please ignore my proposal as it is not working for reading the Tag. When
+reading an object (by calling 'Class'Input) the Tag is not known so the string
+bounds are needed !
+
+I'll try to find something else...
+
+****************************************************************
+
+From: Randy Brukardt
+Sent: Monday, March 19, 2001 5:20 PM
+
+Too bad. We have an (empty) AI on this subject just waiting for a proposal.
+(It seems like a problem worth solving.) Tucker pointed out that the problem
+of being unable to handle the tag is really one of being unable to write a
+new implementation of T'Class'Input, and *that* is caused by not having a
+way to dispatch based on a (internal) tag value (or, equivalently, being
+able to create a default-initialized object from a tag value). We can write
+code to read the tag however you need, you can look up the tag with
+Internal_Tag, but you can't write the needed dispatching and/or object
+creation.
+
+Tuck's musings suggested that perhaps a "magic" generic with this capability
+would be the way to go. Perhaps you can find a solution and make a proposal
+based on that idea??
+
+****************************************************************

Questions? Ask the ACAA Technical Agent