From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.5-pre1 X-Received: by 2002:ac8:4a8f:: with SMTP id l15mr2506885qtq.238.1614100871168; Tue, 23 Feb 2021 09:21:11 -0800 (PST) X-Received: by 2002:a25:b906:: with SMTP id x6mr39542062ybj.504.1614100870973; Tue, 23 Feb 2021 09:21:10 -0800 (PST) Path: eternal-september.org!reader02.eternal-september.org!news.szaf.org!news.uzoreto.com!feeder1.cambriumusenet.nl!feed.tweak.nl!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 23 Feb 2021 09:21:10 -0800 (PST) In-Reply-To: Injection-Info: google-groups.googlegroups.com; posting-host=146.5.2.231; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 146.5.2.231 References: <4d2daa8c-c159-48a4-bdf7-e9aa3b537bcan@googlegroups.com> <4d0aa284-8042-4260-ac58-6d3ac9a82b00n@googlegroups.com> <1cd1f911-ab74-464a-8eff-b6f3d79bfe8an@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <587d1883-ed0f-43ed-94c0-ec8899f078b4n@googlegroups.com> Subject: Re: set_index and and end_of_file with just a stream reference From: Shark8 Injection-Date: Tue, 23 Feb 2021 17:21:11 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:61424 List-Id: On Saturday, February 20, 2021 at 12:08:16 PM UTC-7, 0012com wrote: > Okay :-)=20 > what I wanted is:=20 > I read an acronyme in the stream file, if good I input the adjacent recor= d type, otherwise I would advance on the stream until the next acronyme wit= h set_index(stream_access, index(stream_access) + composite_type_stream_siz= e) and read the next acronyme (unbounded_string).=20 > Now I just input both objects and verify the acronyme.=20 > But I don't like writing an object that maybe won't be used. Hm, what are your datatypes? Is this ONLY text, or are you able to impose y= our own structure? You could have something like this: -- Instantiated Container Packages. Package String_Holder is new Ada.Containers.Indefinite_Holders( Element_Type =3D> String, "=3D" =3D> Ada.Strings.Equal_Case_Insensitive ); Package String_Map is new Ada.Containers.Indefinite_Ordered_Maps( "<" =3D> Ada.Strings.Less_Case_Insensitive, "=3D" =3D> Ada.Strings.Equal_Case_Insensitive, Key_Type =3D> String, Element_Type =3D> String ); -- The heart of the operating program. With String_Holder, String_Map; Package Acronyms is -- Because this is it's own type, you can put other things in the record,= like a link to the place that it's defined, if needed. Type Initialism is new String_Holder.Holder with null record; Function Expand( Acronym : Initialism ) return String; Procedure Register( Acronym, Expansion : String ); --... End Acronyms; Package Body Acronyms is Acronym_Map : String_Map.Map; Procedure Register( Acronym, Expansion : String ) is Begin Acronym_Map.Insert( New_Item =3D> Expansion, Key =3D> Acronym ); End Register; =20 Function Expand( Acronym : Initialism ) return String is Begin Return Acronym_Map( Acronym ); Exception when others =3D> Return Acronym; -- I forget if it's CONSTRAINT_ERROR o= r ASSERT_ERROR when the element is not present. End Expand; End Acronyms; -- in your main Acronym-Stream package... -- Text_Soup is a variant record for handling portions of an acronym-expand= ing string; your main data-structure would probably be an Indefinite_Vector= of Text_Soup'Class, -- you might not need Input or output, depending on your usage, but for aut= omatically expanding the initialism you'd need to use Acronyms.Expand. Type Text_Soup(<>) is tagged private; procedure Output( Stream : not null access Ada.Streams.Root_Stream_Type'Class; Item : in Text_Soup'Class); function Input( Stream : not null access Ada.Streams.Root_Stream_Type'Class) return Text_Soup'Class; -- Other public operations. PRIVATE For Text_Soup'Class'Input use Input; For Text_Soup'Class'Output use Output; Type Text_Soup(Length : Natural) is record case Length is when 0 =3D> Acronym : Initialism; when others =3D> Text : String(1..Length); end case; end record; --...