1 #ifndef __JEEP__JPARSER__
2 #define __JEEP__JPARSER__
38 namespace JPP {
using namespace JPARSER; }
50 using JLANG::JComparisonAvailable;
93 inline bool fail(std::istream& in)
95 return in.bad() || (in.fail() && !in.eof());
139 operator const T&()
const
183 object.__status =
true;
203 out <<
object.__value;
260 inline bool less(
const int value)
const
272 inline bool more(
const int value)
const
331 out <<
object.counter;
356 const std::string& help =
"") :
415 virtual void print(std::ostream& out)
const
417 out <<
"<" <<
getName() <<
">";
427 out <<
" \"" <<
getHelp() <<
"\"";
453 template<class JType_t, bool has_eq = JComparisonAvailable<JType_t>::has_eq>
460 template<
class JType_t>
492 __element.possibleValues.push_back(value);
504 template<
template<
class,
class>
class JContainer_t,
class JAllocator_t>
507 for (
typename JContainer_t<JType_t, JAllocator_t>::const_iterator i = values.begin(); i != values.end(); ++i) {
521 template<
template<
class,
class,
class>
class JContainer_t,
class JCompare_t,
class JAllocator_t>
522 JCSV&
operator,(
const JContainer_t<JType_t, JCompare_t, JAllocator_t>& values)
524 for (
typename JContainer_t<JType_t, JCompare_t, JAllocator_t>::const_iterator i = values.begin(); i != values.end(); ++i) {
539 template<
class JType_t>
552 const std::string& name =
"arg",
553 const std::string& help =
"") :
556 is_initialised(false)
568 setInitialiationStatus(
true);
582 setInitialiationStatus(
false);
598 setInitialiationStatus(
true);
611 return getInitialisationStatus();
622 return is_initialised;
633 is_initialised = value;
643 virtual std::istream&
read(std::istream& in)
645 if (in.peek() == EOF) {
655 while (isspace(in.peek())) {
659 if (in.peek() != EOF) {
663 setInitialiationStatus(
true);
675 virtual std::ostream&
write(std::ostream& out)
const
701 if (in.peek() != EOF) {
705 setInitialiationStatus(
true);
719 template<
template<
class,
class>
class JContainer_t,
class JAllocator_t>
720 inline std::istream&
read(std::istream& in, JContainer_t<TString, JAllocator_t>&
object,
const JBool<false>& option)
734 template<
template<
class,
class>
class JContainer_t,
class JAllocator_t>
735 inline std::istream&
read(std::istream& in, JContainer_t<TString, JAllocator_t>&
object,
const JBool<true>& option)
737 for (std::string buffer; in >> buffer; ) {
738 object.push_back(TString(buffer.c_str()));
758 setInitialiationStatus(
true);
767 template<
class JType_t>
783 const std::string& name =
"arg",
784 const std::string& help =
"") :
799 const std::string& name,
804 setPossibleValues(__begin, __end);
819 const std::string& name,
820 const std::string& help,
825 setPossibleValues(__begin, __end);
837 this->setInitialiationStatus(
true);
851 this->setInitialiationStatus(
false);
865 this->
object = value;
867 this->setInitialiationStatus(
true);
869 possibleValues.push_back(value);
881 template<
template<
class,
class>
class JContainer_t,
class JAllocator_t>
884 setPossibleValues(values.begin(), values.end());
896 template<
template<
class,
class,
class>
class JContainer_t,
class JCompare_t,
class JAllocator_t>
899 setPossibleValues(values.begin(), values.end());
916 if (possibleValues.size() > 1) {
919 if (this->
object == *i) {
928 return this->getInitialisationStatus();
939 virtual void print(std::ostream& out)
const
944 writeArray(out,
" [",
"]",
", ", possibleValues.begin(), possibleValues.end());
958 if (__begin != __end) {
960 this->
object = *__begin;
962 this->setInitialiationStatus(
true);
964 for (T i = __begin; i != __end; ++i) {
965 possibleValues.push_back(*i);
998 this->
object =
false;
1009 virtual std::istream&
read(std::istream& in)
1011 this->
object =
true;
1023 virtual std::ostream&
write(std::ostream& out)
const
1025 return out << object;
1112 virtual std::istream&
read(std::istream& in)
1114 return in >> object;
1124 virtual std::ostream&
write(std::ostream& out)
const
1126 return out << object;
1227 template<
class JType_t>
1244 template<
class JType_t>
1261 template<
class JType_t>
1283 (*this)->setInitialiationStatus(
true);
1297 (*this)->setInitialiationStatus(
false);
1313 return value->read(in);
1329 return value->write(out);
1344 return get()->
print(out);
1409 template<
class JKey_t =
char>
1411 public std::map<JKey_t, JParserElement>,
1445 const int debug = 0) :
1460 using namespace std;
1463 out <<
help << endl;
1478 i->second.print(out);
1494 return (*
this)(
JArgs(argc, argv));
1506 using namespace std;
1507 using namespace JLANG;
1508 using namespace JEEP;
1516 for (JArgs::const_iterator i = args.begin(); i != args.end(); ++i) {
1518 DEBUG(
"Processing option <" << *i <<
">" << endl);
1523 for (
int c; (c = is.get()) != EOF; ) {
1527 if (is.peek() == EOF) {
1531 }
else if (isspace(is.peek())) {
1536 while (is.peek() != EOF) {
1544 if (is.peek() != EOF) {
1573 if (is.peek() != EOF) {
1585 if (is.peek() == EOF && i + 1 != args.end()) {
1594 ofstream out(file_name.c_str());
1596 out << getpid() << endl;
1612 return JArgs(
pid, ++i, args.end());
1622 DEBUG(
"Processing option <" << option <<
"> " << (p != this->end()) << endl);
1624 if (p != this->end()) {
1626 if (p->second->gcount()) {
1628 if (is.peek() == EOF && i + 1 != args.end()) {
1637 catch(
const exception& error) {
1673 int read(
const int argc,
const char*
const argv[])
1675 (*this)(argc, argv);
1702 std::ostream&
write(std::ostream& out)
const
1705 out << i->second->getName() <<
'=' << i->second << std::endl;
1719 friend inline std::ostream& operator<<(std::ostream& out, const JParser<key_type>& parser)
1721 return parser.write(out);
1734 if (!p->second->getInitialisationStatus()) {
1738 if (!p->second->getStatus()) {
1785 template<
class JType_t>
1802 template<
class JType_t,
class T>
1804 const std::string& name,
1805 const std::string&
help,
1822 template<
class JType_t,
class T>
1824 const std::string& name,
1828 return getOption(
object, name,
"", __begin, __end);
1836 #define make_field(A, ...) JPARSER::getOption(A, #A, ##__VA_ARGS__)
1842 #define gmake_option(A, ...) JPARSER::getOption(A, #A, ##__VA_ARGS__)
static int debug
debug level (default is off).
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.
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.
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
JClass_t * __p
pointer to object
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.
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.
Auxiliary class to handle pointer to JPARSER::JParserElementInterface.
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.
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.
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::istream & read(std::istream &in, JContainer_t< TString, JAllocator_t > &object, const JBool< false > &option)
Auxiliary method for reading if TString does not exist.
virtual bool getStatus() const
Status of object.
void print(const TH1 &h1, std::ostream &out)
Print histogram parameters.
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.
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.
int read(const JArgs &args)
Parse the program's command line options.
virtual bool gcount() const
Read counter.
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.
const char * getGITVersion()
Get GIT version.
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. ...
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.
JSharedPointer & operator=(const JSharedPointer &object)
Assignment operator.
JCSV< JType_t > operator=(const JCSV< JType_t > &value)
Assignment operator.
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.
Interface for status of object.
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.
map_type::const_iterator const_iterator
const JParserElement & operator=(const not_initialised &value)
Set initialised status to false.
const char * getName()
Get ROOT name of given data type.
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.
virtual void reset()
Reset pointer.
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.
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