Dip-All  0.91.0
UtilParameters.h
Go to the documentation of this file.
1 //===========================================================================//
2 // This file is part of the DIP Solver Framework. //
3 // //
4 // DIP is distributed under the Eclipse Public License as part of the //
5 // COIN-OR repository (http://www.coin-or.org). //
6 // //
7 // Author: Matthew Galati, SAS Institute Inc. (matthew.galati@sas.com) //
8 // //
9 // Conceptual Design: Matthew Galati, SAS Institute Inc. //
10 // Ted Ralphs, Lehigh University //
11 // //
12 // Copyright (C) 2002-2015, Lehigh University, Matthew Galati, Ted Ralphs //
13 // All Rights Reserved. //
14 //===========================================================================//
15 
16 #ifndef UTIL_PARAMETERS_INCLUDED
17 #define UTIL_PARAMETERS_INCLUDED
18 
19 //===========================================================================//
20 #include <map>
21 #include <string>
22 #include <fstream>
23 
24 //===========================================================================//
25 struct UtilParamT {
26  //bad name for this string, really valueStr?
27  std::string paramName;
28  bool isUsed; //is used in code (a call to getSetting)?
29 };
30 typedef struct UtilParamT UtilParam;
31 
32 //===========================================================================//
33 class UtilParameters {
34 private:
35  std::map<std::string, UtilParam> m_paramMap;
36 
37 public:
39  : m_paramMap() {}
40 
41  UtilParameters(int& argc,
42  char* argv[]) :
43  m_paramMap() {
44  ScanCmdLineArgs(argc, argv);
45  };
46 
48 
49  void ScanCmdLineArgs(int& argc,
50  char* argv[]);
51  void LoadParamFile(std::string& paramFileName);
52  void Add(std::string& section,
53  std::string& name,
54  std::string& value);
55  void Add(const char* section,
56  const char* name,
57  const char* value);
58  std::string GetSetting(const char* name,
59  const char* defaultValue,
60  const char* section = NULL);
61  int GetSetting(const char* name,
62  const int defaultValue,
63  const char* section = NULL);
64  bool GetSetting(const char* name,
65  const bool defaultValue,
66  const char* section = NULL);
67  long GetSetting(const char* name,
68  const long defaultValue,
69  const char* section = NULL);
70  double GetSetting(const char* name,
71  const double defaultValue,
72  const char* section = NULL);
73 
74  std::string GetSetting(const char* name,
75  const std::string defaultValue,
76  const char* section = NULL) ;
77 private:
78  UtilParam* FindEntry(const char* section,
79  const char* name);
80  std::string* Find(const char* section,
81  const char* name);
82 };
83 
84 #endif
UtilParameters(int &argc, char *argv[])
string GetSetting(const char *name, const char *defaultValue, const char *section=NULL)
UtilParam * FindEntry(const char *section, const char *name)
void ScanCmdLineArgs(int &argc, char *argv[])
std::map< std::string, UtilParam > m_paramMap
void LoadParamFile(string &paramFileName)
void Add(string &section, string &name, string &value)
map< string, UtilParam > m_paramMap
string * Find(const char *section, const char *name)
std::string paramName