UtilParameters.h

Go to the documentation of this file.
00001 //===========================================================================//
00002 // This file is part of the DIP Solver Framework.                            //
00003 //                                                                           //
00004 // DIP is distributed under the Eclipse Public License as part of the        //
00005 // COIN-OR repository (http://www.coin-or.org).                              //
00006 //                                                                           //
00007 // Author: Matthew Galati, SAS Institute Inc. (matthew.galati@sas.com)       //
00008 //                                                                           //
00009 // Conceptual Design: Matthew Galati, SAS Institute Inc.                     //
00010 //                    Ted Ralphs, Lehigh University                          //
00011 //                                                                           //
00012 // Copyright (C) 2002-2013, Lehigh University, Matthew Galati, Ted Ralphs    //
00013 // All Rights Reserved.                                                      //
00014 //===========================================================================//
00015 
00016 #ifndef UTIL_PARAMETERS_INCLUDED
00017 #define UTIL_PARAMETERS_INCLUDED
00018 
00019 //===========================================================================//
00020 #include <map>
00021 #include <string>
00022 #include <fstream>
00023 
00024 //===========================================================================//
00025 struct UtilParamT {
00026    //bad name for this string, really valueStr?
00027    std::string paramName;
00028    bool   isUsed;        //is used in code (a call to getSetting)?
00029 };
00030 typedef struct UtilParamT UtilParam;
00031 
00032 //===========================================================================//
00033 class UtilParameters {
00034 private:
00035    std::map<std::string, UtilParam> m_paramMap;
00036 
00037 public:
00038    UtilParameters()
00039       : m_paramMap() {}
00040 
00041    UtilParameters(int&   argc,
00042                   char* argv[]) :
00043       m_paramMap() {
00044       ScanCmdLineArgs(argc, argv);
00045    };
00046 
00047    ~UtilParameters() {};
00048 
00049    void ScanCmdLineArgs(int&   argc,
00050                         char* argv[]);
00051    void   LoadParamFile(std::string& paramFileName);
00052    void   Add(std::string& section,
00053               std::string& name,
00054               std::string& value);
00055    void   Add(const char* section,
00056               const char* name,
00057               const char* value);
00058    std::string GetSetting(const char* name,
00059                           const char* defaultValue,
00060                           const char* section = NULL);
00061    int    GetSetting(const char* name,
00062                      const int    defaultValue,
00063                      const char* section = NULL);
00064    bool   GetSetting(const char* name,
00065                      const bool   defaultValue,
00066                      const char* section = NULL);
00067    long   GetSetting(const char* name,
00068                      const long   defaultValue,
00069                      const char* section = NULL);
00070    double GetSetting(const char* name,
00071                      const double defaultValue,
00072                      const char* section = NULL);
00073 
00074    std::string GetSetting(const char* name,
00075                           const std::string defaultValue,
00076                           const char* section = NULL) ;
00077 private:
00078    UtilParam* FindEntry(const char* section,
00079                         const char* name);
00080    std::string*     Find(const char* section,
00081                          const char* name);
00082 };
00083 
00084 #endif

Generated on 12 Feb 2015 for Dip-All by  doxygen 1.6.1