streaming redux

SHOO zan77137 at nifty.com
Tue Dec 28 18:33:30 PST 2010


(2010/12/29 8:41), Andrei Alexandrescu wrote:
> On 12/28/10 5:14 PM, Haruki Shigemori wrote:
>> (2010/12/28 16:02), Andrei Alexandrescu wrote:
>>> I've put together over the past days an embryonic streaming interface.
>>> It separates transport from formatting, input from output, and buffered
>>> from unbuffered operation.
>>>
>>> http://erdani.com/d/phobos/std_stream2.html
>>>
>>> There are a number of questions interspersed. It would be great to start
>>> a discussion using that design as a baseline. Please voice any related
>>> thoughts - thanks!
>>>
>>>
>>> Andrei
>>
>> I've waited so long for this day.
>> Excuse me, would you give me a user side code and librarian side code
>> using std.stream2?
>> I don't know a concrete implementation of the std.stream2 interfaces.
>
> There isn't one. The source code is just support for documentation, and
> I attach it with this message.
>
> Thanks for participating! I know there has been some good stream-related
> activity in the Japanese D community.
>
>
> Andrei

Like this?

-----
import std.stream2;

void main()
{
     /*
     <data>
         <int>123</int>
         <double>55.98</double>
         <string>aabbccddee</string>
     </data>
     */
     auto infile = new BufferedFileTransport("intest.xml");
     auto unfmt  = new XmlUnformatter(infile);

     int a;
     double b;
     string c;

     unfmt.read(a);
     unfmt.read(b);
     unfmt.read(c);

     writeln(a); // 123
     writeln(b); // 55.98
     writeln(c); // aabbccddee

     auto outfile = new UnbufferedFileTransport("outtest.dat");
     auto fmt     = new BinaryFormatter(outfile);

     fmt.put(a);
     fmt.put(b);
     fmt.put(c);
     /*
         |  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
     ----+------------------------------------------------
     0000| 7B-00-00-00-00-00-00-00-3D-0A-D7-A3-70-FD-4B-40
     0001| 0A-00-00-00-61-61-62-62-63-63-64-64-65-65
     */
}

--
SHOO


More information about the Digitalmars-d mailing list