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;
435 virtual void print(std::ostream& out)
const
439 out <<
"<" <<
getName() <<
">";
446 out << setw(width) <<
" ";
455 out <<
" \"" <<
getHelp() <<
"\"";
481 template<class JType_t, bool has_eq = JComparisonAvailable<JType_t>::has_eq>
488 template<
class JType_t>
520 __element.possibleValues.push_back(value);
532 template<
template<
class,
class>
class JContainer_t,
class JAllocator_t>
535 for (
typename JContainer_t<JType_t, JAllocator_t>::const_iterator
i = values.begin();
i != values.end(); ++
i) {
536 __element.possibleValues.push_back(*
i);
549 template<
template<
class,
class,
class>
class JContainer_t,
class JCompare_t,
class JAllocator_t>
552 for (
typename JContainer_t<JType_t, JCompare_t, JAllocator_t>::const_iterator
i = values.begin();
i != values.end(); ++
i) {
553 __element.possibleValues.push_back(*
i);
567 template<
class JType_t>
584 is_initialised(false)
650 return is_initialised;
661 is_initialised = value;
671 virtual std::istream&
read(std::istream&
in)
override
673 if (in.peek() == EOF) {
683 while (isspace(in.peek())) {
687 if (in.peek() != EOF) {
703 virtual std::ostream&
write(std::ostream& out)
const override
729 if (in.peek() != EOF) {
756 template<bool option = JLANG::JResolve<TString>::value>
774 static inline std::istream&
read(std::istream&
in,
T&
object)
808 static inline std::istream&
read(std::istream&
in,
T&
object)
810 return object.ReadLine(in);
824 object.push_back(buffer.c_str());
869 template<
class JType_t>
906 setPossibleValues(__begin, __end);
927 setPossibleValues(__begin, __end);
967 this->
object = value;
971 possibleValues.push_back(value);
983 template<
template<
class,
class>
class JContainer_t,
class JAllocator_t>
986 setPossibleValues(values.begin(), values.end());
998 template<
template<
class,
class,
class>
class JContainer_t,
class JCompare_t,
class JAllocator_t>
1001 setPossibleValues(values.begin(), values.end());
1018 if (possibleValues.size() > 1) {
1021 if (this->
object == *
i) {
1040 virtual void print(std::ostream& out)
const override
1045 writeArray(out,
" [",
"]",
", ", possibleValues.begin(), possibleValues.end());
1059 if (__begin != __end) {
1061 this->
object = *__begin;
1065 for (
T i = __begin;
i != __end; ++
i) {
1066 possibleValues.push_back(*
i);
1099 this->
object =
false;
1110 virtual std::istream&
read(std::istream&
in)
override
1112 this->
object =
true;
1124 virtual std::ostream&
write(std::ostream& out)
const override
1126 return out << object;
1213 virtual std::istream&
read(std::istream&
in)
override
1215 return in >> object;
1225 virtual std::ostream&
write(std::ostream& out)
const override
1227 return out << object;
1316 JSharedPointer_t::operator=(static_cast<JSharedPointer_t&>(value));
1328 template<
class JType_t>
1345 template<
class JType_t>
1362 template<
class JType_t>
1384 (*this)->setInitialiationStatus(
true);
1398 (*this)->setInitialiationStatus(
false);
1414 return value->read(in);
1430 return value->write(out);
1444 return get()->
print(out);
1513 template<
class JKey_t =
char>
1515 public std::map<JKey_t, JParserElement>,
1549 const int debug = 0) :
1564 this->insert(parser.begin(), parser.end());
1577 using namespace std;
1578 using namespace JPP;
1581 out << help << endl;
1596 i->second.print(out);
1627 return (*
this)(
JArgs(argc, argv));
1639 using namespace std;
1640 using namespace JLANG;
1641 using namespace JEEP;
1649 for (JArgs::const_iterator
i = args.begin();
i != args.end(); ++
i) {
1651 DEBUG(
"Processing option <" << *
i <<
">" << endl);
1656 for (
int c; (
c =
is.get()) != EOF; ) {
1660 if (
is.peek() == EOF) {
1664 }
else if (isspace(
is.peek())) {
1669 while (
is.peek() != EOF) {
1677 if (
is.peek() != EOF) {
1697 cout <<
"source: " <<
getSource() << endl;
1711 if (
is.peek() != EOF) {
1723 if (
is.peek() == EOF &&
i + 1 != args.end()) {
1732 ofstream out(file_name.c_str());
1734 out << getpid() << endl;
1750 return JArgs(pid, ++
i, args.end());
1760 DEBUG(
"Processing option <" << option <<
"> " << (p != this->end()) << endl);
1762 if (p != this->end()) {
1764 if (p->second->gcount()) {
1766 if (
is.peek() == EOF &&
i + 1 != args.end()) {
1775 catch(
const exception& error) {
1811 int read(
const int argc,
const char*
const argv[])
1813 (*this)(argc, argv);
1840 std::ostream&
write(std::ostream& out)
const
1843 out <<
i->second->getName() <<
'=' <<
i->second << std::endl;
1857 friend inline std::ostream& operator<<(std::ostream& out, const JParser<key_type>& parser)
1859 return parser.write(out);
1872 if (!p->second->getInitialisationStatus()) {
1876 if (!p->second->getStatus()) {
1923 template<
class JType_t>
1940 template<
class JType_t,
class T>
1960 template<
class JType_t,
class T>
1966 return getOption(
object, name,
"", __begin, __end);
1983 #define VARGS_STRING(A, B, ...) (static_cast<std::ostringstream&>(JPARSER::getOstream() << B << std::flush)).str()
1989 #define make_field(A, ...) JPARSER::getOption(A, #A, VARGS_STRING("", ##__VA_ARGS__, ""))
1995 #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.
bool is_valid(const json &js)
Check validity of JSon data.
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.
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)...
$WORKDIR ev_configure_dqsimulator txt echo process $DQ_SIMULATOR $i $SOURCE_HOST[$index] csh c(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&($DQ_SIMULATOR\-u\$NAME\$\-H\$SERVER\$\-M\$LOGGER\$\-d $DEBUG</dev/null > &/dev/null &))'
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.
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
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.
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.
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