comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: set_index and and end_of_file with just a stream reference
Date: Sun, 21 Feb 2021 01:22:37 +0100	[thread overview]
Message-ID: <s0s949$j9b$1@gioia.aioe.org> (raw)
In-Reply-To: a135e4e9-9e51-4b57-ace7-f3cc930b7973n@googlegroups.com

On 2021-02-20 20:08, Mehdi Saada wrote:
> Okay :-)
> what I wanted is:
> I read an acronyme in the stream file, if good I input the adjacent record type, otherwise I would advance on the stream until the next acronyme with set_index(stream_access, index(stream_access) + composite_type_stream_size) and read the next acronyme (unbounded_string).
> Now I just input both objects and verify the acronyme.
> But I don't like writing an object that maybe won't be used.

So, the problem is "compartmentalization" of a stream.

[As Simon said you better read/write everything as is]

If you really want to implement it, one technique is chained "virtual" 
stream. You create a stream type like this:

    type Compartment_Stream
         (  Source : not null access Root_Stream_Type'Class
         )  is new Root_Stream_Type with ...

The Read/Write operations call to Read/Write of Source, but add 
delimiters separating "compartments." E.g. the stream elements 0..254 
are encoded as is. The element 255 is encoded as a pair (255,255). The 
pairs (255,*) are treated as an "end of a compartment" and ignored. This 
way you can add a Skip operation to Compartment_Stream that reads 
everything until first (255,*). You can even create a nested structure 
of compartments using this schema. E.g. encode start of a compartment as 
(255,0) and its end as (255,1) etc.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  parent reply	other threads:[~2021-02-21  0:22 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-20 15:26 set_index and and end_of_file with just a stream reference Mehdi Saada
2021-02-20 15:35 ` Mehdi Saada
2021-02-20 16:01   ` Simon Wright
2021-02-20 16:04 ` Dmitry A. Kazakov
2021-02-20 16:22   ` Mehdi Saada
2021-02-20 16:30     ` Mehdi Saada
2021-02-20 17:59       ` Dmitry A. Kazakov
2021-02-20 19:08         ` Mehdi Saada
2021-02-20 21:41           ` Simon Wright
2021-02-21  0:22           ` Dmitry A. Kazakov [this message]
2021-02-23 17:21           ` Shark8
2021-02-23 17:56           ` J-P. Rosen
2021-02-20 17:52     ` Dmitry A. Kazakov
2021-02-21  1:56   ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox