# PhasicFlow: src/phasicFlow/commandLine/commandLine.hpp Source File

commandLine.hpp
Go to the documentation of this file.
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#ifndef __commandLine_hpp__
#define __commandLine_hpp__
#include <any>
#include "CLI.hpp"
#include "types.hpp"
#include "Lists.hpp"
#include "streams.hpp"
namespace pFlow
{
class commandLine
:
public CLI::App
{
public:
using Option = CLI::Option;
using ParseError = CLI::ParseError;
using any = std::any;
protected:
word appName_;
List<any> internalBinVars_;
inline static word versionStr = "v-"+
int322Word(phasicFlow_VERSION_MAJOR)+
"."+
int322Word(phasicFlow_VERSION_MINOR);
inline static word copyRight = "(copyright(C): www.cemf.ir)";
inline static word versionName = "phasicFlow "+ versionStr;
inline static word versoinCopyright = versionName + " " +copyRight;
inline static word description = "Command line help for "+
versoinCopyright +"\n";
public:
commandLine(word appName);
commandLine(word appName, word disptn);
bool parse(int argc, char** argv);
template<typename Type>
Option* addOption(
word optionName,
word description,
word opText = "");
template<typename Type>
Option* addOption(
word optionName,
Type& bindingVar,
word description,
word opText = "");
word productName()const
{
return versionName;
}
word productNameCopyright()const
{
return versoinCopyright;
}
};
}// pFlow
template<typename Type>
pFlow::commandLine::Option*
pFlow::commandLine::addOption(
word optionName,
word description,
word opText)
{
try{
Type& bindingVar = std::any_cast<Type&>(
internalBinVars_.emplace_back( any(Type()))
);
return CLI::App::add_option(optionName, bindingVar, description)->option_text(opText);
}
catch (ParseError& err){
fatalExit;
return nullptr;
}
}
template<typename Type>
pFlow::commandLine::Option*
pFlow::commandLine::addOption(
word optionName,
Type& bindingVar,
word description,
word opText)
{
try{
return CLI::App::add_option(optionName, bindingVar, description)->option_text(opText);
}
catch (ParseError& err){
fatalExit;
return nullptr;
}
}
#endif
pFlow::List< any >
pFlow::commandLine::description
static word description
Definition: commandLine.hpp:64
Lists.hpp
fatalExit
#define fatalExit
Definition: error.hpp:57
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:63
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: demComponent.hpp:28
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)
Definition: bTypesFunctions.cpp:67
pFlow::commandLine::productNameCopyright
word productNameCopyright() const
Definition: commandLine.hpp:96