Go to the documentation of this file. 1 #ifndef __JEEP__JPARSER__
2 #define __JEEP__JPARSER__
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;
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;
1092 virtual std::istream&
read(std::istream& in)
1094 this->
object =
true;
1106 virtual std::ostream&
write(std::ostream& out)
const
1108 return out << object;
1195 virtual std::istream&
read(std::istream& in)
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;
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__, ""))
void setPossibleValues(T __begin, T __end)
Set possible values.
void print(std::ostream &out) const
Print.
Template specialisation of JPARSER::JParserTemplateElement for type bool.
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.
JParserTemplateElement< bool > getOption(bool &object, const std::string &name, const std::string &help="")
Auxiliary method for creation of template parser element object.
virtual bool getInitialisationStatus() const
Get initialisation status of parameter.
Test availability of comparison operators of non-composite data types.
const JOption< T > & operator=(const T &value)
Assignment to a value.
const JParserElement & operator=(const not_initialised &value)
Set initialised status to false.
friend std::istream & operator>>(std::istream &in, JOption &object)
Read option from input.
JCSV< JType_t > operator=(const JContainer_t< JType_t, JAllocator_t > &values)
Assignment to a default value and possible other values.
virtual void setInitialiationStatus(const bool value)
Set initialisation status of parameter.
virtual bool gcount() const
Read counter.
Data structure to store command line arguments.
static std::istream & read(std::istream &in, T &object)
Read object from input stream.
virtual std::istream & read(std::istream &in)
Stream input.
JSharedPointer< JParserElementInterface > JSharedPointer_t
virtual bool gcount() const
Read counter.
map_type::iterator iterator
Auxiliary class for handling I/O of TString depending on its existence.
std::string help
help message
Template specialisation of JPARSER::JParserTemplateElement for type JCounter.
std::ostream & write(std::ostream &out) const
Template specialisation of JParserTemplateElement<std::string>::write to surround text with quotes.
virtual bool getInitialisationStatus() const =0
Get initialisation status of parameter.
const char * getGITCommit()
Get GIT commit.
JCSV & operator,(const JContainer_t< JType_t, JAllocator_t > &values)
Parsing of additional possible values.
const std::string & getHelp() const
Get help of parameter.
std::vector< JType_t > possibleValues
virtual std::ostream & write(std::ostream &out) const
Stream output.
virtual bool getStatus() const
Get status of this counter.
virtual bool gcount() const
Read counter.
std::ostream & writeArray(std::ostream &out, const char *left, const char *right, const char *sep, T __begin, T __end)
Write array of objects.
General puprpose classes and methods.
bool is_valid(const T &value)
Check validity of given value.
Interface for status of object.
std::string double_quote(const std::string &value)
Quote string.
friend std::ostream & operator<<(std::ostream &out, const JParser< key_type > &parser)
Stream output.
Empty structure for specification of parser element that is initialised (i.e.
virtual void print(std::ostream &out) const
Print.
void setPrintOption(std::ostream &out, const int option)
Set print option.
virtual bool getInitialisationStatus() const
Get initialisation status of parameter.
void check_status() const
Check if all required options have been set.
virtual bool getStatus() const
Status of object.
const std::string & getName() const
Get name of parameter.
JParser(const int debug=0)
Default constructor.
int read(const JArgs &args)
Parse the program's command line options.
virtual void terminate(const int status)
Terminate.
JParserTemplateElement< JType_t > & operator=(const JParserTemplateElement< JType_t > &value)
Assignment operator.
JParserElement()
Default constructor.
Utility class to parse command line options.
virtual std::istream & read(std::istream &in)
Stream input.
map_type::const_iterator const_iterator
virtual bool getStatus() const =0
Get status of parameter.
Auxiliary class to handle pointer to JPARSER::JParserElementInterface.
std::ostream & write(std::ostream &out) const
Print the current parameter values.
Template specialisation of JPARSER::JParserTemplateElement for data type with equal operator ==.
JParserElement & operator=(JParserElement &value)
Assignment operator.
Template specialisation of JPARSER::JParserTemplateElement for data type without equal operator ==.
std::istream & read(std::istream &in)
Template specialisation of JParserTemplateElement<std::string>::read to read complete line from strea...
Interface for ASCII output using standard streams.
JCSV< JType_t > operator=(const JType_t &value)
Assignment to a default value and possible other values.
virtual void setInitialiationStatus(const bool value)=0
Set initialisation status of parameter.
bool getStatus() const
Get status.
virtual bool getStatus() const
Get status of object.
virtual bool getStatus() const
Status of object.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
JOption()
Default constructor.
const JParserTemplateElement< JType_t, false > & operator=(const initialised &value)
Set initialised status to true.
static std::istream & read(std::istream &in, std::vector< T > &object)
Read std::vector of objects from input stream.
JCSV(JParserTemplateElement< JType_t > &element)
Constructor.
Auxiliary class to handle multiple boolean-like I/O.
JParserTemplateElement< JType_t > & __element
friend std::ostream & operator<<(std::ostream &out, const JOption &object)
Write options to output.
bool getLongprint(std::ostream &out)
Get long print option.
JParserTemplateElement< JType_t > & operator=(JType_t &value)
Assignment operator.
JParserElementInterface(const std::string &name="arg", const std::string &help="")
Constructor.
JArgs operator()(const JArgs &args)
Parse the program's command line options.
std::istream & readObject(std::istream &in, T &object)
Stream input of object.
virtual bool getStatus() const
Get status of object.
std::string getNamespace(const std::string &type_name)
Get name space, i.e.
JParserTemplateElement(JType_t &object, const std::string &name="arg", const std::string &help="")
Constructor.
virtual std::istream & read(std::istream &in)
Stream input.
Auxiliary data structure for alignment of data.
Exception when parsing a value.
T * clone() const
Get clone of this object.
virtual void print(std::ostream &out) const
Print.
bool less(const int value) const
Compare value.
friend std::ostream & operator<<(std::ostream &out, const JCounter &object)
Write options to output.
const JParserElement & operator=(const initialised &value)
Set initialised status to true.
bool more(const int value) const
Compare value.
static char REVISION_OPTION
revision option
virtual std::ostream & write(std::ostream &out) const
Stream output.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
JCSV< JType_t > operator=(const JContainer_t< JType_t, JCompare_t, JAllocator_t > &values)
Assignment to a default value and possible other values.
virtual std::ostream & write(std::ostream &out) const
Stream output.
friend std::istream & operator>>(std::istream &in, JCounter &object)
Read option from input.
std::string getFilename(const std::string &file_name)
Get file name part, i.e.
const char * getGITVersion()
Get GIT version.
Interface for I/O of parser element.
int getCounter() const
Get counter.
std::ostream & writeObject(std::ostream &out, const T &object)
Stream output of object.
JCSV & operator,(JType_t value)
Parsing of additional possible values.
Auxiliary template class for type bool.
static std::istream & read(std::istream &in, T &object)
Read object from input stream.
virtual void setInitialiationStatus(const bool value)
Set initialisation status of parameter.
bool less(const JCounter &value) const
Compare value.
JParser & join(const JParser &parser)
Join parser.
static char END_OF_OPTIONS
end of all options
void reset(JCLBInput &data, size_t size)
Reset CLB buffers.
JParserTemplateElement(bool &object, const std::string &name="arg", const std::string &help="")
Constructor.
bool read(Vec &v, std::istream &is)
Read a Vec(tor) from a stream.
std::map< key_type, JParserElement > map_type
JArgs operator()(const int argc, const char *const argv[])
Parse the program's command line options.
const JParserTemplateElement< JType_t, false > & operator=(const JType_t &value)
Assignment to a default value.
virtual bool getInitialisationStatus() const
Get initialisation status of parameter.
Template definition of auxiliary base class for comparison of data structures.
bool fail(std::istream &in)
Check for stream state.
JOption(const T &value)
Constructor.
#define DEBUG(A)
Message macros.
static int NORMAL_EXIT_CODE
exit code of normal end
Auxiliary class to assign the remainder of a sequence of Comma Separated Values.
static char START_OF_OPTION
Parser options.
virtual std::ostream & write(std::ostream &out) const =0
Stream output.
JParserTemplateElement(JType_t &object, const std::string &name="arg", const std::string &help="")
Constructor.
virtual void setInitialiationStatus(const bool value)
Set initialisation status of parameter.
JCounter()
Default constructor.
JParserElement(const JParserElement &value)
Copy constructor.
virtual const char * what() const
Get error message.
JParserTemplateElement(JType_t &object, const std::string &name, T __begin, T __end)
Constructor.
JParserTemplateElement(JCounter &object, const std::string &name, const std::string &help="")
Constructor.
Auxiliary class to handle optional I/O.
const JParserTemplateElement< JType_t, true > & operator=(const not_initialised &value)
Set initialised status to false.
void print(const TH1 &h1, std::ostream &out)
Print histogram parameters.
friend std::ostream & operator<<(std::ostream &out, const JParserElement &value)
Stream output.
T get(const JHead &header)
Get object from header.
JParser(const std::string &message, const int debug=0)
Constructor.
Auxiliary classes and methods for language specific functionality.
std::string getURL()
Get URL of document pages.
JCSV< JType_t > operator=(const JCSV< JType_t > &value)
Assignment operator.
JLANG::JParserException JParserException
Template class holder for I/O of parser element.
JCSV & operator,(const JContainer_t< JType_t, JCompare_t, JAllocator_t > &values)
Parsing of additional possible values.
const JCounter & operator=(const bool value)
Set value.
const JParserTemplateElement< JType_t, false > & operator=(const not_initialised &value)
Set initialised status to false.
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
friend std::istream & operator>>(std::istream &in, JParserElement &value)
Stream input.
const char * getSource()
Get source.
Empty structure for specification of parser element that is not initialised (i.e.
std::string pid
process name
Auxiliary class for handling debug parameter within a class.
static char PRINT_OPTION
print option
bool getShortprint(std::ostream &out)
Get short print option.
static char HELP_OPTION
help option
void print(std::ostream &out) const
Print the possible command line options.
The template JSharedPointer class can be used to share a pointer to an object.
static std::istream & read(std::istream &in, std::vector< T > &object)
Read std::vector of objects from input stream.
int read(const int argc, const char *const argv[])
Parse the program's command line options.
bool is_valid() const
Check validity of pointer.
static char PID_OPTION
print PID to file
const char * getGITDate()
Get GIT date.