www.cemf.ir
commandLine.hpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 
22 #ifndef __commandLine_hpp__
23 #define __commandLine_hpp__
24 
25 #include <any>
26 #include "CLI.hpp"
27 
28 #include "types.hpp"
29 #include "Lists.hpp"
30 #include "streams.hpp"
31 
32 namespace pFlow
33 {
34 
35 
37 :
38  public CLI::App
39 {
40 public:
41 
42  using Option = CLI::Option;
43 
44  using ParseError = CLI::ParseError;
45 
46  using any = std::any;
47 
48 protected:
49 
51 
53 
54  inline static word versionStr = "v-"+
55  int322Word(phasicFlow_VERSION_MAJOR)+
56  "."+
57  int322Word(phasicFlow_VERSION_MINOR);
58  inline static word copyRight = "(copyright(C): www.cemf.ir)";
59 
60  inline static word versionName = "phasicFlow "+ versionStr;
61 
62  inline static word versoinCopyright = versionName + " " +copyRight;
63 
64  inline static word description = "Command line help for "+
65  versoinCopyright +"\n";
66 
67 
68 
69 public:
70 
71  commandLine(word appName);
72 
73  commandLine(word appName, word disptn);
74 
75 
76  bool parse(int argc, char** argv);
77 
78  template<typename Type>
80  word optionName,
82  word opText = "");
83 
84  template<typename Type>
86  word optionName,
87  Type& bindingVar,
89  word opText = "");
90 
92  {
93  return versionName;
94  }
95 
97  {
98  return versoinCopyright;
99  }
100 
101 };
102 
103 }// pFlow
104 
105 
106 template<typename Type>
109  word optionName,
110  word description,
111  word opText)
112 {
113  try{
114 
115  Type& bindingVar = std::any_cast<Type&>(
116  internalBinVars_.emplace_back( any(Type()))
117  );
118  return CLI::App::add_option(optionName, bindingVar, description)->option_text(opText);
119  }
120  catch (ParseError& err){
121  fatalExit;
122  return nullptr;
123  }
124 }
125 
126 
127 template<typename Type>
130  word optionName,
131  Type& bindingVar,
132  word description,
133  word opText)
134 {
135  try{
136 
137  return CLI::App::add_option(optionName, bindingVar, description)->option_text(opText);
138  }
139  catch (ParseError& err){
140  fatalExit;
141  return nullptr;
142  }
143 }
144 
145 
146 
147 #endif
148 
pFlow::List< any >
pFlow::commandLine::description
static word description
Definition: commandLine.hpp:64
Lists.hpp
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
types.hpp
pFlow::commandLine::appName_
word appName_
Definition: commandLine.hpp:50
pFlow::commandLine::addOption
Option * addOption(word optionName, word description, word opText="")
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::commandLine
Definition: commandLine.hpp:36
pFlow::commandLine::copyRight
static word copyRight
Definition: commandLine.hpp:58
pFlow::commandLine::internalBinVars_
List< any > internalBinVars_
Definition: commandLine.hpp:52
pFlow
Definition: demGeometry.hpp:27
pFlow::commandLine::Option
CLI::Option Option
Definition: commandLine.hpp:42
pFlow::commandLine::parse
bool parse(int argc, char **argv)
Definition: commandLine.cpp:50
pFlow::commandLine::versionStr
static word versionStr
Definition: commandLine.hpp:54
pFlow::commandLine::versoinCopyright
static word versoinCopyright
Definition: commandLine.hpp:62
pFlow::commandLine::productName
word productName() const
Definition: commandLine.hpp:91
pFlow::commandLine::commandLine
commandLine(word appName)
Definition: commandLine.cpp:24
streams.hpp
pFlow::commandLine::versionName
static word versionName
Definition: commandLine.hpp:60
pFlow::commandLine::any
std::any any
Definition: commandLine.hpp:46
pFlow::commandLine::ParseError
CLI::ParseError ParseError
Definition: commandLine.hpp:44
pFlow::int322Word
word int322Word(const int32 &v)
Convert int32 to word.
Definition: bTypesFunctions.cpp:110
pFlow::commandLine::productNameCopyright
word productNameCopyright() const
Definition: commandLine.hpp:96