ForEach and traversal methods in OOP data structures 
Author Message
 ForEach and traversal methods in OOP data structures

Hello World.

        I've got a problem with traversal of data structures. I've implemented
many data types as descendants of the abstract  DataObjectType object.
DataObjectType provides a basic set
of methods, for example Traverse and ForEach:

        procedure ForEach (Task : pointer);
        procedure Traverse (Start, Stop : word; Task : pointer);

For each calls a procedure, method or function (far-declared maybe)
that performs a task. The declaration of the task procedure is;

        procedure MyTask (var Data; var Continue : boolean);

Data contains element data from the data structure. Continue is set
to TRUE if the procedure would like to abort the traversal, for
example when an element has been located.

Turbo Vision uses a strange way of calling an Action pointer that
is assumed to be far declared. I'm not very good at assembler
programming, so I've just guessed what Turbo Vision ForEach does. I
would like a similair procedure that uses the following;

        procedure ElementPointer (Index : word) : pointer;
                Method that returns pointer to element data
        procedure Elements : word;
                Number of elements

It should not be impossible. Could some one help me please? For
some reason so far my own invetions all have crashed my programs,
for example in the code;

        procedure MyTask (var Data : string; var Continue : boolean);
        begin
                GlobalObject.Display (Data);
                if EventHandler.UserAbort then Continue := FALSE;
        end;

        ...



/J




Wed, 27 Jan 1999 03:00:00 GMT  
 ForEach and traversal methods in OOP data structures

Quote:

> Hello World.

>         I've got a problem with traversal of data structures. I've implemented
> many data types as descendants of the abstract  DataObjectType object.
> DataObjectType provides a basic set
> of methods, for example Traverse and ForEach:
>      This may not be a direct answer to your question, but I hope it is helpful anyway.

     It sounds to me like your question can be rephrased as "How do I apply some operation
to each element of a complex data structure?"  I had encountered this problem once with a
structure I'd built as a tree-like set of linked lists, then having to compute some function
on each element of the list.  I basically wrote a routine called "DoOncePerItem" that was
passed the root of my data structure and a Procedure variable.  It was the job of "DoOncePerItem"
to know how to traverse my structure -- as it found each element, it applied the passed procedure
to that element.  [Did that make sense?].  It was all done with Standard Pascal, and worked very
nicely.

Bob Schor
Pascal Enthusiast



Wed, 27 Jan 1999 03:00:00 GMT  
 ForEach and traversal methods in OOP data structures

Hi,

Quote:
> It sounds to me like your question can be rephrased as "How do I apply some operation
> to each element of a complex data structure?"  I had encountered this problem once with a
> structure I'd built as a tree-like set of linked lists, then having to compute some function
> on each element of the list.  I basically wrote a routine called "DoOncePerItem" that was
> passed the root of my data structure and a Procedure variable.  It was the job of "DoOncePerItem"
> to know how to traverse my structure -- as it found each element, it applied the passed procedure
> to that element.  [Did that make sense?].  It was all done with Standard Pascal, and worked very
> nicely.

        The only difference between your procedure and the one I
would like in my program, is that I would like both a "procedure
ForEach (Task : pointer)" and a "procedure Traverse (Start, Stop
: word; Task : pointer)". That is, I would like to perform
tasks for all elements (ForEach) in straight forward order, _or_
I would like to traverse some of the elements backward (5, 1, Task)
or forward (1, 5, Task).

        It seems like you have to know a lot about assembler calls
to procedures and how methods are designed (I guess you'd have to
write an entire method in assembler). Turbo Vision uses a common
"CALL" instruction. But shouldn't it be "FAR CALL"?

Still looking help with this matter!!!

/J




Thu, 28 Jan 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. ForEach and traversal methods in OOP data structures

2. Define data structure for graph (abstract data structures)

3. HELP! ForEach/FirstThat methods

4. HELP! ForEach/FirstThat methods

5. TASM data structures to Pascal data types

6. Really posting data, what method?

7. Programming tool in OOP featuring data structures, streams ... whatever!!!

8. Programming tool in OOP featuring data structures, streams ... whatever!!!

9. data structure

10. D1: Help - large data structures

11. Data structure corruption.

12. Data Structure source code for all to share?

 

 
Powered by phpBB® Forum Software