* Re: Inter-object pointer problem [not found] <1147806613.377038.169250@j33g2000cwa.googlegroups.com> @ 2006-05-16 19:58 ` Georg Bauhaus 2006-05-16 20:09 ` Jeffrey R. Carter 2006-05-16 20:27 ` Martin Dowie 2 siblings, 0 replies; 4+ messages in thread From: Georg Bauhaus @ 2006-05-16 19:58 UTC (permalink / raw) Alex Catlin wrote: > Say I have Packages A and B, implementing data structure A and B > respectively. I want to create a new B everytime I call a certain > procedure, and insert a pointer to that data structure Do you mean, a pointer to a package instance? > The problem is that generic package A is expecting to be instantiated > with an access type, but the Ptr_B doesnt exist until I have called > procedure X. Is there a reason that you are instantiating the package inside the procedure? > If this were C I would instantiate A_Structure as a static > type In this case your idea and the use of a generic _package_ do not correspond so well, I'd say. But I might have misunderstood your description of problem and solution. Could you clarify a bit, e.g. "structure" is a rather ambigous term, used in C, ML, and elsewhere, meaning different things. But it's not clear (to me at least) what it is supposed to mean here. Do you have a slightly more specified example, one that could be compiled, if not successful? ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Inter-object pointer problem [not found] <1147806613.377038.169250@j33g2000cwa.googlegroups.com> 2006-05-16 19:58 ` Inter-object pointer problem Georg Bauhaus @ 2006-05-16 20:09 ` Jeffrey R. Carter [not found] ` <1147816421.575165.66310@j33g2000cwa.googlegroups.com> 2006-05-16 20:27 ` Martin Dowie 2 siblings, 1 reply; 4+ messages in thread From: Jeffrey R. Carter @ 2006-05-16 20:09 UTC (permalink / raw) Alex Catlin wrote: > > The problem is that generic package A is expecting to be instantiated > with an access type, but the Ptr_B doesnt exist until I have called > procedure X. If this were C I would instantiate A_Structure as a static > type during procedure X so it didn't keep making new A's every call, > but I dont think I can do that in ADA. Is there a fix based on some > concept i'm completely missing or am I going to have to completely > change the organisation of the program? This is so far from being correct Ada that it's impossible to tell what you're trying to do, but I'd suggest you pull the instantiation of B_Pkg out of the procedure. If you can provide a better example, with information such as the specifications of the packages and the definition of B_Pointer_Type, we can probably help you better. It's likely you don't need access types or values at all outside the packages; pointers are needed far less often in Ada than in C (compiler writers excepted). Finally, "Ada" is a woman's name, not the American Dental Association (or other acronym). People on c.l.a get more or less upset with others who don't capitalize it correctly. -- Jeff Carter "If you don't get the President of the United States on that phone, ... you're going to have to answer to the Coca-Cola Company." Dr. Strangelove 32 ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <1147816421.575165.66310@j33g2000cwa.googlegroups.com>]
* Re: Inter-object pointer problem [not found] ` <1147816421.575165.66310@j33g2000cwa.googlegroups.com> @ 2006-05-17 2:03 ` Jeffrey R. Carter 0 siblings, 0 replies; 4+ messages in thread From: Jeffrey R. Carter @ 2006-05-17 2:03 UTC (permalink / raw) Alex Catlin wrote: > > I have a pairing heap package, I'm going to store a load of integers in > multiple pairing heaps. > I have a binary tree package, I want to store pointers to these > different heaps in the binary tree. The idea is that I can search > through the binary tree (sorted by key), and find out which heap the > Personal_Data is with that ID. Why pointers? Why not the heaps themselves? > with Ada.Text_IO, RB_Tree_Package, Pairing_Heap; > > package body Main is > > --The tree package needs a pointer to a heap datatype to be > instantiated > --One (obviously invalid) way would be to put > Pairing_Heap.Heap_Ptr in here. package Personal_Data_Heap is new Pairing_Heap (Personal_Data); -- I assume Personal_Data is visible, since you use it that way -- later. > package RB_Tree is new RB_Tree_Package(Key, *a pointer to a heap*); "Key" is undefined here, and later you want to use Integer for your key. package RB_Tree is new RB_Tree_Package (Integer, Personal_Data_Heap.Pairing_Heap); > Group_Tree : RB_Tree.Red_Black_Tree; > > --Create new heap, put Personal_Data in it, then put key field and > pointer to the > --new heap in tree. > procedure Process (Key : in Integer; > Data : in Integer) is > New_Entry : Personal_Data := (Key, Data); > package Heap is new Pairing_Heap (Personal_Data); > type Heap_Ptr is access Heap; Get rid of Heap and Heap_Ptr. Note you cannot have a pointer to a package. Heap : Personal_Data_Heap.Pairing_Heap; > begin > Ptr_To_Heap := Heap; > Heap.Insert(Heap,Personal_Data); > RB_Tree.Insert( T => Group_Tree, > Key => Key, > Content => Ptr_To_Heap); Nor can you pass a type (Personal_Data) to a procedure. Personal_Data_Heap.Insert (Main_Heap => Heap, D => New_Entry); RB_Tree.Insert (T => Group_Tree, Key => Key, Content => Heap); > end Process; > end Main; It would help to have the spec of Main. Note that you have exactly one pair in each heap, so why not simply store the pair in the tree and skip the heap altogether: package RB_Tree is new RB_Tree_Package (Integer, Personal_Data); ... RB_Tree.Insert (T => Group_Tree, Key => Key, Content => New_Entry); ? -- Jeff Carter "If you don't get the President of the United States on that phone, ... you're going to have to answer to the Coca-Cola Company." Dr. Strangelove 32 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Inter-object pointer problem [not found] <1147806613.377038.169250@j33g2000cwa.googlegroups.com> 2006-05-16 19:58 ` Inter-object pointer problem Georg Bauhaus 2006-05-16 20:09 ` Jeffrey R. Carter @ 2006-05-16 20:27 ` Martin Dowie 2 siblings, 0 replies; 4+ messages in thread From: Martin Dowie @ 2006-05-16 20:27 UTC (permalink / raw) Alex Catlin wrote: > Say I have Packages A and B, implementing data structure A and B > respectively. I want to create a new B everytime I call a certain > procedure, and insert a pointer to that data structure into the main > data structure A to keep track of all these B's flying around. > > I'm trying something like: > > with A_Pkg, B_Pkg; > ..... > package A_Structure is new A_Pkg (B_Pointer_Type); > B_List : A_Structure; > > procedure X (Data : in Data_Type) is > package B_Structure is new B_Pkg; > New_B : B_Structure > Ptr_B is access New_B; > begin > B_Structure.Insert(B_Structure,Data); > B_List.Insert(B_List,Ptr_B); > end X; > ..... > > The problem is that generic package A is expecting to be instantiated > with an access type, but the Ptr_B doesnt exist until I have called > procedure X. If this were C I would instantiate A_Structure as a static > type during procedure X so it didn't keep making new A's every call, > but I dont think I can do that in ADA. Is there a fix based on some > concept i'm completely missing or am I going to have to completely > change the organisation of the program? > I'd be grateful if anyone could point me in the direction of something > to try, Thanks. > If you want to have a container holding lots of "B"'s and call that container an "A" then try the new Ada.Container.* hierarchy in Ada2005 (there are 'backports' to Ada95 out there if you have even a gentle look). Only you wouldn't be inserting a pointer to a "B" in the structure "A" but an "Iterator". Cheers -- Martin p.s. As other have pointed out, your example highlights some serious misconception about Ada - but at least Ada is fun to learn! :-) ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-05-17 2:03 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <1147806613.377038.169250@j33g2000cwa.googlegroups.com> 2006-05-16 19:58 ` Inter-object pointer problem Georg Bauhaus 2006-05-16 20:09 ` Jeffrey R. Carter [not found] ` <1147816421.575165.66310@j33g2000cwa.googlegroups.com> 2006-05-17 2:03 ` Jeffrey R. Carter 2006-05-16 20:27 ` Martin Dowie
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox