comp.lang.ada
 help / color / mirror / Atom feed
* Sequental IO and pointers
@ 2005-11-27  1:17 ejijott
  2005-11-27  1:19 ` ejijott
  2005-11-27 14:02 ` Stephen Leake
  0 siblings, 2 replies; 5+ messages in thread
From: ejijott @ 2005-11-27  1:17 UTC (permalink / raw)


pastebin snippet at http://pastebin.com/439265

I've posted before in this group and I would just like to say thanks
for all the help im getting :) .. dont want to clutter up posts with
replies of gratitude so... ah well, another question then :)

Can I actually export my Storage/Node types as defined in my code
snippet? Or would I have to add another type which is used to export
only the item, len and count variables and then when importing my data
I feed this in to my variable of type Storage?




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Sequental IO and pointers
  2005-11-27  1:17 Sequental IO and pointers ejijott
@ 2005-11-27  1:19 ` ejijott
  2005-11-27 14:02 ` Stephen Leake
  1 sibling, 0 replies; 5+ messages in thread
From: ejijott @ 2005-11-27  1:19 UTC (permalink / raw)


Oops, forgot that this is for an assignment in my CS class... so no
fiddling with their pre-packaged types/functions/procedures :)




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Sequental IO and pointers
  2005-11-27  1:17 Sequental IO and pointers ejijott
  2005-11-27  1:19 ` ejijott
@ 2005-11-27 14:02 ` Stephen Leake
  2005-11-27 18:10   ` ejijott
  1 sibling, 1 reply; 5+ messages in thread
From: Stephen Leake @ 2005-11-27 14:02 UTC (permalink / raw)


ejijott@gmail.com writes:

> pastebin snippet at http://pastebin.com/439265

For code this short, it is better to include it in the post, rather
than putting on a website; that makes it easier to refer to in replies.

> I've posted before in this group and I would just like to say thanks
> for all the help im getting :)

You're welcome - gratitude is appreciated :).

> Can I actually export my Storage/Node types as defined in my code
> snippet? 

Well, you can, but importing won't make sense; the pointers will not
be valid.

> Or would I have to add another type which is used to export only the
> item, len and count variables and then when importing my data I feed
> this in to my variable of type Storage?

You don't need another type, just modify Save to not output the
pointer. 

Then in Restore (which you don't show), you need to rebuild the linked
data structure. That is the hard part; how does Restore know what
objects are linked? Typically Save must output some object ID, which
is _not_ the pointer.

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Sequental IO and pointers
  2005-11-27 14:02 ` Stephen Leake
@ 2005-11-27 18:10   ` ejijott
  2005-11-27 18:54     ` ejijott
  0 siblings, 1 reply; 5+ messages in thread
From: ejijott @ 2005-11-27 18:10 UTC (permalink / raw)


Snippet of my (current) Load procedure:

>
    procedure Load(S: in out Storage; File: String) is
        package StorageIO is new Sequential_IO(Node);
        use StorageIO;
        fh_storage:StorageIO.File_type;
        import_node:Node;
    begin
        Open(fh_storage, Name=>file, Mode=>In_file);
        Read(fh_storage, import_node);
        S.next:=import_node;
        Close(fh_storage);
    end Load;
<

Would using Direct_IO be a better/other solution to use? What I
understand of that package is that you get indexing features to use.

> You don't need another type, just modify Save to not output the
> pointer.

How would I go about doing that, using a Node/Storage type for output?
Doesnt Write put the whole shebang into my binary file?




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Sequental IO and pointers
  2005-11-27 18:10   ` ejijott
@ 2005-11-27 18:54     ` ejijott
  0 siblings, 0 replies; 5+ messages in thread
From: ejijott @ 2005-11-27 18:54 UTC (permalink / raw)


As an ad hoc solution my Save and Load procedures now work, as follows:

>
    procedure Save(S: Storage; File: String) is
        type ord is record
                item:  string(1..50);
                len:   integer :=-1;
                count: integer := 0;
        end record;

        package OrdlistaIO is new Sequential_IO(ord);
        use OrdlistaIO;
        fh_ordlista:OrdlistaIO.File_type;
        tnode:Storage;
        ord_att_spara:ord;
    begin
        tnode:=S;
        Create(fh_ordlista, Name=>file);
        while tnode /= null loop
            ord_att_spara.item(1 .. tnode.len):=tnode.item(1 ..
tnode.len);
            ord_att_spara.len:=tnode.len;
            ord_att_spara.count:=tnode.count;
            Write(fh_ordlista, ord_att_spara);
            tnode:=tnode.next;
        end loop;

        close(fh_ordlista);
    end Save;

    procedure Load(S: in out Storage; File: String) is
        type ord is record
                item:  string(1..50);
                len:   integer :=-1;
                count: integer := 0;
        end record;

        package OrdlistaIO is new Sequential_IO(ord);
        use OrdlistaIO;
        fh_ordlista:OrdlistaIO.File_type;
        inläst_post:ord;
    begin
        Open(fh_ordlista, Name=>file, Mode=>In_file);
        while not END_OF_FILE(fh_ordlista) loop
            Read(fh_ordlista, inläst_post);
            for i in 1 .. inläst_post.count loop
                Append(S, inläst_post.item(1 .. inläst_post.len));
            end loop;
        end loop;
        Close(fh_ordlista);
    end Load;
<

The Append procedure adds my input record to the end of my linked list
and all is well... but still, something tells me there should be some
sort of prettier/faster implementation to use here... In the assignment
we are supposed to make functions to read both normal textfiles
(strings after eachother) and binary files... I really dont see how a
simple thing like this could benefit from using binary files.




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-11-27 18:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-27  1:17 Sequental IO and pointers ejijott
2005-11-27  1:19 ` ejijott
2005-11-27 14:02 ` Stephen Leake
2005-11-27 18:10   ` ejijott
2005-11-27 18:54     ` ejijott

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