Shiokaze Framework
A research-oriented fluid solver for computer graphics
configuration.h
Go to the documentation of this file.
1 /*
2 ** configuration.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 July 19, 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_CONFIGURATION_H
26 #define SHKZ_CONFIGURATION_H
27 //
28 #include <string>
29 #include <map>
30 #include <stack>
31 #include <shiokaze/core/common.h>
32 #include <shiokaze/core/credit.h>
33 //
35 //
37 class configuration {
40 public:
45  configuration();
52  configuration( std::map<std::string,std::string> dictionary );
57  void print_variables () const;
62  void print_help() const;
67  void print_splash() const;
74  void check_touched () const;
83  bool is_parameter_set ( std::string name ) const;
92  bool check_set ( std::string name ) const;
97  static void print_bar( std::string str="" );
102  static void print_center( std::string str );
107  struct auto_group {
127  std::string name,
128  std::string argument_name="",
129  std::string author="",
130  std::string address="",
131  std::tuple<int,int,int> date=std::tuple<int,int,int>(0,0,0),
132  double version=0.0
133  ) : config(config) {
134  config.push_group(name,argument_name,author,address,date,version);
135  }
144  auto_group( configuration &config, const credit &info ) : config(config) {
145  config.push_group(info);
146  }
151  ~auto_group() { config.pop_group(); }
152  private:
153  configuration &config;
154  };
163  std::string get_current_group_name( bool argument_name=false ) const;
170  bool stack_empty() const { return m_group_stack.empty(); }
177  void push_group( const credit &info );
195  void push_group( std::string name,
196  std::string argument_name="",
197  std::string author="",
198  std::string address="",
199  std::tuple<int,int,int> date=std::tuple<int,int,int>(0,0,0),
200  double version=0.0 );
205  void pop_group();
216  bool get_integer( std::string name, int &value, std::string description=std::string() );
225  void set_integer( std::string name, int value );
234  void set_default_integer( std::string name, int value );
245  bool get_unsigned( std::string name, unsigned &value, std::string description=std::string() );
254  void set_unsigned( std::string name, unsigned value );
263  void set_default_unsigned( std::string name, unsigned value );
274  bool get_bool( std::string name, bool &value, std::string description=std::string() );
283  void set_bool( std::string name, bool value );
292  void set_default_bool( std::string name, bool value );
303  double get_double( std::string name, double &value, std::string description=std::string() );
312  void set_double( std::string name, double value );
321  void set_default_double( std::string name, double value );
332  bool get_real( std::string name, Real &value, std::string description=std::string() );
341  void set_real( std::string name, Real value );
350  void set_default_real( std::string name, Real value );
361  bool get_vec2i( std::string name, int value[2], std::string description=std::string() );
370  void set_vec2i( std::string name, const int value[2] );
379  void set_default_vec2i( std::string name, const int value[2] );
390  bool get_vec2d( std::string name, double value[2], std::string description=std::string() );
399  void set_vec2d( std::string name, const double value[2] );
408  void set_default_vec2d( std::string name, const double value[2] );
419  bool get_vec3i( std::string name, int value[3], std::string description=std::string() );
428  void set_vec3i( std::string name, const int value[3] );
437  void set_default_vec3i( std::string name, const int value[3] );
448  bool get_vec3d( std::string name, double value[3], std::string description=std::string());
457  void set_vec3d( std::string name, const double value[3] );
466  void set_default_vec3d( std::string name, const double value[3] );
477  bool get_vec4d( std::string name, double value[4], std::string description=std::string());
486  void set_vec4d( std::string name, const double value[4] );
495  void set_default_vec4d( std::string name, const double value[4] );
506  bool get_string( std::string name, std::string &value, std::string description=std::string() );
515  void set_string( std::string name, std::string value );
524  void set_default_string( std::string name, std::string value );
533  bool exist( std::string name ) const;
540  const std::map<std::string,std::string> & get_dictionary() const { return m_dictionary; }
541  //
542 private:
543  //
544  struct double2 { double v[2]; };
545  struct double3 { double v[3]; };
546  struct double4 { double v[4]; };
547  struct int2 { int v[2]; };
548  struct int3 { int v[3]; };
549  //
550  std::map<std::string,int> default_integer;
551  std::map<std::string,unsigned> default_unsigned;
552  std::map<std::string,bool> default_bool;
553  std::map<std::string,double> default_double;
554  std::map<std::string,Real> default_real;
555  std::map<std::string,double2> default_vec2d;
556  std::map<std::string,double3> default_vec3d;
557  std::map<std::string,double4> default_vec4d;
558  std::map<std::string,int2> default_vec2i;
559  std::map<std::string,int3> default_vec3i;
560  std::map<std::string,std::string> default_string;
561  //
562  struct Entry {
563  bool is_default;
564  std::string type;
565  std::string value;
566  std::string description;
567  };
568  //
569  struct Group {
570  std::string author;
571  std::string address;
572  std::tuple<int,int,int> date;
573  double version;
574  std::map<std::string,Entry> entries;
575  };
576  //
577  struct Title {
578  std::string name;
579  std::string argument_name;
580  unsigned id;
581  bool operator<( const Title &a ) const { return id < a.id; }
582  };
583  //
584  void register_variables ( std::string name, bool is_default, std::string type, std::string value, std::string description );
585  //
586  void print_credit( const Group &group ) const;
587  void print_groupbar( const Title &group_title, const Group &group ) const;
588  std::string concated_name( std::string name ) const;
589  //
590  std::map<std::string,std::string> m_dictionary;
591  std::map<Title,Group> m_groups;
592  std::stack<Title> m_group_stack;
593  unsigned m_label_index;
594 };
595 //
597 //
598 #endif
599 //
configuration::get_double
double get_double(std::string name, double &value, std::string description=std::string())
Get the parameter of double type.
configuration::print_help
void print_help() const
Print a help manual of the currently set parameters.
configuration::get_real
bool get_real(std::string name, Real &value, std::string description=std::string())
Get the parameter of Real type.
configuration::print_center
static void print_center(std::string str)
Print the input message at the center of the line.
configuration::set_default_vec3i
void set_default_vec3i(std::string name, const int value[3])
Set default parameter of vec3i type.
configuration::set_default_unsigned
void set_default_unsigned(std::string name, unsigned value)
Set default unsgined integer parameter.
configuration::set_unsigned
void set_unsigned(std::string name, unsigned value)
Set the unsigned integer parameter.
configuration::push_group
void push_group(const credit &info)
Push the group to the top of the group stack.
configuration::auto_group::~auto_group
~auto_group()
Destructor for auto_group.
Definition: configuration.h:151
configuration::set_default_vec3d
void set_default_vec3d(std::string name, const double value[3])
Set default parameter of vec3d type.
configuration::get_integer
bool get_integer(std::string name, int &value, std::string description=std::string())
Get the integer parameter.
configuration::set_real
void set_real(std::string name, Real value)
Set the parameter of Real type.
configuration::get_vec4d
bool get_vec4d(std::string name, double value[4], std::string description=std::string())
Get the parameter of vec4d type.
credit.h
configuration::print_variables
void print_variables() const
Print the currently set parameters.
configuration::is_parameter_set
bool is_parameter_set(std::string name) const
Check if a parameter with the name is set via command line.
configuration::set_bool
void set_bool(std::string name, bool value)
Set the boolean parameter.
configuration::set_default_bool
void set_default_bool(std::string name, bool value)
Set default boolean parameter.
configuration::exist
bool exist(std::string name) const
Get if the parameter of the input name exists.
configuration::set_vec4d
void set_vec4d(std::string name, const double value[4])
Set the parameter of vec4d type.
configuration::print_bar
static void print_bar(std::string str="")
Print the input message surrounded by --—.
configuration::set_default_real
void set_default_real(std::string name, Real value)
Set default parameter of Real type.
SHKZ_BEGIN_NAMESPACE
#define SHKZ_BEGIN_NAMESPACE
Name space beggining definition for shiokaze.
Definition: common.h:39
configuration::set_integer
void set_integer(std::string name, int value)
Set the integer parameter.
configuration::set_default_vec2d
void set_default_vec2d(std::string name, const double value[2])
Set default parameter of vec2d type.
configuration::auto_group::auto_group
auto_group(configuration &config, std::string name, std::string argument_name="", std::string author="", std::string address="", std::tuple< int, int, int > date=std::tuple< int, int, int >(0, 0, 0), double version=0.0)
Constructor for auto_group.
Definition: configuration.h:126
configuration::set_default_vec4d
void set_default_vec4d(std::string name, const double value[4])
Set default parameter of vec4d type.
configuration::print_splash
void print_splash() const
Print splash greeting messsages.
configuration::get_unsigned
bool get_unsigned(std::string name, unsigned &value, std::string description=std::string())
Get the unsigned integer parameter.
configuration::get_string
bool get_string(std::string name, std::string &value, std::string description=std::string())
Get the string parameter.
configuration::set_vec3i
void set_vec3i(std::string name, const int value[3])
Set the parameter of vec3i type.
configuration::get_bool
bool get_bool(std::string name, bool &value, std::string description=std::string())
Get the boolean parameter.
configuration::set_vec3d
void set_vec3d(std::string name, const double value[3])
Set the parameter of vec3d type.
Real
float Real
Precision of the general floating point number. You may change here to double to increase the precisi...
Definition: config.h:34
configuration::get_vec3d
bool get_vec3d(std::string name, double value[3], std::string description=std::string())
Get the parameter of vec3d type.
configuration::set_default_string
void set_default_string(std::string name, std::string value)
Set default string parameter.
configuration::get_vec2d
bool get_vec2d(std::string name, double value[2], std::string description=std::string())
Get the parameter of vec2d type.
configuration::set_default_vec2i
void set_default_vec2i(std::string name, const int value[2])
Set default parameter of vec2i type.
configuration::configuration
configuration()
Default constructor for configuration.
configuration::get_current_group_name
std::string get_current_group_name(bool argument_name=false) const
Get the name of the currently focused group (or argument name).
configuration::set_vec2d
void set_vec2d(std::string name, const double value[2])
Set the parameter of vec2d type.
common.h
configuration::set_default_double
void set_default_double(std::string name, double value)
Set default parameter of double type.
configuration::auto_group
Class that automates the push and pop groups.
Definition: configuration.h:107
configuration::set_double
void set_double(std::string name, double value)
Set the parameter of double type.
configuration::get_vec3i
bool get_vec3i(std::string name, int value[3], std::string description=std::string())
Get the parameter of vec3i type.
configuration::check_touched
void check_touched() const
Check if all the parameters are loaded by the program.
credit
Class that defines the name, argument name, author's name, email address, date and the version of the...
Definition: credit.h:47
configuration::check_set
bool check_set(std::string name) const
Check if a parameter with the name is set.
configuration
Class that controls the settings of the program.
Definition: configuration.h:39
configuration::pop_group
void pop_group()
Remove the current group from the gruop stack.
SHKZ_END_NAMESPACE
#define SHKZ_END_NAMESPACE
Name space end definition for shiokaze.
Definition: common.h:44
configuration::stack_empty
bool stack_empty() const
Get if the group stack is empty.
Definition: configuration.h:170
configuration::set_vec2i
void set_vec2i(std::string name, const int value[2])
Set the parameter of vec2i type.
configuration::set_default_integer
void set_default_integer(std::string name, int value)
Set default integer parameter.
configuration::set_string
void set_string(std::string name, std::string value)
Set string parameter.
configuration::auto_group::auto_group
auto_group(configuration &config, const credit &info)
Constructor for auto_group.
Definition: configuration.h:144
configuration::get_vec2i
bool get_vec2i(std::string name, int value[2], std::string description=std::string())
Get the parameter of vec2i type.
configuration::get_dictionary
const std::map< std::string, std::string > & get_dictionary() const
Get the dictionary of parameter.
Definition: configuration.h:540