LogService
libdadi: utility tools for distributed applications
Options.hh
1 /****************************************************************************/
2 /* DIET forwarder implementation - Executable options */
3 /* */
4 /* Author(s): */
5 /* - Gael Le Mahec (gael.le.mahec@ens-lyon.fr) */
6 /* */
7 /* This file is part of DIET . */
8 /* */
9 /* Copyright (C) 2000-2003 ENS Lyon, LIFC, INSA, INRIA and SysFera (2000) */
10 /* */
11 /* - Frederic.Desprez@ens-lyon.fr (Project Manager) */
12 /* - Eddy.Caron@ens-lyon.fr (Technical Manager) */
13 /* - Tech@sysfera.com (Maintainer and Technical Support) */
14 /* */
15 /* This software is a computer program whose purpose is to provide an */
16 /* distributed logging services. */
17 /* */
18 /* */
19 /* This software is governed by the CeCILL license under French law and */
20 /* abiding by the rules of distribution of free software. You can use, */
21 /* modify and/ or redistribute the software under the terms of the CeCILL */
22 /* license as circulated by CEA, CNRS and INRIA at the following URL */
23 /* "http://www.cecill.info". */
24 /* */
25 /* As a counterpart to the access to the source code and rights to copy, */
26 /* modify and redistribute granted by the license, users are provided */
27 /* only with a limited warranty and the software's author, the holder */
28 /* of the economic rights, and the successive licensors have only */
29 /* limited liability. */
30 /* */
31 /* In this respect, the user's attention is drawn to the risks */
32 /* associated with loading, using, modifying and/or developing or */
33 /* reproducing the software by the user in light of its specific status */
34 /* of free software, that may mean that it is complicated to */
35 /* manipulate, and that also therefore means that it is reserved for */
36 /* developers and experienced professionals having in-depth computer */
37 /* knowledge. Users are therefore encouraged to load and test the */
38 /* software's suitability as regards their requirements in conditions */
39 /* enabling the security of their systems and/or data to be ensured and, */
40 /* more generally, to use and operate it in the same conditions as */
41 /* regards security. */
42 /* */
43 /* The fact that you are presently reading this means that you have had */
44 /* knowledge of the CeCILL license and that you accept its terms. */
45 /* */
46 /****************************************************************************/
47 #ifndef OPTIONS_HH
48 #define OPTIONS_HH
49 
50 #include <list>
51 #include <map>
52 #include <string>
53 
54 class Options;
55 
56 /* Standard configuration class. Used as an abstract class for parameters
57  * processing.
58  */
60 public:
61  Configuration();
62 
63  explicit Configuration(const std::string& pgName);
64 
65  const std::string&
66  getPgName() const;
67 
68  const std::string&
69  getConfigFile() const;
70 
71  void
72  setConfigFile(const std::string& configFile);
73 
74 private:
75  std::string pgName;
76  std::string configFile;
77 };
78 
79 /* Callback function type definition. */
80 typedef void (*optCallback)(const std::string&, Configuration*);
81 
82 /* Options class. Used to process the users command line parameters. */
83 /* This class is a generic command line parameters processing tool.
84  */
85 class Options {
86 public:
87  Options(Configuration* config, int argc, char* argv[], char* envp[] = NULL);
88 
89  void
90  setOptCallback(const std::string& arg, optCallback callBack);
91 
92  void
93  setEnvCallback(const std::string& arg, optCallback callBack);
94 
95  void
96  setParamCallback(unsigned int idx, optCallback callBack);
97 
98  void
99  setFlagCallback(const char flag, optCallback callBack);
100 
101  void
102  processOptions();
103 
104  void
105  processEnv();
106 
107 private:
108  Configuration* config;
109  std::map<std::string, std::string> arguments;
110  std::map<std::string, std::string> environment;
111  std::map<unsigned int, std::string> params;
112  std::list<std::string> singleArgs;
113  std::list<std::string> singleEnvs;
114  std::list<char> flags;
115  std::map<std::string, optCallback> optCallbacks;
116  std::map<std::string, optCallback> envCallbacks;
117  std::map<unsigned int, optCallback> paramCallbacks;
118  std::map<char, optCallback> flagCallbacks;
119 };
120 
121 /* A simple configuration file class.
122  * The file must respect the format:
123  * <attribute> = <value>
124  */
125 class ConfigFile {
126 public:
127  ConfigFile();
128 
129  explicit ConfigFile(const std::string& path);
130 
131  void
132  parseFile(const std::string& path);
133 
134  const std::string&
135  getAttr(const std::string& key);
136 
137 private:
138  std::map<std::string, std::string> attributes;
139 };
140 #endif
Definition: Options.hh:125
Definition: Options.hh:85
Definition: Options.hh:59