Dip  0.92.4
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 // Authors: Matthew Galati, SAS Institute Inc. (matthew.galati@sas.com) //
8 // Ted Ralphs, Lehigh University (ted@lehigh.edu) //
9 // Jiadong Wang, Lehigh University (jiw408@lehigh.edu) //
10 // //
11 // Copyright (C) 2002-2019, Lehigh University, Matthew Galati, Ted Ralphs //
12 // All Rights Reserved. //
13 //===========================================================================//
14 
15 #ifndef UTIL_PARAMETERS_INCLUDED
16 #define UTIL_PARAMETERS_INCLUDED
17 
18 //===========================================================================//
19 #include <map>
20 #include <string>
21 #include <fstream>
22 #include <sstream>
23 #include <vector>
24 
25 //===========================================================================//
26 class UtilParameters {
27 private:
28  std::map<std::string, std::string> m_paramMap;
29 
30 public:
32  : m_paramMap() {}
33 
34  UtilParameters(int& argc,
35  char* argv[]) :
36  m_paramMap() {
37  ScanCmdLineArgs(argc, argv);
38  };
39 
41 
42  const std::map<std::string, std::string> getParamMap() { return m_paramMap; }
43 
44  void ScanCmdLineArgs(int& argc,
45  char* argv[]);
46  void LoadParamFile(std::string& paramFileName);
47  void Add(std::string& section,
48  std::string& name,
49  std::string& value);
50  void Add(const char* section,
51  const char* name,
52  const char* value);
53  std::string GetSetting(const char* name,
54  const char* defaultValue,
55  const char* section = NULL);
56  int GetSetting(const char* name,
57  const int defaultValue,
58  const char* section = NULL);
59  bool GetSetting(const char* name,
60  const bool defaultValue,
61  const char* section = NULL);
62  long GetSetting(const char* name,
63  const long defaultValue,
64  const char* section = NULL);
65  double GetSetting(const char* name,
66  const double defaultValue,
67  const char* section = NULL);
68 
69  std::string GetSetting(const char* name,
70  const std::string defaultValue,
71  const char* section = NULL) ;
72 
73  std::vector<std::string> &split(const std::string &s,
74  std::vector<std::string> &elems,
75  char delim = '@') {
76  std::stringstream ss(s);
77  std::string item;
78  while (std::getline(ss, item, delim)) {
79  elems.push_back(item);
80  }
81  return elems;
82  }
83 
84  private:
85 
86  std::string* Find(const char* section,
87  const char* name);
88 };
89 
90 #endif
UtilParameters(int &argc, char *argv[])
string GetSetting(const char *name, const char *defaultValue, const char *section=NULL)
void ScanCmdLineArgs(int &argc, char *argv[])
std::vector< std::string > & split(const std::string &s, std::vector< std::string > &elems, char delim= '@')
void LoadParamFile(string &paramFileName)
std::map< std::string, std::string > m_paramMap
void Add(string &section, string &name, string &value)
map< string, UtilParam > m_paramMap
string * Find(const char *section, const char *name)
const std::map< std::string, std::string > getParamMap()