1 #ifndef __JEEP__JPARSER__ 
    2 #define __JEEP__JPARSER__ 
   14 #include <type_traits> 
   53   using JLANG::JComparisonAvailable;
 
   73     static std::ostringstream buffer;
 
  116     return in.bad() || (in.fail() && !in.eof());
 
  123   template<class T, bool is_fundamental = std::is_fundamental<T>::value>
 
  140     JProxy(
const std::string& option, 
const T& value) :
 
  197     operator const T&() 
const 
  213       __value  = 
object.__value;
 
  248         if (buffer == 
object.__option) {
 
  250           object.__value = 
object.__custom;
 
  254           istringstream 
is(buffer);
 
  256           is >> 
object.__value;
 
  258           in.setstate(is.rdstate());
 
  275       return out << 
object.__value;
 
  299     JProxy(
const std::string& option, 
const T& value) :
 
  325       return static_cast<const T&
>(*this);
 
  361       static_cast<T&
>(*this)  = 
static_cast<const T&
>(object);
 
  375       static_cast<T&
>(*this)  = value;
 
  396         if (buffer == 
object.__option) {
 
  398           static_cast<T&
>(object) = 
object.__custom;
 
  402           istringstream 
is(buffer);
 
  404           is >> 
static_cast<T&
>(object);
 
  406           in.setstate(is.rdstate());
 
  423       return out << static_cast<const T&>(object);
 
  456       return (this->counter != 0);
 
  468       return this->counter < value.
counter;
 
  478     inline bool less(
const int value)
 const 
  480       return this->counter < value;
 
  490     inline bool more(
const int value)
 const 
  492       return this->counter > value;
 
  549       out << 
object.counter;
 
  574                             const std::string& help = 
"") :
 
  608     virtual bool getStatus() 
const = 0;
 
  616     virtual bool getInitialisationStatus() 
const = 0;
 
  624     virtual void setInitialiationStatus(
const bool value) = 0;
 
  632     virtual void print(std::ostream& out)
 const  
  636       out << 
"<" << 
getName() << 
">"; 
 
  643           out << setw(width) << 
" ";
 
  652         out << 
" \"" << getHelp() << 
"\""; 
 
  678   template<class JType_t, bool has_eq = JComparisonAvailable<JType_t>::has_eq>
 
  685   template<
class JType_t>
 
  717       __element.possibleValues.push_back(value);
 
  729     template<
template<
class, 
class> 
class JContainer_t, 
class JAllocator_t>
 
  732       for (
typename JContainer_t<JType_t, JAllocator_t>::const_iterator 
i = values.begin(); 
i != values.end(); ++
i) {
 
  733         __element.possibleValues.push_back(*
i);
 
  746     template<
template<
class, 
class, 
class> 
class JContainer_t, 
class JCompare_t, 
class JAllocator_t>
 
  749       for (
typename JContainer_t<JType_t, JCompare_t, JAllocator_t>::const_iterator 
i = values.begin(); 
i != values.end(); ++
i) {
 
  750         __element.possibleValues.push_back(*
i);
 
  764   template<
class JType_t>
 
  777                            const std::string& 
name   = 
"arg",
 
  778                            const std::string& help   = 
"") :
 
  781       is_initialised(false)
 
  793       setInitialiationStatus(
true);
 
  807       setInitialiationStatus(
false);
 
  823       setInitialiationStatus(
true);
 
  836       return getInitialisationStatus(); 
 
  847       return is_initialised;
 
  858       is_initialised = value;
 
  868     virtual std::istream& 
read(std::istream& 
in)
 override  
  870       if (in.peek() == EOF) {
 
  880       while (isspace(in.peek())) {
 
  884       if (in.peek() != EOF) {
 
  888       setInitialiationStatus(
true);
 
  900     virtual std::ostream& 
write(std::ostream& out)
 const override  
  926     if (in.peek() != EOF) {
 
  930     setInitialiationStatus(
true);
 
  953   template<bool option = JLANG::JResolve<TString>::value>
 
  971     static inline std::istream& 
read(std::istream& 
in, 
T& 
object)
 
 1005     static inline std::istream& 
read(std::istream& 
in, 
T& 
object)
 
 1007       return object.ReadLine(in);
 
 1020       for (std::string buffer; in >> buffer; ) {
 
 1021         object.push_back(buffer.c_str());
 
 1040     setInitialiationStatus(
true);
 
 1057     setInitialiationStatus(
true);
 
 1066   template<
class JType_t>
 
 1082                            const std::string& 
name   = 
"arg",
 
 1083                            const std::string& help   = 
"") :
 
 1098                            const std::string& 
name,
 
 1103       setPossibleValues(__begin, __end);
 
 1118                            const std::string& 
name,
 
 1119                            const std::string& help,
 
 1124       setPossibleValues(__begin, __end);
 
 1136       this->setInitialiationStatus(
true);
 
 1150       this->setInitialiationStatus(
false);
 
 1164       this->
object = value;
 
 1166       this->setInitialiationStatus(
true);
 
 1168       possibleValues.push_back(value);
 
 1180     template<
template<
class, 
class> 
class JContainer_t, 
class JAllocator_t>
 
 1183       setPossibleValues(values.begin(), values.end());
 
 1195     template<
template<
class, 
class, 
class> 
class JContainer_t, 
class JCompare_t, 
class JAllocator_t>
 
 1198       setPossibleValues(values.begin(), values.end());
 
 1215       if (possibleValues.size() > 1) {
 
 1218           if (this->
object == *
i) {
 
 1227         return this->getInitialisationStatus(); 
 
 1237     virtual void print(std::ostream& out)
 const override  
 1242         writeArray(out, 
" [", 
"]", 
", ", possibleValues.begin(), possibleValues.end());
 
 1256       if (__begin != __end) {
 
 1258         this->
object = *__begin;
 
 1260         this->setInitialiationStatus(
true);
 
 1262         for (
T i = __begin; 
i != __end; ++
i) {
 
 1263           possibleValues.push_back(*
i);
 
 1296       this->
object = 
false;
 
 1307     virtual std::istream& 
read(std::istream& 
in)
 override  
 1309       this->
object = 
true;
 
 1321     virtual std::ostream& 
write(std::ostream& out)
 const override  
 1323       return out << object;
 
 1410     virtual std::istream& 
read(std::istream& 
in)
 override  
 1412       return in >> object;
 
 1422     virtual std::ostream& 
write(std::ostream& out)
 const override  
 1424       return out << object;
 
 1513       JSharedPointer_t::operator=(static_cast<JSharedPointer_t&>(value));
 
 1525     template<
class JType_t>
 
 1542     template<
class JType_t>
 
 1559     template<
class JType_t>
 
 1581         (*this)->setInitialiationStatus(
true);
 
 1595       (*this)->setInitialiationStatus(
false);
 
 1611         return value->read(in);
 
 1627         return value->write(out);
 
 1641         return get()->
print(out);
 
 1710   template<
class JKey_t = 
char>
 
 1712     public std::map<JKey_t, JParserElement>,
 
 1746             const int debug = 0) :
 
 1761       this->insert(parser.begin(), parser.end());
 
 1774       using namespace std;
 
 1775       using namespace JPP;
 
 1778         out << help << endl;
 
 1793         i->second.print(out);
 
 1824       return (*
this)(
JArgs(argc, argv));
 
 1836       using namespace std;
 
 1837       using namespace JLANG;
 
 1838       using namespace JEEP;
 
 1846       for (JArgs::const_iterator 
i = args.begin(); 
i != args.end(); ++
i) {
 
 1848         DEBUG(
"Processing option <" << *
i << 
">" << endl);
 
 1853         for (
int c; (
c = 
is.get()) != EOF; ) {
 
 1857             if        (
is.peek() == EOF) {                      
 
 1861             } 
else if (isspace(
is.peek())) {                    
 
 1866             while (
is.peek() != EOF) {                          
 
 1874                 if (
is.peek() != EOF) {
 
 1894                 cout << 
"source:    " << 
getSource()     << endl;
 
 1908                 if (
is.peek() != EOF) {
 
 1920                     if (
is.peek() == EOF && 
i + 1 != args.end()) {
 
 1929                     ofstream out(file_name.c_str());
 
 1931                     out << getpid() << endl;
 
 1947                 return JArgs(pid, ++
i, args.end());
 
 1957                 DEBUG(
"Processing option <" << option << 
"> " << (p != this->end()) << endl);
 
 1959                 if (p != this->end()) {
 
 1961                   if (p->second->gcount()) {
 
 1963                     if (
is.peek() == EOF && 
i + 1 != args.end()) {
 
 1972                   catch(
const exception& error) {
 
 2008     int read(
const int argc, 
const char* 
const argv[])
 
 2010       (*this)(argc, argv);
 
 2037     std::ostream& 
write(std::ostream& out)
 const 
 2040         out << 
i->second->getName() << 
'=' << 
i->second << std::endl;
 
 2054     friend inline std::ostream& operator<<(std::ostream& out, const JParser<key_type>& parser)
 
 2056       return parser.write(out); 
 
 2069         if (!p->second->getInitialisationStatus()) {
 
 2073         if (!p->second->getStatus()) {
 
 2092   template<
class JType_t>
 
 2109   template<
class JType_t, 
class T>
 
 2111                                                    const std::string& 
name,
 
 2112                                                    const std::string& help,
 
 2129   template<
class JType_t, 
class T>
 
 2131                                                    const std::string& 
name,
 
 2135     return getOption(
object, name, 
"", __begin, __end);
 
 2152 #define VARGS_STRING(A, B, ...) (static_cast<std::ostringstream&>(JPARSER::getOstream() << B << std::flush)).str() 
 2158 #define make_field(A, ...)   JPARSER::getOption(A, #A, VARGS_STRING("", ##__VA_ARGS__, "")) 
 2164 #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. 
 
const T & getValue() const 
Get actual value. 
 
friend std::istream & operator>>(std::istream &in, JProxy &object)
Read option from input. 
 
friend std::istream & operator>>(std::istream &in, JProxy &object)
Read option from input. 
 
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 T & getCustom() const 
Get custom value. 
 
Template specialisation of JPARSER::JParserTemplateElement for data type with equal operator ==...
 
JProxy & operator=(const JProxy &object)
Assignment operator. 
 
JParserTemplateElement< JType_t > getOption(JType_t &object, const std::string &name, const std::string &help="")
Auxiliary method for creation of template parser element object. 
 
static char PRINT_OPTION
print option 
 
JProxy & operator=(const T &value)
Assignment to a value. 
 
virtual void setInitialiationStatus(const bool value) override
Set initialisation status of parameter. 
 
std::string double_quote(const std::string &value)
Quote string. 
 
std::ostream & write(std::ostream &out) const 
Print the current parameter values. 
 
const char * getGITDate()
Get GIT date. 
 
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. 
 
Template specialisation of JPARSER::JParserTemplateElement for data type without equal operator ==...
 
JParserTemplateElement< JType_t > & operator=(JType_t &value)
Assignment operator. 
 
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. 
 
Auxiliary class to handle pointer to JPARSER::JParserElementInterface. 
 
JProxy & operator=(const JProxy &object)
Assignment operator. 
 
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. 
 
friend std::ostream & operator<<(std::ostream &out, const JProxy &object)
Write options to output. 
 
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. 
 
const JCounter & operator=(const bool value)
Set value. 
 
static char REVISION_OPTION
revision option 
 
const T & getCustom() const 
Get custom value. 
 
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. 
 
JProxy(const T &value)
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. 
 
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. 
 
JProxy & operator=(const T &value)
Assignment to a value. 
 
virtual bool getStatus() const override
Get status of object. 
 
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. 
 
then fatal The output file must have the wildcard in the name
 
JLANG::JParserException JParserException
 
bool fail(std::istream &in)
Check for stream state. 
 
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. 
 
const std::string & getOption() const 
Get option. 
 
JParserElementInterface(const std::string &name="arg", const std::string &help="")
Constructor. 
 
std::map< key_type, JParserElement > map_type
 
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. 
 
Auxiliary class to assign a custom value following the reading of a specific textual value...
 
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 The output file must have the wildcard in the e g root fi 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
 
bool write(const Vec &v, std::ostream &os)
Write a Vec(tor) to a stream. 
 
virtual std::istream & read(std::istream &in) override
Stream input. 
 
const T & getValue() const 
Get actual value. 
 
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. 
 
JProxy(const std::string &option, const T &value)
Constructor. 
 
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. 
 
const char * getGITCommit()
Get GIT commit. 
 
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. 
 
friend std::ostream & operator<<(std::ostream &out, const JProxy &object)
Write options to output. 
 
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. 
 
JProxy(const T &value)
Constructor. 
 
std::string pid
process name 
 
virtual bool gcount() const override
Read counter. 
 
Template class holder for I/O of parser element. 
 
const std::string & getOption() const 
Get option. 
 
JParser & join(const JParser &parser)
Join parser. 
 
virtual void setInitialiationStatus(const bool value) override
Set initialisation status of parameter. 
 
JProxy(const std::string &option, const T &value)
Constructor. 
 
friend std::ostream & operator<<(std::ostream &out, const JParserElement &value)
Stream output. 
 
JParserTemplateElement(JCounter &object, const std::string &name, const std::string &help="")
Constructor. 
 
const std::string & getHelp() const 
Get help of parameter. 
 
bool less(const JCounter &value) const 
Compare value. 
 
std::istream & read(std::istream &in)
 
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