File: alog-controlled_map.ads

## Documentation

Table of Contents
Class Inheritance Tree

1.     --

2.     --  Copyright (c) 2009,

3.     --  Reto Buerki, Adrian-Ken Rueegsegger

4.     --

5.     --  This file is part of Alog.

6.     --

7.     --  Alog is free software; you can redistribute it and/or modify

8.     --  it under the terms of the GNU Lesser General Public License as published

9.     --  by the Free Software Foundation; either version 2.1 of the License, or

10.     --  (at your option) any later version.

11.     --

12.     --  Alog is distributed in the hope that it will be useful,

13.     --  but WITHOUT ANY WARRANTY; without even the implied warranty of

14.     --  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

15.     --  GNU Lesser General Public License for more details.

16.     --

17.     --  You should have received a copy of the GNU Lesser General Public License

18.     --  along with Alog; if not, write to the Free Software

19.     --  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,

20.     --  MA  02110-1301  USA

21.     --

23.     with Ada.Finalization;

24.     with Ada.Containers.Indefinite_Ordered_Maps;

26.     generic

27.        type Key_Type (<>) is private;

28.        type Element_Type (<>) is limited private;

29.        type Element_Handle is access Element_TypeTo API docTo spec;

31.        with function "<" (Left, Right : Key_TypeTo API docTo spec) return Boolean is <>;

33.     --  Controlled variant of a map. The memory of an element pointed to by a

34.     --  previously inserted handle is freed upon calling Delete, Clear or during

35.     --  finalization of the controlled map. Thus control over objects inserted into

36.     --  this map resides with the controlled map.

37.     package Alog.Controlled_MapTo API docTo specTo body is

39.        pragma Preelaborate;

41.        type MapTo API docTo body is new Ada.Finalization.Limited_Controlled with private;

42.        --  A controlled map container.

44.        procedure InsertTo API docTo body

45.          (ContainerTo API docTo body : in out MapTo API docTo specTo body;

46.           KeyTo API docTo body       :        Key_TypeTo API docTo spec;

47.           New_Item  :        Element_HandleTo API docTo spec);

48.        --  Insert a new element handle with 'Key' into the controlled map.

50.        function ElementTo API docTo body

51.          (ContainerTo API docTo body : MapTo API docTo specTo body;

52.           KeyTo API docTo body       : Key_TypeTo API docTo spec)

53.           return Element_HandleTo API docTo spec;

54.        --  Return a handle to an element identified by 'Key'.

56.        procedure DeleteTo API docTo body

57.          (ContainerTo API docTo body : in out MapTo API docTo specTo body;

58.           KeyTo API docTo body       :        Key_TypeTo API docTo spec);

59.        --  Delete the element with key 'Key' from the map. Memory of the element is

60.        --  freed.

62.        function ContainsTo API docTo body

63.          (ContainerTo API docTo body : MapTo API docTo specTo body;

64.           KeyTo API docTo body       : Key_TypeTo API docTo spec)

65.           return Boolean;

66.        --  Returns True if an element with key 'Key' is in the map.

68.        function Is_EmptyTo API docTo body (ContainerTo API docTo body : MapTo API docTo specTo body) return Boolean;

69.        --  Returns True if the map is empty.

71.        procedure ClearTo API docTo body (ContainerTo API docTo body : in out MapTo API docTo specTo body);

72.        --  Remove all elements in the map. Memory of the elements is freed.

74.        function LengthTo API docTo body (ContainerTo API docTo body : MapTo API docTo specTo body) return Natural;

75.        --  Return the current element count.

77.        procedure IterateTo API docTo body

78.          (ContainerTo API docTo body : MapTo API docTo specTo body;

79.           Process   : not null access procedure (Handle : Element_HandleTo API docTo spec));

80.        --  Iterate over all elements in the map and call the 'Process' procedure

81.        --  for each handle.

83.     private

85.        overriding

86.        procedure Finalize (Container : in out MapTo API docTo specTo body);

87.        --  Clean up the the controlled map. This will Free all the memory occupied

88.        --  by the elements in the map.

90.        package Map_Of_Elements_Package is new

91.          Ada.Containers.Indefinite_Ordered_Maps

92.            (Key_Type     => Key_TypeTo API docTo spec,

93.             Element_Type => Element_HandleTo API docTo spec);

95.        package MOEP renames Map_Of_Elements_Package;

97.        type MapTo API docTo spec is new Ada.Finalization.Limited_Controlled with record

98.           Data : MOEP.Map;

99.        end record;

101.     end Alog.Controlled_MapTo API docTo specTo body;