*** empty log message ***
[h316.git] / pc-tools / ldc2 / src / configuration_manager.hh
index d88d3dd7959bad57227dbe6f4a37d959d2d78d14..0858c9bab2f1139958aca2de29c4ab798f70c093 100644 (file)
@@ -1,3 +1,17 @@
+/******************************************************************************
+ * 
+ * LDC2 source code
+ *
+ * $Date: 2007/03/26 01:00:38 $
+ * $Author: hachti $
+ *
+ * $Log: configuration_manager.hh,v $
+ * Revision 2.0  2007/03/26 01:00:38  hachti
+ * *** empty log message ***
+ *
+ *
+ ******************************************************************************/
 #ifndef ARGUMENT_READER_H
 #define ARGUMENT_READER_H
 
 using namespace std;
 
 /*!
- *\brief Hachti's wonderful commandline parser.
+ *\brief Hachti's even more wonderful configuration manager.
  *
  * This class is designed to do all the work with the parameters passed to 
  * the main() routine of a program.\n
+ * Additionally, it is able to interpret configuration files.
  * Usage:\n
  *   - Create an instance.
- *   - Add Parameters/switches with add_param().
+ *   - Add Parameters/switches with add_option_*().
  *   - Add Arguments with add_argument().
  *   - Call read_args() with your main routine's arguments.
  *     The vector returned by read_args() contains all error
  *     messages. When it's empty, everything is fine!
  *   - Call get_help() if you want nice formatted help output.
  *     (You want!!!)
- * Sould be easy to use..... Enjoy.
+ * Sould be easy to use....
  */
-class argument_reader{
+class configuration_manager{
   
-public:
-  argument_reader(string name);
-
-  void add_param (string  shortname, 
-                 string  longname, 
-                 string  description, 
-                 int    *status, 
-                 string *target=NULL, 
-                 string  placeholder=string("<string>")
-                 );
-  
-  vector<string> read_args(int argc, char ** args);
-  void get_help(vector<string> & target);
-  vector<string> get_help();
-
-  void add_argument(string placeholder, string description, int * status, string * target);
-
-private:
+protected: // Types
   /*!
-   *\brief Container for one command line option.
+   *\brief Container for an option switch
    */
-  class opt_t{
+  class opt_switch_t{
   public:
-    opt_t (string shortname, string longname,string description, int * status, 
-              string * target=NULL, string placeholder=string("<string>"));
+    opt_switch_t (const string & shortname, 
+                 const string & longname,
+                 const string & description, 
+                 int * status,
+                 const bool & allow_commandline=true, 
+                 const bool & allow_config_file=true);
     string shortname;
     string longname;
     int * status;
     string * target;    
     string description;
     string placeholder;
+    bool allow_conffile;
+    bool allow_cmdline;
   };
 
   /*!
-   *\brief Container for one command line argument.
+   *\brief Container for an option value
+   */
+  class opt_value_t{
+  public:
+    opt_value_t (const string & shortname, 
+             const string & longname,
+             const string & description, 
+             int * status,
+             string * target, 
+             const string & placeholder=string("<string>"),
+             const bool & allow_commandline=true, 
+             const bool & allow_config_file=true);
+    string shortname;
+    string longname;
+    int * status;
+    string * target;    
+    string description;
+    string placeholder;
+    bool allow_conffile;
+    bool allow_cmdline;
+  };
+  
+  /*!
+   *\brief Container for a commandline argument
    */
-  class arg_t{
+  class cmd_arg_t{
   public:
-    arg_t (string placeholder,string description,
-                   int * status, string * target);
+    cmd_arg_t (const  string & placeholder,
+              const  string & description,
+              int * status, 
+              string * target);
     int * status;
     string * target;    
     string description;
     string placeholder;
   };
-  vector<opt_t>opt_v;
-  vector<arg_t>arg_v;
+  
+public: // Methods
+
+  configuration_manager(string name);
+  void add_option_value (const string & shortname,
+                        const string & longname, 
+                        const string & description, 
+                        int    *status, 
+                        string *target=NULL, 
+                        const string &  placeholder=string("<string>"),
+                        const bool & allow_commandline=true,
+                        const bool & allow_config_file=true
+                        );
+
+  void add_option_switch (const string &  shortname,
+                         const string & longname, 
+                         const string & description, 
+                         int    *status, 
+                         const bool & allow_commandline=true,
+                         const bool & allow_config_file=true
+                         );
+  
+  void add_argument (const string & description, 
+                    int    *status, 
+                    string *target=NULL, 
+                    const string & placeholder=string("<string>")
+                    );
+  
+  vector<string> read_args(int argc, char ** args);
+  vector<string> read_file(string filename);
+  
+  void get_help (vector<string> & target);
+  vector<string> get_help();
+  
+protected: // members
+  vector<opt_switch_t>option_switches;
+  vector<opt_value_t>option_values;
+  vector<cmd_arg_t>cmd_args;
   string app_name;
 
-}; // class argument_reader
+protected: // methods
+  string analyse_string(const string & line);
+  bool analyse_bool(const string & data);
+  bool analyse_bool_false(const string & data);
+}; // class configuration_manager
 
 
 #endif
+