Added new arguments to configuration::find_parameter() to allow for a list of
[AXE.git] / src / configuration.h
1 /**************************************************************************
2 **  (c) Copyright 2002, Andromeda Technology & Automation
3 ***************************************************************************
4 ** MODULE INFORMATION *
5 ***********************
6 **      FILE NAME      : configuration.h
7 **      SYSTEM NAME    : AXE - Andromeda X-windows Encapsulation
8 **      VERSION NUMBER : $Revision: 1.4 $
9 **
10 **  DESCRIPTION      : Definition of configuration class 
11 **
12 **  EXPORTED OBJECTS : class configuration
13 **  LOCAL    OBJECTS : 
14 **  MODULES  USED    : String
15 ***************************************************************************
16 **  ADMINISTRATIVE INFORMATION *
17 ********************************
18 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
19 **      CREATION DATE   : Nov 02, 2002
20 **      LAST UPDATE     : 
21 **      MODIFICATIONS   : 
22 **************************************************************************/
23
24 /*****************************
25    $Log: configuration.h,v $
26    Revision 1.4  2007-05-04 14:01:22  arjen
27    Added new arguments to configuration::find_parameter() to allow for a list of
28    sections and a list of parameters in sections.
29    The new arguments are section index and parameter index (default = 0).
30
31    Revision 1.3  2002/11/02 14:35:15  arjen
32    Uses the XML2 library
33    BugFix: segfault when finding a parameters that is not in the user-sepcific
34    config tree.
35
36    Revision 1.2  2002/09/02 06:18:20  arjen
37    Fixed some date and time conversion functions
38
39    Revision 1.1  2002/07/25 08:01:26  arjen
40    First checkin, AXE release 0.2
41
42 *****************************/
43
44 /* static const char *RCSID = "$Id: configuration.h,v 1.4 2007-05-04 14:01:22 arjen Exp $"; */
45
46 #ifndef CONFIGURATION_H
47 #define CONFIGURATION_H
48
49 #include <libxml/parser.h>   // usually in /usr/include/libxml2, see xml2-config
50
51 #include "String.h"
52
53 /*
54 ///////////////////////////////////////////////////////////////////////////
55 //  NAME           : configuration
56 //  BASECLASS      :
57 //  MEMBERS        : 
58 //  OPERATORS      :
59 //  METHODS        : read
60 //                   find_parameter
61 //
62 //  DESCRIPTION    : Handle configurational parameters for the application.
63 //                   Many applications need some permanently stored configurational
64 //                   data. The information is usually stored in two places: A system-
65 //                   wide configuration file and a configuration file per user.
66 //                   The content of the configuration file is in XML format.
67 //                   The configuration base class takes care of finding the configuration
68 //                   files, e.g. in /etc/app.conf or in /usr/local/etc/app.conf, along
69 //                   with the configuration file in the user's home directory.
70 //                   The config files are parsed with the gnome XML parser and a
71 //                   framework is provided to find configurational items.
72 //
73 //  RELATIONS      : 
74 //  SEE ALSO       :
75 //  LAST MODIFIED  : Apr 13, 2007
76 ///////////////////////////////////////////////////////////////////////////
77 */
78
79 class configuration
80 {
81
82    xmlDocPtr     system;   // The system-wide config tree
83    xmlDocPtr     user;     // User-specific config tree
84    String        app_name; // Name of the application and XML root element
85
86    xmlNodePtr    xmlFindTag(xmlNodePtr, const String, int n = 0);
87
88 public:
89
90    configuration()
91    {
92       system  = NULL;
93       user    = NULL;
94       app_name = "AXE";
95    }
96
97    //  Find the config files and parse the XML
98
99    bool read(const String name);
100
101    //  Return the value of a config parameter
102
103    String find_parameter(const String section, const String parameter, int sec_n = 0, int param_n = 0);
104
105 };
106
107 #endif // CONFIGURATION_H