comp.lang.ada
 help / color / mirror / Atom feed
From: "markww" <markww@gmail.com>
Subject: Re: how to import a package
Date: 11 Dec 2006 19:19:44 -0800
Date: 2006-12-11T19:19:44-08:00	[thread overview]
Message-ID: <1165893584.829025.235440@l12g2000cwl.googlegroups.com> (raw)
In-Reply-To: <Abjfh.1093829$084.864157@attbi_s22>

Thanks all I think I got it now. Dmitry A. Kazakov, Adam Beneschan,
your posts really showed me how to set it up. Now I have all the list
functions as part of that package and it's working as expected for a
generic list.

I'm wondering still if it's possible to have a data member in the
package definition that serve as my start and end nodes. In C++ I'd do
something like:

    struct List {

        AddNode(...);
        DeleteNode(...);
        ...

        Node *pStart, *pEnd; // keeps track of start and end nodes for
a single list instance.
    }

am I allowed to do the same in my package definition? Then things would
be a lot neater. Right now I have the start and end pointers as
variables external to the package, so everytime I call AddNode() etc I
have to pass them through which is pretty sloppy. It looks like:

    generic
        type T is private;
    package Generic_List is
        type Node;
        type Node_Ptr is access Node;
        type Node is limited record -- We don't copy nodes
            Data : T;                -- The data in the node
            Prev : Node_Ptr;         -- Previous node, else null
            Next : Node_Ptr;         -- Next node, else null
         end record;

       procedure Add(Start : in out Node_Ptr; Last : in out Node_Ptr;
Data : T);
       procedure Delete(Start : in out Node_Ptr; Last : in out
Node_Ptr; nIndex : INTEGER);
       function GetNodeCount (Start : Node_Ptr) return INTEGER;
       function GetNode(Start : Node_Ptr; nIndex : INTEGER) return
Node_Ptr;
       function GetNodePosition(Start : Node_Ptr; MatchData : T) return
INTEGER;

      -- Something like:
      m_Start : Node_Ptr;
      m_Last : Node_Ptr;

   end Generic_List;

then externally I'd hope to use it like:

    GenericList.Add(T);

instead of what I'm doing now:

    GenericList.Add(Start, Last, T);

Thanks,
Mark

Jeffrey R. Carter wrote:
> markww wrote:
> >
> >     procedure Add_Record(GenericData : PERSON_REC) is
> >     Temp : gNode.Node_Ptr;
> >     begin
> >
> >         Temp := new gNode.Node;
> >         Temp.Data := GenericData;
> >     end Add_Record;
>
> This leaks memory.
>
> Others have discussed the solution to your specific problem, but I think
> what you're missing is the general mind-set that a type definition and
> the operations on that type should be encapsulated in a package. So far,
> you only have 1 operation (Add_Record), but in a generally useful
> linked-list package you'd probably have a lot more. Those operations
> should be in the package; then, whenever you instantiate the package,
> you get the operations.
>
> This concept, encapsulation of data and their operations (usually with
> hiding of the data's structure), is called "object orientedness". In
> many languages, this design concept is mixed up with the implementation
> concept of programming by extension (incorrectly called OOP); for
> example, in C++, you get both from the "class" construct. In Ada, the 2
> are separate.
>
> At this point, you might find it instructive to look at some existing
> linked-list packages, such as the one in the Ada-0X container library,
> or the ones in the PragmAda Reusable Components
>
> http://pragmada.home.mchsi.com/
>
> or many of the component libraries you can find at adapower.com or
> adaworld.com.
>
> --
> Jeff Carter
> "Blessed is just about anyone with a vested interest in the status quo."
> Monty Python's Life of Brian
> 73




  reply	other threads:[~2006-12-12  3:19 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-06  2:14 how to import a package markww
2006-12-06  3:06 ` Adam Beneschan
2006-12-06  3:34   ` markww
2006-12-06  9:18     ` Simon Wright
2006-12-06 19:47 ` Jeffrey R. Carter
2006-12-06 23:56   ` markww
2006-12-07  1:18     ` Björn Persson
2006-12-07  1:26     ` Brian May
2006-12-07  4:14       ` markww
2006-12-07  4:40         ` Brian May
2006-12-07  9:32           ` Stuart
2006-12-07 11:21             ` Jean-Pierre Rosen
2006-12-11  6:16               ` markww
2006-12-11  6:50                 ` markww
2006-12-11  9:40                   ` Georg Bauhaus
2006-12-11 14:19                     ` markww
2006-12-11 15:03                       ` Dmitry A. Kazakov
2006-12-11 16:22                       ` Adam Beneschan
2006-12-11 20:28                       ` Jeffrey R. Carter
2006-12-12  3:19                         ` markww [this message]
2006-12-12  3:31                           ` Jeffrey R. Carter
2006-12-12  9:03                           ` Stuart
2006-12-12 10:56                           ` Georg Bauhaus
2006-12-11  7:00                 ` Simon Wright
2006-12-07  4:06     ` Jeffrey R. Carter
replies disabled

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