VICI  0.11.815
Visual Chart Interpreter
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
xini.h
Go to the documentation of this file.
1 /*
2  * xini.h
3  *
4  * Copyright 2009 - 2016 Brenton Ross
5  *
6  * This file is part of VICI.
7  *
8  * VICI is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * VICI is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with VICI. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
27 /*
28 Ini file, XML format, loaded by looking in the following locations:
29 
30  P = path provided on the command line.
31  E = path provided in the environment
32  C = the current working directory
33  H = the user's home directory
34  D = directories as listed
35 
36 Containing application must provide a string containing the
37 keys for the above search locations: eg
38 const string ini::config = "PECHD:-i:QM_CONF:qmd.xml:.qmd.xml:/etc/qmd/qmd.xml";
39 
40 The above will first look for a command line parameter following -i,
41 then it will look in the environment for a variable QM_CONF,
42 then in the current directory for a file called qmd.xml,
43 then for a file $HOME/.qmd.xml, and finally for /etc/qmd/qmd.xml
44 
45 Any further paths added at the end are checked in sequence.
46 */
47 
48 #ifndef CFI_XINI_H
49 #define CFI_XINI_H
50 
51 #include "xml.h"
52 
53 class XiniTestCase;
54 
55 namespace VICI
56 {
57 
58 namespace cfi
59 {
60 
62 
88 class XINI : private Xml
89 {
90  friend class ::XiniTestCase;
91 protected:
92  // static XINI *me; ///< pointer to single instance of class.
93  static int argc;
94  static char ** argv;
95  static Path configFile;
96  XINI();
97 
99  static const std::string config;
100 
101 private:
103 
107  VICI::Path searchConfigPath( csr conf);
108 
109 public:
111 
114  static void configure(const Path &p);
115 
117 
121  static void configure( int c, char ** v );
122 
124  static XINI & instance();
125 
127 
132  bool getVal( const std::string & xpath_expression, std::string &val );
133 
135 
140  int getVals( const std::string & xpath_expr, std::vector< std::string > &results );
141 
143 
147  void getPath( const std::string & xpath_expr, VICI::Path &path );
148 
150 
153  const Path & getConfigFilename() const;
154 };
155 
156 } // namespace cfi
157 } // end namespce VICI
158 
159 
160 #endif /* XINI_H_ */
XINI()
constructor
Definition: xini.cpp:44
static XINI & instance()
get a reference to the single instance of the class.
Definition: xini.cpp:194
static int argc
number of command line args
Definition: xini.h:93
const Path & getConfigFilename() const
get the name of the config file being used
Definition: xini.cpp:280
static const std::string config
configuration string defined by the using application using the format specified. ...
Definition: xini.h:99
Manipulate path strings.
Definition: stringy.h:74
A simple C++ wrapper for libxml2.
static void configure(const Path &p)
Configure XINI to use the specified path.
Definition: xini.cpp:174
bool getVal(const std::string &xpath_expression, std::string &val)
get a value from the config file.
Definition: xini.cpp:227
Load an XML configuration file.
Definition: xini.h:88
const std::string & csr
short cut for string constants
Definition: vici.h:80
static char ** argv
command line args
Definition: xini.h:94
A C++ wrapper for libxml2.
Definition: xml.h:73
void getPath(const std::string &xpath_expr, VICI::Path &path)
get a path from a set of paths
Definition: xini.cpp:258
int getVals(const std::string &xpath_expr, std::vector< std::string > &results)
get a set of values
Definition: xini.cpp:245
static Path configFile
path to config file
Definition: xini.h:95