Package: registry.file

Dependencies

   with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
   with GNAT.Dynamic_Tables; 
   with Ada.Text_IO; use Ada.Text_IO;
   with registry.sysdep; use registry.sysdep;

Description

This is the real implementation for registry informations stored in a file. This implementation sould work on all plattforms, however on windows the real registry access is preferred. The package registry.factory implements a Create function, wich returns always a suitable registry implementation

Header

package registry.file is
 

Type Summary

file_registry derived from registry_type
Overridden Operations:  Close, Create, Delete_Key, Delete_Section, Get, Get, Get_Keys, Get_Sections, Is_Open, Open, Put, Put, Set_Section
New Operations:  Init_Registry

Other Items:

type file_registry is new registry_type with private;

function Create(programm_name : String;s_access : sys_access) return file_registry;
Create a file-registry for programm_name with selected access.
programm_name : String Name of the programm or more general the name of the config file on Unix or Windows
s_access : sys_access If CLASS_USER the information is stored so that the normal user can access them. CLASS_SYSTEM indicates system wide access. The user can only read but not write this information. Only the administrator can read and write to this.

For opening a registry better use the Create function from the package registry.factory. This function returns a correct initialized instance of one of the subtypes of registry-file or registry-win.


procedure Put(reg : in out file_registry;
              key : in r_key;
              val : in String
             );
Store a key/value pair in the file-registry. If the key does not exists in the section, the key is created, otherwise the old value of the key is overwritten. The value is from type String.
reg : file_registry a with Create initialized handle of the registry
key : r_key The key name.
val : String The string value for the key.

procedure Put(reg : in out file_registry;
              key : in r_key;
              val : in Integer
             );
Store a key/value pair in the file-registry. If the key does not exists in the section, the key is created, otherwise the old value of the key is overwritten. The value is from type String.
reg : file_registry a with Create initialized handle of the registry
key : r_key The key name.
val : Integer The integer value for the key.

procedure Get(reg : in out file_registry;
              key : in r_key;
              val : out Unbounded_String
             );
Get a value from a key. In case that the key does not exists the exception REGISTRY_NO_KEY is raised;
reg : file_registry a with Create initialized handle of the registry.
key : r_key The key name.
val : Unbounded_String Returns the value from the key.

procedure Get(reg : in out file_registry;
              key : in r_key;
              val : out Integer
             );
Get a value from a key. In case that the key does not exists the exception REGISTRY_NO_KEY is raised;
reg : file_registry a with Create initialized handle of the registry.
key : r_key The key name.
val : integer Returns the value from the key.

function Get_Sections(reg : in file_registry)
return sectionTable;
Get all known sections.
reg : file_registry a with Create initialized handle of the registry.
Returns : secionTable An array of r_section with all sections of this registry.

function Get_Keys(reg : in file_registry) 
return keyTable;
get all known keys for the current section. If there is no key, raise REGISTRY_NO_KEY exception

procedure Open(reg : in out file_registry );
Open access to the registry
reg : file_registry a with Create initialized handle of the registry. Open reads and parses the configuration file and raises REGISTRY_SYNTAX_ERROR in case of an syntax error in the configuration file. A detailed error message can be retrieved via the Get_ErrorMessage function.

procedure Close(reg: in out file_registry);
Close access to the registry and write back all changes. The current configuration file is overwritten with new values
reg : file_registry a with Create initialized handle of the registry.

procedure Set_Section (reg : in out file_registry; s : in r_section);
Set a setion in the registry. If the section does not exists the section is created. A section is enclosed with [] within the registry file.
reg : registry_type a with Create initialized handle of the registry.
s : r_section A section name.

procedure Init_Registry(reg: in out file_registry;
                        a : in sys_access; p_name : in Unbounded_String;
                        def_home : String := Get_Home_Dir;
                        def_system : String := Get_Sys_Dir
                  );
Initialize the file Registry and overwrite the default settings for the path to the home and system configuration files
reg : file_registry The registry handle to initialize
s_access : sys_access If CLASS_USER the information is stored so that the normal user can access them. CLASS_SYSTEM indicates system wide access. The user can only read but not write this information. Only the administrator can read and write to this.
p_name : Unbounded_String The programm name.
def_home : String := Get_Home_Dir A new path for the directory for the user configuration file. Normaly this is the value of the enviroment variable HOME.
def_system : String := Get_Sys_Dir The direcory for the system wide configuration file. On Unix this defaults to /etc
Todo : Set suitable default on windows

function Is_Open(reg : in file_registry) return Boolean;
Check if the registry is opened;
reg : file_registry a with Create initialized handle of the registry.
Returns : boolean true if the registry is open.

procedure Delete_Key(reg : in out file_registry; key : in r_key);
Delete a key from the current section. In case that the key does not exists the exception REGISTRY_NO_KEY is raised.
reg : file_registry a with Create initialized handle of the registry.
key : r_key The key name to delete.

procedure Delete_Section(reg : in out file_registry; sec : in r_section);
Delete a complete section including all keys. The current section is set back to the empty default section. So after this command you must restore your previous default section via the Set_Section function. In case that the section does not exists the exception REGISTRY_NO_SECTION is raised.
reg : file_registry a with Create initialized handle of the registry.
sec : r_section The section name to delete.

private

   --  Implementation-defined ...
end registry.file;