-- --
-- S p e c --
-- --
--- Copyright (C) 2004-2011, Free Software Foundation, Inc. --
+-- Copyright (C) 2011, Free Software Foundation, Inc. --
-- --
-- This specification is derived from the Ada Reference Manual for use with --
-- GNAT. The copyright notice above, and the license provisions that follow --
-- This unit was originally developed by Matthew J Heaney. --
------------------------------------------------------------------------------
+with Ada.Iterator_Interfaces;
private with Ada.Streams;
generic
pragma Pure;
pragma Remote_Types;
- type Tree (Capacity : Count_Type) is tagged private;
+ type Tree (Capacity : Count_Type) is tagged private
+ with Constant_Indexing => Constant_Reference,
+ Variable_Indexing => Reference,
+ Default_Iterator => Iterate,
+ Iterator_Element => Element_Type;
pragma Preelaborable_Initialization (Tree);
type Cursor is private;
Empty_Tree : constant Tree;
No_Element : constant Cursor;
+ function Has_Element (Position : Cursor) return Boolean;
+
+ package Tree_Iterator_Interfaces is new
+ Ada.Iterator_Interfaces (Cursor, Has_Element);
function Equal_Subtree
(Left_Position : Cursor;
Position : Cursor;
Process : not null access procedure (Element : in out Element_Type));
+ type Constant_Reference_Type
+ (Element : not null access constant Element_Type) is private
+ with Implicit_Dereference => Element;
+
+ type Reference_Type
+ (Element : not null access Element_Type) is private
+ with Implicit_Dereference => Element;
+
procedure Assign (Target : in out Tree; Source : Tree);
function Copy (Source : Tree; Capacity : Count_Type := 0) return Tree;
-- This version of the AI:
-- 10-06-02 AI05-0136-1/07
- -- declares Find_In_Subtree with a Container parameter,
- -- but this seems incorrect. We need a ruling from the
- -- ARG about whether this really was intended. ???
+ -- declares Find_In_Subtree this way:
+ --
+ -- function Find_In_Subtree
+ -- (Container : Tree;
+ -- Item : Element_Type;
+ -- Position : Cursor) return Cursor;
+ --
+ -- It seems that the Container parameter is there by mistake, but we need
+ -- an official ruling from the ARG. ???
function Find_In_Subtree
- (Container : Tree;
- Item : Element_Type;
- Position : Cursor) return Cursor;
+ (Position : Cursor;
+ Item : Element_Type) return Cursor;
+
+ -- This version of the AI:
+ -- 10-06-02 AI05-0136-1/07
+ -- declares Ancestor_Find this way:
+ --
+ -- function Ancestor_Find
+ -- (Container : Tree;
+ -- Item : Element_Type;
+ -- Position : Cursor) return Cursor;
+ --
+ -- It seems that the Container parameter is there by mistake, but we need
+ -- an official ruling from the ARG. ???
function Ancestor_Find
- (Container : Tree;
- Item : Element_Type;
- Position : Cursor) return Cursor;
+ (Position : Cursor;
+ Item : Element_Type) return Cursor;
function Contains
(Container : Tree;
Item : Element_Type) return Boolean;
- function Has_Element (Position : Cursor) return Boolean;
-
procedure Iterate
(Container : Tree;
Process : not null access procedure (Position : Cursor));
(Position : Cursor;
Process : not null access procedure (Position : Cursor));
+ function Iterate (Container : Tree)
+ return Tree_Iterator_Interfaces.Forward_Iterator'Class;
+
+ function Iterate_Subtree (Position : Cursor)
+ return Tree_Iterator_Interfaces.Forward_Iterator'Class;
+
+ function Iterate_Children
+ (Container : Tree;
+ Parent : Cursor)
+ return Tree_Iterator_Interfaces.Reversible_Iterator'Class;
+
function Child_Count (Parent : Cursor) return Count_Type;
function Child_Depth (Parent, Child : Cursor) return Count_Type;
Position : Cursor);
procedure Splice_Children
- (Target : in out Tree;
- Target_Parent : Cursor;
- Before : Cursor;
- Source : in out Tree;
- Source_Parent : Cursor);
+ (Target : in out Tree;
+ Target_Parent : Cursor;
+ Before : Cursor;
+ Source : in out Tree;
+ Source_Parent : Cursor);
procedure Splice_Children
(Container : in out Tree;
procedure Previous_Sibling (Position : in out Cursor);
-- This version of the AI:
+
-- 10-06-02 AI05-0136-1/07
+
-- declares Iterate_Children this way:
- --
+
-- procedure Iterate_Children
-- (Container : Tree;
-- Parent : Cursor;
-- Process : not null access procedure (Position : Cursor));
- --
- -- It seems that the Container parameter is there by mistake, but
- -- we need an official ruling from the ARG. ???
+
+ -- It seems that the Container parameter is there by mistake, but we need
+ -- an official ruling from the ARG. ???
procedure Iterate_Children
(Parent : Cursor;
Process : not null access procedure (Position : Cursor));
private
+ use Ada.Streams;
type Children_Type is record
First : Count_Type'Base;
end record;
type Tree_Node_Array is array (Count_Type range <>) of Tree_Node_Type;
- type Element_Array is array (Count_Type range <>) of Element_Type;
+ type Element_Array is array (Count_Type range <>) of aliased Element_Type;
type Tree (Capacity : Count_Type) is tagged record
Nodes : Tree_Node_Array (0 .. Capacity) := (others => <>);
Count : Count_Type := 0;
end record;
- use Ada.Streams;
-
procedure Write
(Stream : not null access Root_Stream_Type'Class;
Container : Tree);
Node : Count_Type'Base := -1;
end record;
+ procedure Read
+ (Stream : not null access Root_Stream_Type'Class;
+ Position : out Cursor);
+ for Cursor'Read use Read;
+
procedure Write
(Stream : not null access Root_Stream_Type'Class;
Position : Cursor);
-
for Cursor'Write use Write;
+ type Constant_Reference_Type
+ (Element : not null access constant Element_Type) is null record;
+
+ procedure Write
+ (Stream : not null access Root_Stream_Type'Class;
+ Item : Constant_Reference_Type);
+ for Constant_Reference_Type'Write use Write;
+
procedure Read
- (Stream : not null access Root_Stream_Type'Class;
- Position : out Cursor);
+ (Stream : not null access Root_Stream_Type'Class;
+ Item : out Constant_Reference_Type);
+ for Constant_Reference_Type'Read use Read;
- for Cursor'Read use Read;
+ type Reference_Type
+ (Element : not null access Element_Type) is null record;
+ procedure Write
+ (Stream : not null access Root_Stream_Type'Class;
+ Item : Reference_Type);
+ for Reference_Type'Write use Write;
+
+ procedure Read
+ (Stream : not null access Root_Stream_Type'Class;
+ Item : out Reference_Type);
+ for Reference_Type'Read use Read;
+
+ function Constant_Reference
+ (Container : aliased Tree;
+ Position : Cursor) return Constant_Reference_Type;
+
+ function Reference
+ (Container : aliased Tree;
+ Position : Cursor) return Reference_Type;
- Empty_Tree : constant Tree := Tree'(Capacity => 0, others => <>);
+ Empty_Tree : constant Tree := (Capacity => 0, others => <>);
No_Element : constant Cursor := Cursor'(others => <>);