File: alog-maps.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.Strings.Unbounded.Hash;

24.     with Ada.Containers.Hashed_Maps;

26.     --  Alog maps package. Provides map data types.

27.     package Alog.MapsTo API docTo specTo body is

29.        type Wildcard_Level_MapTo API docTo body is tagged private;

30.        --  A map of loglevels with string as key type.

32.        type CursorTo API docTo body is private;

33.        --  Index for a map element.

35.        No_ElementTo API docTo body : constant CursorTo API docTo specTo body;

37.        Wildcard   : constant Character := '*';

38.        --  Character used as wildcard indicator in lookups.

40.        function ElementTo API docTo body

41.          (MapTo API docTo body : Wildcard_Level_MapTo API docTo specTo body;

42.           Key : String)

43.           return Log_LevelTo API docTo spec;

44.        --  Returns the loglevel element for given key.

46.        function ElementTo API docTo body (PositionTo API docTo body : CursorTo API docTo specTo body) return Log_LevelTo API docTo spec;

47.        --  Returns the loglevel element at given position.

49.        function FindTo API docTo body

50.          (MapTo API docTo body : Wildcard_Level_MapTo API docTo specTo body;

51.           Key : String)

52.           return CursorTo API docTo specTo body;

53.        --  Returns the position for an element with specified key. If no element is

54.        --  found No_Element is returned.

56.        function LookupTo API docTo body

57.          (MapTo API docTo body : Wildcard_Level_MapTo API docTo specTo body;

58.           Key : String)

59.           return CursorTo API docTo specTo body;

60.        --  Returns the position of the element with the closest match to given key.

61.        --  This function considers wildcards when searching for an element.

62.        --

63.        --  Example:      Key   | Element

64.        --             -------------------

65.        --              Foo.*   |  Debug

66.        --              Foo.Bar |  Alert

67.        --

68.        --  A lookup for "Foo.Foo" has no exact match. The next closest match is

69.        --  "Foo.*" which will return the Debug element. Looking for "Foo" will

70.        --  return Debug since it matches the wildcard "Foo.*".

71.        --

72.        --  If no exact and wildcard match is found No_Element is returned.

74.        procedure InsertTo API docTo body

75.          (MapTo API docTo body  : in out Wildcard_Level_MapTo API docTo specTo body;

76.           Key  :        String;

77.           ItemTo API docTo body :        Log_LevelTo API docTo spec);

78.        --  Insert given key/item pair into map. If given key is already present the

79.        --  associated item is replaced.

81.        procedure ClearTo API docTo body (MapTo API docTo body : in out Wildcard_Level_MapTo API docTo specTo body);

82.        --  Clears the wildcard map.

84.        function LengthTo API docTo body (MapTo API docTo body : Wildcard_Level_MapTo API docTo specTo body) return Natural;

85.        --  Return the number of elements in the map.

87.     private

89.        use Ada.Strings.Unbounded;

91.        package Map_Of_Loglevels_Package is new Ada.Containers.Hashed_Maps

92.          (Key_Type        => Unbounded_String,

93.           Element_Type    => Log_LevelTo API docTo spec,

94.           Hash            => Hash,

95.           Equivalent_Keys => "=");

97.        package MOLP renames Map_Of_Loglevels_Package;

99.        type Wildcard_Level_MapTo API docTo spec is tagged record

100.           Data : MOLP.Map;

101.        end record;

103.        type CursorTo API docTo spec is new MOLP.Cursor;

105.        No_ElementTo API docTo spec : constant CursorTo API docTo specTo body := CursorTo API docTo specTo body (MOLP.No_Element);

107.     end Alog.MapsTo API docTo specTo body;