1 #ifndef __JEEP__JPARSER__
2 #define __JEEP__JPARSER__
49 using JLANG::JComparisonAvailable;
95 return in.bad() || (in.fail() && !in.eof());
139 operator const T&()
const
183 object.__status =
true;
203 out <<
object.__value;
261 inline bool less(
const int value)
const
273 inline bool more(
const int value)
const
332 out <<
object.counter;
357 const std::string& help =
"") :
416 virtual void print(std::ostream& out)
const
420 out <<
"<" <<
getName() <<
">";
427 out << setw(width) <<
" ";
436 out <<
" \"" <<
getHelp() <<
"\"";
462 template<class JType_t, bool has_eq = JComparisonAvailable<JType_t>::has_eq>
469 template<
class JType_t>
501 __element.possibleValues.push_back(value);
513 template<
template<
class,
class>
class JContainer_t,
class JAllocator_t>
516 for (
typename JContainer_t<JType_t, JAllocator_t>::const_iterator i = values.begin(); i != values.end(); ++i) {
517 __element.possibleValues.push_back(*i);
530 template<
template<
class,
class,
class>
class JContainer_t,
class JCompare_t,
class JAllocator_t>
531 JCSV&
operator,(
const JContainer_t<JType_t, JCompare_t, JAllocator_t>& values)
533 for (
typename JContainer_t<JType_t, JCompare_t, JAllocator_t>::const_iterator i = values.begin(); i != values.end(); ++i) {
534 __element.possibleValues.push_back(*i);
548 template<
class JType_t>
561 const std::string&
name =
"arg",
562 const std::string& help =
"") :
565 is_initialised(false)
631 return is_initialised;
642 is_initialised = value;
652 virtual std::istream&
read(std::istream&
in)
654 if (in.peek() == EOF) {
664 while (isspace(in.peek())) {
668 if (in.peek() != EOF) {
684 virtual std::ostream&
write(std::ostream& out)
const
710 if (in.peek() != EOF) {
737 template<bool option = JLANG::JResolve<TString>::value>
755 static inline std::istream&
read(std::istream&
in,
T&
object)
789 static inline std::istream&
read(std::istream&
in,
T&
object)
791 return object.ReadLine(in);
804 for (std::string buffer; in >> buffer; ) {
805 object.push_back(TString(buffer.c_str()));
850 template<
class JType_t>
866 const std::string&
name =
"arg",
867 const std::string& help =
"") :
882 const std::string&
name,
887 setPossibleValues(__begin, __end);
902 const std::string&
name,
903 const std::string& help,
908 setPossibleValues(__begin, __end);
948 this->
object = value;
952 possibleValues.push_back(value);
964 template<
template<
class,
class>
class JContainer_t,
class JAllocator_t>
967 setPossibleValues(values.begin(), values.end());
979 template<
template<
class,
class,
class>
class JContainer_t,
class JCompare_t,
class JAllocator_t>
982 setPossibleValues(values.begin(), values.end());
999 if (possibleValues.size() > 1) {
1002 if (this->
object == *i) {
1022 virtual void print(std::ostream& out)
const
1027 writeArray(out,
" [",
"]",
", ", possibleValues.begin(), possibleValues.end());
1041 if (__begin != __end) {
1043 this->
object = *__begin;
1047 for (
T i = __begin; i != __end; ++i) {
1048 possibleValues.push_back(*i);
1081 this->
object =
false;
1094 this->
object =
true;
1106 virtual std::ostream&
write(std::ostream& out)
const
1108 return out << object;
1197 return in >> object;
1207 virtual std::ostream&
write(std::ostream& out)
const
1209 return out << object;
1298 JSharedPointer_t::operator=(static_cast<JSharedPointer_t&>(value));
1310 template<
class JType_t>
1327 template<
class JType_t>
1344 template<
class JType_t>
1366 (*this)->setInitialiationStatus(
true);
1380 (*this)->setInitialiationStatus(
false);
1396 return value->read(in);
1412 return value->write(out);
1427 return get()->
print(out);
1492 template<
class JKey_t =
char>
1494 public std::map<JKey_t, JParserElement>,
1528 const int debug = 0) :
1543 this->insert(parser.begin(), parser.end());
1557 using namespace std;
1558 using namespace JPP;
1561 out << help << endl;
1576 i->second.print(out);
1607 return (*
this)(
JArgs(argc, argv));
1619 using namespace std;
1620 using namespace JLANG;
1621 using namespace JEEP;
1629 for (JArgs::const_iterator i = args.begin(); i != args.end(); ++i) {
1631 DEBUG(
"Processing option <" << *i <<
">" << endl);
1636 for (
int c; (c =
is.get()) != EOF; ) {
1640 if (
is.peek() == EOF) {
1644 }
else if (isspace(
is.peek())) {
1649 while (
is.peek() != EOF) {
1657 if (
is.peek() != EOF) {
1677 cout <<
"source: " <<
getSource() << endl;
1691 if (
is.peek() != EOF) {
1703 if (
is.peek() == EOF && i + 1 != args.end()) {
1712 ofstream out(file_name.c_str());
1714 out << getpid() << endl;
1730 return JArgs(pid, ++i, args.end());
1740 DEBUG(
"Processing option <" << option <<
"> " << (p != this->end()) << endl);
1742 if (p != this->end()) {
1744 if (p->second->gcount()) {
1746 if (
is.peek() == EOF && i + 1 != args.end()) {
1755 catch(
const exception& error) {
1791 int read(
const int argc,
const char*
const argv[])
1793 (*this)(argc, argv);
1820 std::ostream&
write(std::ostream& out)
const
1823 out << i->second->getName() <<
'=' << i->second << std::endl;
1837 friend inline std::ostream& operator<<(std::ostream& out, const JParser<key_type>& parser)
1839 return parser.write(out);
1852 if (!p->second->getInitialisationStatus()) {
1856 if (!p->second->getStatus()) {
1903 template<
class JType_t>
1920 template<
class JType_t,
class T>
1922 const std::string&
name,
1923 const std::string& help,
1940 template<
class JType_t,
class T>
1942 const std::string&
name,
1946 return getOption(
object, name,
"", __begin, __end);
1954 #define make_field(A, ...) JPARSER::getOption(A, #A, VARGS_STRING("", ##__VA_ARGS__, ""))
1960 #define make_option(A, ...) JPARSER::getOption(A, #A, VARGS_STRING("", ##__VA_ARGS__, ""))
JArgs operator()(const JArgs &args)
Parse the program's command line options.
virtual void print(std::ostream &out) const
Print.
virtual bool gcount() const
Read counter.
Utility class to parse command line options.
Auxiliary data structure for alignment of data.
virtual bool getInitialisationStatus() const
Get initialisation status of parameter.
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 void setInitialiationStatus(const bool value)
Set initialisation status of parameter.
virtual bool getStatus() const =0
Get status of parameter.
virtual void setInitialiationStatus(const bool value)
Set initialisation status of parameter.
const JParserElement & operator=(const initialised &value)
Set initialised status to true.
virtual std::ostream & write(std::ostream &out) const
Stream output.
const char * getGITCommit()
Get GIT commit.
Template specialisation of JPARSER::JParserTemplateElement for data type with equal operator ==...
static char PRINT_OPTION
print option
const char * getGITDate()
Get GIT date.
std::string double_quote(const std::string &value)
Quote string.
virtual std::istream & read(std::istream &in)
Stream input.
std::ostream & write(std::ostream &out) const
Print the current parameter values.
std::string help
help message
friend std::istream & operator>>(std::istream &in, JParserElement &value)
Stream input.
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.
bool read(Vec &v, std::istream &is)
Read a Vec(tor) from a stream.
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.
virtual void setInitialiationStatus(const bool value)
Set initialisation status of parameter.
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
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)...
Auxiliary class to handle optional I/O.
void setPrintOption(std::ostream &out, const int option)
Set print option.
virtual bool getStatus() const
Get status of object.
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.
virtual std::istream & read(std::istream &in)
Stream input.
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.
bool getLongprint(std::ostream &out)
Get long print option.
virtual bool getInitialisationStatus() const =0
Get initialisation status of parameter.
const JCounter & operator=(const bool value)
Set value.
virtual bool getStatus() const
Status of object.
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.
virtual std::istream & read(std::istream &in)
Stream input.
void setPossibleValues(T __begin, T __end)
Set possible values.
std::ostream & write(std::ostream &out) const
virtual bool getStatus() const
Status of object.
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.
I/O formatting auxiliaries.
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.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
int read(const JArgs &args)
Parse the program's command line options.
bool is_valid(const json &js)
Check validity of JSon data.
virtual bool gcount() const
Read counter.
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.
JOption(const T &value)
Constructor.
virtual std::ostream & write(std::ostream &out) const
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
Get status of object.
virtual bool getInitialisationStatus() const
Get initialisation status of parameter.
Empty structure for specification of parser element that is not initialised (i.e. does require 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.
Interface for ASCII output using standard streams.
virtual bool getStatus() const
Get status of this counter.
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
bool less(const int value) const
Compare value.
virtual bool getInitialisationStatus() const
Get initialisation status of parameter.
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.
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
Template class holder for I/O of parser element.
virtual const char * what() const
Get error message.
virtual std::ostream & write(std::ostream &out) const
Stream output.
JParser & join(const JParser &parser)
Join parser.
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.
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