Shiokaze Framework
A research-oriented fluid solver for computer graphics
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
cmdparser.h
Go to the documentation of this file.
1 /*
2 ** cmdparser.h
3 **
4 ** This is part of Shiokaze, a research-oriented fluid solver for computer graphics.
5 ** Created by Ryoichi Ando <rand@nii.ac.jp> on Feb 1, 2017.
6 **
7 ** Permission is hereby granted, free of charge, to any person obtaining a copy of
8 ** this software and associated documentation files (the "Software"), to deal in
9 ** the Software without restriction, including without limitation the rights to use,
10 ** copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
11 ** Software, and to permit persons to whom the Software is furnished to do so,
12 ** subject to the following conditions:
13 **
14 ** The above copyright notice and this permission notice shall be included in all copies
15 ** or substantial portions of the Software.
16 **
17 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18 ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
19 ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 ** HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21 ** CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22 ** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24 //
25 #ifndef SHKZ_CMDPARSER_H
26 #define SHKZ_CMDPARSER_H
27 //
29 #include <algorithm>
30 //
32 //
34 class cmdparser : public configuration {
37 public:
42  cmdparser() {}
51  cmdparser( int argc, const char * argv[] ) {
52  parse(argc,argv);
53  }
60  cmdparser( const cmdparser &parser ) {
61  parse(parser.get_dictionary());
62  }
69  cmdparser( std::map<std::string,std::string> dictionary ) {
70  parse(dictionary);
71  }
78  void parse( std::map<std::string,std::string> dictionary ) {
79  for( auto it=dictionary.begin(); it!=dictionary.end(); ++it ) {
80  set_string(it->first,it->second);
81  }
83  }
92  void parse ( int argc, const char * argv[] ) {
93  for( unsigned i=0; i<argc; i++ ) {
94  std::string str(argv[i]);
95  for( unsigned k=0; k<str.size(); k++ ) {
96  if( str.at(k) == '=' ) {
97  std::string name(str.begin(),str.begin()+k);
98  std::string value(str.begin()+k+1,str.end());
99  value.erase(std::remove(value.begin(), value.end(), '\\'), value.end());
100  set_string(name,value);
101  }
102  }
103  m_arg_str += str;
104  if( i != argc-1 ) m_arg_str += " ";
105  }
106  rebuild_arg_str();
107  }
113  m_arg_str = std::string();
114  const auto &dictionary = get_dictionary();
115  for( auto it=dictionary.crbegin(); it!=dictionary.crend(); ++it ) {
116  m_arg_str += it->first + "=" + it->second + " ";
117  }
118  }
125  std::string get_arg_string() const {
126  return m_arg_str;
127  }
128  //
129 private:
130  std::string m_arg_str;
131 };
132 //
134 //
135 #endif
cmdparser::cmdparser
cmdparser(int argc, const char *argv[])
Constructor for cmdparser.
Definition: cmdparser.h:51
cmdparser
Class that parses command line arguments.
Definition: cmdparser.h:36
cmdparser::cmdparser
cmdparser(std::map< std::string, std::string > dictionary)
Constructor for cmdparser.
Definition: cmdparser.h:69
cmdparser::rebuild_arg_str
void rebuild_arg_str()
Parse dictionary and set arguments.
Definition: cmdparser.h:112
SHKZ_BEGIN_NAMESPACE
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
cmdparser::get_arg_string
std::string get_arg_string() const
Get the organized string of arguments.
Definition: cmdparser.h:125
cmdparser::parse
void parse(int argc, const char *argv[])
Analyze arguments and set from the arguments called from main function.
Definition: cmdparser.h:92
cmdparser::parse
void parse(std::map< std::string, std::string > dictionary)
Parse dictionary and set arguments.
Definition: cmdparser.h:78
configuration.h
configuration
Class that controls the settings of the program.
Definition: configuration.h:39
SHKZ_END_NAMESPACE
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
cmdparser::cmdparser
cmdparser(const cmdparser &parser)
Copy constructor for cmdparser.
Definition: cmdparser.h:60
cmdparser::cmdparser
cmdparser()
Default constructor.
Definition: cmdparser.h:42
configuration::set_string
void set_string(std::string name, std::string value)
Set string parameter.
configuration::get_dictionary
const std::map< std::string, std::string > & get_dictionary() const
Get the dictionary of parameter.
Definition: configuration.h:540