OSDN Git Service

Nathanael Nerode <neroden@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / ada / g-regist.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                         G N A T . R E G I S T R Y                        --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --                                                                          --
10 --              Copyright (C) 2001 Free Software Foundation, Inc.           --
11 --                                                                          --
12 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
13 -- terms of the  GNU General Public License as published  by the Free Soft- --
14 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
15 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
18 -- for  more details.  You should have  received  a copy of the GNU General --
19 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
20 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
21 -- MA 02111-1307, USA.                                                      --
22 --                                                                          --
23 -- As a special exception,  if other files  instantiate  generics from this --
24 -- unit, or you link  this unit with other files  to produce an executable, --
25 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
26 -- covered  by the  GNU  General  Public  License.  This exception does not --
27 -- however invalidate  any other reasons why  the executable file  might be --
28 -- covered by the  GNU Public License.                                      --
29 --                                                                          --
30 -- Extensive contributions were provided by Ada Core Technologies Inc.   --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 --  The registry is a Windows database to store key/value pair. It is used
35 --  to keep Windows operation system and applications configuration options.
36 --  The database is a hierarchal set of key and for each key a value can
37 --  be associated. This package provides high level routines to deal with
38 --  the Windows registry. For full registry API, but at a lower level of
39 --  abstraction, refer to the Win32.Winreg package provided with the
40 --  Win32Ada binding. For example this binding handle only key values of
41 --  type Standard.String.
42
43 --  This package is specific to the NT version of GNAT, and is not available
44 --  on any other platforms.
45
46 package GNAT.Registry is
47
48    type HKEY is private;
49    --  HKEY is a handle to a registry key, including standard registry keys:
50    --  HKEY_CLASSES_ROOT, HKEY_CURRENT_CONFIG, HKEY_CURRENT_USER,
51    --  HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_PERFORMANCE_DATA.
52
53    HKEY_CLASSES_ROOT     : constant HKEY;
54    HKEY_CURRENT_USER     : constant HKEY;
55    HKEY_CURRENT_CONFIG   : constant HKEY;
56    HKEY_LOCAL_MACHINE    : constant HKEY;
57    HKEY_USERS            : constant HKEY;
58    HKEY_PERFORMANCE_DATA : constant HKEY;
59
60    type Key_Mode is (Read_Only, Read_Write);
61    --  Access mode for the registry key.
62
63    Registry_Error : exception;
64    --  Registry_Error is raises by all routines below if a problem occurs
65    --  (key cannot be opened, key cannot be found etc).
66
67    function Create_Key
68      (From_Key : HKEY;
69       Sub_Key  : String;
70       Mode     : Key_Mode := Read_Write)
71       return     HKEY;
72    --  Open or create a key (named Sub_Key) in the Windows registry database.
73    --  The key will be created under key From_Key. It returns the key handle.
74    --  From_Key must be a valid handle to an already opened key or one of
75    --  the standard keys identified by HKEY declarations above.
76
77    function Open_Key
78      (From_Key : HKEY;
79       Sub_Key  : String;
80       Mode     : Key_Mode := Read_Only)
81       return     HKEY;
82    --  Return a registry key handle for key named Sub_Key opened under key
83    --  From_Key. It is possible to open a key at any level in the registry
84    --  tree in a single call to Open_Key.
85
86    procedure Close_Key (Key : HKEY);
87    --  Close registry key handle. All resources used by Key are released.
88
89    function Key_Exists (From_Key : HKEY; Sub_Key : String) return Boolean;
90    --  Returns True if Sub_Key is defined under From_Key in the registry.
91
92    function Query_Value (From_Key : HKEY; Sub_Key : String) return String;
93    --  Returns the registry key's value associated with Sub_Key in From_Key
94    --  registry key.
95
96    procedure Set_Value (From_Key : HKEY; Sub_Key : String; Value : String);
97    --  Add the pair (Sub_Key, Value) into From_Key registry key.
98
99    procedure Delete_Key (From_Key : HKEY; Sub_Key : String);
100    --  Remove Sub_Key from the registry key From_Key.
101
102    procedure Delete_Value (From_Key : HKEY; Sub_Key : String);
103    --  Remove the named value Sub_Key from the registry key From_Key.
104
105    generic
106       with procedure Action
107         (Index   : Positive;
108          Sub_Key : String;
109          Value   : String;
110          Quit    : in out Boolean);
111    procedure For_Every_Key_Value (From_Key : HKEY);
112    --  Iterates over all the pairs (Sub_Key, Value) registered under
113    --  From_Key. Index will be set to 1 for the first key and will be
114    --  incremented by one in each iteration. Quit can be set to True to
115    --  stop iteration; its initial value is False.
116    --
117    --  Key value that are not of type string are skipped. In this case, the
118    --  iterator behaves exactly as if the key was not present. Note that you
119    --  must use the Win32.Winreg API to deal with this case.
120
121 private
122
123    type HKEY is mod 2 ** Integer'Size;
124
125    HKEY_CLASSES_ROOT     : constant HKEY := 16#80000000#;
126    HKEY_CURRENT_USER     : constant HKEY := 16#80000001#;
127    HKEY_LOCAL_MACHINE    : constant HKEY := 16#80000002#;
128    HKEY_USERS            : constant HKEY := 16#80000003#;
129    HKEY_PERFORMANCE_DATA : constant HKEY := 16#80000004#;
130    HKEY_CURRENT_CONFIG   : constant HKEY := 16#80000005#;
131
132 end GNAT.Registry;