1 #ifndef __JEEP__JPARSER__
2 #define __JEEP__JPARSER__
52 using JLANG::JComparisonAvailable;
72 static std::ostringstream buffer;
115 return in.bad() || (in.fail() && !in.eof());
159 operator const T&()
const
203 object.__status =
true;
223 out <<
object.__value;
281 inline bool less(
const int value)
const
293 inline bool more(
const int value)
const
352 out <<
object.counter;
377 const std::string& help =
"") :
436 virtual void print(std::ostream& out)
const
440 out <<
"<" <<
getName() <<
">";
447 out << setw(width) <<
" ";
456 out <<
" \"" <<
getHelp() <<
"\"";
482 template<class JType_t, bool has_eq = JComparisonAvailable<JType_t>::has_eq>
489 template<
class JType_t>
521 __element.possibleValues.push_back(value);
533 template<
template<
class,
class>
class JContainer_t,
class JAllocator_t>
536 for (
typename JContainer_t<JType_t, JAllocator_t>::const_iterator i = values.begin(); i != values.end(); ++i) {
537 __element.possibleValues.push_back(*i);
550 template<
template<
class,
class,
class>
class JContainer_t,
class JCompare_t,
class JAllocator_t>
553 for (
typename JContainer_t<JType_t, JCompare_t, JAllocator_t>::const_iterator i = values.begin(); i != values.end(); ++i) {
554 __element.possibleValues.push_back(*i);
568 template<
class JType_t>
581 const std::string&
name =
"arg",
582 const std::string& help =
"") :
585 is_initialised(false)
651 return is_initialised;
662 is_initialised = value;
672 virtual std::istream&
read(std::istream&
in)
override
674 if (in.peek() == EOF) {
684 while (isspace(in.peek())) {
688 if (in.peek() != EOF) {
704 virtual std::ostream&
write(std::ostream& out)
const override
730 if (in.peek() != EOF) {
757 template<bool option = JLANG::JResolve<TString>::value>
775 static inline std::istream&
read(std::istream&
in,
T&
object)
809 static inline std::istream&
read(std::istream&
in,
T&
object)
811 return object.ReadLine(in);
824 for (std::string buffer; in >> buffer; ) {
825 object.push_back(TString(buffer.c_str()));
870 template<
class JType_t>
886 const std::string&
name =
"arg",
887 const std::string& help =
"") :
902 const std::string&
name,
907 setPossibleValues(__begin, __end);
922 const std::string&
name,
923 const std::string& help,
928 setPossibleValues(__begin, __end);
968 this->
object = value;
972 possibleValues.push_back(value);
984 template<
template<
class,
class>
class JContainer_t,
class JAllocator_t>
987 setPossibleValues(values.begin(), values.end());
999 template<
template<
class,
class,
class>
class JContainer_t,
class JCompare_t,
class JAllocator_t>
1002 setPossibleValues(values.begin(), values.end());
1019 if (possibleValues.size() > 1) {
1022 if (this->
object == *i) {
1042 virtual void print(std::ostream& out)
const override
1047 writeArray(out,
" [",
"]",
", ", possibleValues.begin(), possibleValues.end());
1061 if (__begin != __end) {
1063 this->
object = *__begin;
1067 for (
T i = __begin; i != __end; ++i) {
1068 possibleValues.push_back(*i);
1101 this->
object =
false;
1112 virtual std::istream&
read(std::istream&
in)
override
1114 this->
object =
true;
1126 virtual std::ostream&
write(std::ostream& out)
const override
1128 return out << object;
1215 virtual std::istream&
read(std::istream&
in)
override
1217 return in >> object;
1227 virtual std::ostream&
write(std::ostream& out)
const override
1229 return out << object;
1318 JSharedPointer_t::operator=(static_cast<JSharedPointer_t&>(value));
1330 template<
class JType_t>
1347 template<
class JType_t>
1364 template<
class JType_t>
1386 (*this)->setInitialiationStatus(
true);
1400 (*this)->setInitialiationStatus(
false);
1416 return value->read(in);
1432 return value->write(out);
1447 return get()->
print(out);
1516 template<
class JKey_t =
char>
1518 public std::map<JKey_t, JParserElement>,
1552 const int debug = 0) :
1567 this->insert(parser.begin(), parser.end());
1581 using namespace std;
1582 using namespace JPP;
1585 out << help << endl;
1600 i->second.print(out);
1631 return (*
this)(
JArgs(argc, argv));
1643 using namespace std;
1644 using namespace JLANG;
1645 using namespace JEEP;
1653 for (JArgs::const_iterator i = args.begin(); i != args.end(); ++i) {
1655 DEBUG(
"Processing option <" << *i <<
">" << endl);
1660 for (
int c; (
c =
is.get()) != EOF; ) {
1664 if (
is.peek() == EOF) {
1668 }
else if (isspace(
is.peek())) {
1673 while (
is.peek() != EOF) {
1681 if (
is.peek() != EOF) {
1701 cout <<
"source: " <<
getSource() << endl;
1715 if (
is.peek() != EOF) {
1727 if (
is.peek() == EOF && i + 1 != args.end()) {
1736 ofstream out(file_name.c_str());
1738 out << getpid() << endl;
1754 return JArgs(pid, ++i, args.end());
1764 DEBUG(
"Processing option <" << option <<
"> " << (p != this->end()) << endl);
1766 if (p != this->end()) {
1768 if (p->second->gcount()) {
1770 if (
is.peek() == EOF && i + 1 != args.end()) {
1779 catch(
const exception& error) {
1815 int read(
const int argc,
const char*
const argv[])
1817 (*this)(argc, argv);
1844 std::ostream&
write(std::ostream& out)
const
1847 out << i->second->getName() <<
'=' << i->second << std::endl;
1861 friend inline std::ostream& operator<<(std::ostream& out, const JParser<key_type>& parser)
1863 return parser.write(out);
1876 if (!p->second->getInitialisationStatus()) {
1880 if (!p->second->getStatus()) {
1927 template<
class JType_t>
1944 template<
class JType_t,
class T>
1946 const std::string&
name,
1947 const std::string& help,
1964 template<
class JType_t,
class T>
1966 const std::string&
name,
1970 return getOption(
object, name,
"", __begin, __end);
1987 #define VARGS_STRING(A, B, ...) (static_cast<std::ostringstream&>(JPARSER::getOstream() << B << std::flush)).str()
1993 #define make_field(A, ...) JPARSER::getOption(A, #A, VARGS_STRING("", ##__VA_ARGS__, ""))
1999 #define make_option(A, ...) JPARSER::getOption(A, #A, VARGS_STRING("", ##__VA_ARGS__, ""))
JArgs operator()(const JArgs &args)
Parse the program's command line options.
Utility class to parse command line options.
Auxiliary data structure for alignment of data.
virtual std::istream & read(std::istream &in) override
Stream input.
JParser(const int debug=0)
Default constructor.
static char PID_OPTION
print PID to file
JParserTemplateElement< JType_t > & operator=(const JParserTemplateElement< JType_t > &value)
Assignment operator.
virtual bool getStatus() const =0
Get status of parameter.
const JParserElement & operator=(const initialised &value)
Set initialised status to true.
virtual bool getInitialisationStatus() const override
Get initialisation status of parameter.
std::istream & read(std::istream &in, JTestSummary &summary, const char delimiter= ' ')
Read test summary.
const char * getGITCommit()
Get GIT commit.
Template specialisation of JPARSER::JParserTemplateElement for data type with equal operator ==...
static char PRINT_OPTION
print option
virtual void setInitialiationStatus(const bool value) override
Set initialisation status of parameter.
const char * getGITDate()
Get GIT date.
std::string double_quote(const std::string &value)
Quote string.
std::ostream & write(std::ostream &out) const
Print the current parameter values.
std::string help
help message
virtual bool getStatus() const override
Status of object.
friend std::istream & operator>>(std::istream &in, JParserElement &value)
Stream input.
virtual std::ostream & write(std::ostream &out) const override
Stream output.
const JOption< T > & operator=(const T &value)
Assignment to a value.
Template specialisation of JPARSER::JParserTemplateElement for data type without equal operator ==...
JParserTemplateElement< JType_t > & operator=(JType_t &value)
Assignment operator.
JParserTemplateElement< bool > getOption(bool &object, const std::string &name, const std::string &help="")
Auxiliary method for creation of template parser element object.
JParserTemplateElement(JType_t &object, const std::string &name="arg", const std::string &help="")
Constructor.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
then echo Enter input within $TIMEOUT_S seconds echo n User name
Auxiliary class to handle pointer to JPARSER::JParserElementInterface.
static std::istream & read(std::istream &in, std::vector< T > &object)
Read std::vector of objects from input stream.
Auxiliary class for handling I/O of TString depending on its existence.
Jpp environment information.
const JParserTemplateElement< JType_t, true > & operator=(const not_initialised &value)
Set initialised status to false.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
virtual bool gcount() const override
Read counter.
Auxiliary class to handle optional I/O.
virtual void setInitialiationStatus(const bool value) override
Set initialisation status of parameter.
std::string getNamespace(const std::string &type_name)
Get name space, i.e. part before JEEP::TYPENAME_SEPARATOR.
bool is_valid() const
Check validity of pointer.
std::ostream & getOstream()
Get output stream for conversion to std::string.
JParser(const std::string &message, const int debug=0)
Constructor.
JParserElement()
Default constructor.
JSharedPointer< JParserElementInterface > JSharedPointer_t
const std::string & getName() const
Get name of parameter.
virtual void print(std::ostream &out) const
Print.
JParserTemplateElement< JType_t > & __element
std::istream & readObject(std::istream &in, T &object)
Stream input of object.
virtual bool getStatus() const override
Status of object.
virtual bool getInitialisationStatus() const =0
Get initialisation status of parameter.
const JCounter & operator=(const bool value)
Set value.
virtual void setInitialiationStatus(const bool value)=0
Set initialisation status of parameter.
static char REVISION_OPTION
revision option
JParserElement(const JParserElement &value)
Copy constructor.
bool more(const int value) const
Compare value.
void setPossibleValues(T __begin, T __end)
Set possible values.
std::ostream & write(std::ostream &out) const
void print(std::ostream &out) const
Print the possible command line options.
JParserTemplateElement(JType_t &object, const std::string &name, T __begin, T __end)
Constructor.
JCSV & operator,(JType_t value)
Parsing of additional possible values.
std::string getGITVersion(const std::string &tag)
Get GIT version for given GIT tag.
Auxiliary template class for type bool.
The template JSharedPointer class can be used to share a pointer to an object.
JCSV(JParserTemplateElement< JType_t > &element)
Constructor.
map_type::iterator iterator
JParserElement & operator=(JParserElement &value)
Assignment operator.
const JParserTemplateElement< JType_t, false > & operator=(const initialised &value)
Set initialised status to true.
Interface for I/O of parser element.
JCounter()
Default constructor.
virtual bool getInitialisationStatus() const override
Get initialisation status of parameter.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
int read(const JArgs &args)
Parse the program's command line options.
bool getLongprint(std::ostream &out)
Get long print option.
bool is_valid(const json &js)
Check validity of JSon data.
virtual std::ostream & write(std::ostream &out) const override
Stream output.
std::string getURL()
Get URL of document pages.
friend std::istream & operator>>(std::istream &in, JOption &object)
Read option from input.
int getCounter() const
Get counter.
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
friend std::istream & operator>>(std::istream &in, JCounter &object)
Read option from input.
virtual bool getStatus() const override
Get status of object.
JOption(const T &value)
Constructor.
virtual std::ostream & write(std::ostream &out) const override
Stream output.
void check_status() const
Check if all required options have been set.
Data structure to store command line arguments.
Exception when parsing a value.
JParserTemplateElement(JType_t &object, const std::string &name, const std::string &help, T __begin, T __end)
Constructor.
const JParserTemplateElement< JType_t, true > & operator=(const initialised &value)
Set initialised status to true.
Template definition of auxiliary base class for comparison of data structures.
General purpose messaging.
JLANG::JParserException JParserException
bool fail(std::istream &in)
Check for stream state.
virtual std::ostream & write(std::ostream &out) const =0
Stream output.
JParserTemplateElement(bool &object, const std::string &name="arg", const std::string &help="")
Constructor.
JCSV< JType_t > operator=(const JContainer_t< JType_t, JAllocator_t > &values)
Assignment to a default value and possible other values.
virtual bool getStatus() const override
Get status of object.
Empty structure for specification of parser element that is not initialised (i.e. does require input)...
virtual std::istream & read(std::istream &in) override
Stream input.
virtual void terminate(const int status)
Terminate.
JParserElementInterface(const std::string &name="arg", const std::string &help="")
Constructor.
std::map< key_type, JParserElement > map_type
Template specialisation of JPARSER::JParserTemplateElement for type bool.
std::ostream & writeArray(std::ostream &out, const char *left, const char *right, const char *sep, T __begin, T __end)
Write array of objects.
JParserTemplateElement(JType_t &object, const std::string &name="arg", const std::string &help="")
Constructor.
virtual const char * what() const override
Get error message.
Interface for ASCII output using standard streams.
int read(const int argc, const char *const argv[])
Parse the program's command line options.
JCSV & operator,(const JContainer_t< JType_t, JAllocator_t > &values)
Parsing of additional possible values.
std::vector< JType_t > possibleValues
void setPrintOption(std::ostream &out, const int option)
Set print option.
bool less(const int value) const
Compare value.
virtual void print(std::ostream &out) const override
Print.
virtual std::istream & read(std::istream &in) override
Stream input.
JCSV< JType_t > operator=(const JCSV< JType_t > &value)
Assignment operator.
const char * getSource()
Get source.
static char END_OF_OPTIONS
end of all options
const JParserTemplateElement< JType_t, false > & operator=(const not_initialised &value)
Set initialised status to false.
Auxiliary class to assign the remainder of a sequence of Comma Separated Values.
JCSV< JType_t > operator=(const JType_t &value)
Assignment to a default value and possible other values.
Template specialisation of JPARSER::JParserTemplateElement for type JCounter.
Auxiliary class to handle multiple boolean-like I/O.
static std::istream & read(std::istream &in, T &object)
Read object from input stream.
Interface for status of object.
static std::istream & read(std::istream &in, std::vector< T > &object)
Read std::vector of objects from input stream.
virtual bool getStatus() const override
Get status of this counter.
static int NORMAL_EXIT_CODE
exit code of normal end
const JParserTemplateElement< JType_t, false > & operator=(const JType_t &value)
Assignment to a default value.
bool getShortprint(std::ostream &out)
Get short print option.
static char START_OF_OPTION
Parser options.
std::string getFilename(const std::string &file_name)
Get file name part, i.e. part after last JEEP::PATHNAME_SEPARATOR if any.
map_type::const_iterator const_iterator
const JParserElement & operator=(const not_initialised &value)
Set initialised status to false.
void print(std::ostream &out) const
Print.
virtual bool gcount() const
Read counter.
JArgs operator()(const int argc, const char *const argv[])
Parse the program's command line options.
$WORKDIR ev_configure_domsimulator txt echo process $DOM_SIMULATOR $i $SOURCE_HOST[$index] csh c(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&($DOM_SIMULATOR\-u\$NAME\$\-H\$SERVER\$\-M\$LOGGER\$\-d $DEBUG</dev/null > &/dev/null &))'
T * clone() const
Get clone of this object.
std::string pid
process name
virtual bool gcount() const override
Read counter.
Template class holder for I/O of parser element.
JParser & join(const JParser &parser)
Join parser.
virtual void setInitialiationStatus(const bool value) override
Set initialisation status of parameter.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
friend std::ostream & operator<<(std::ostream &out, const JParserElement &value)
Stream output.
JParserTemplateElement(JCounter &object, const std::string &name, const std::string &help="")
Constructor.
bool getStatus() const
Get status.
const std::string & getHelp() const
Get help of parameter.
JOption()
Default constructor.
bool less(const JCounter &value) const
Compare value.
std::istream & read(std::istream &in)
friend std::ostream & operator<<(std::ostream &out, const JOption &object)
Write options to output.
virtual bool getInitialisationStatus() const override
Get initialisation status of parameter.
JCSV & operator,(const JContainer_t< JType_t, JCompare_t, JAllocator_t > &values)
Parsing of additional possible values.
JCSV< JType_t > operator=(const JContainer_t< JType_t, JCompare_t, JAllocator_t > &values)
Assignment to a default value and possible other values.
static std::istream & read(std::istream &in, T &object)
Read object from input stream.
friend std::ostream & operator<<(std::ostream &out, const JCounter &object)
Write options to output.
#define DEBUG(A)
Message macros.
Auxiliary class for handling debug parameter within a class.
std::ostream & writeObject(std::ostream &out, const T &object)
Stream output of object.
static char HELP_OPTION
help option