Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JParser.hh
Go to the documentation of this file.
1 #ifndef __JEEP__JPARSER__
2 #define __JEEP__JPARSER__
3 
4 #include <sys/types.h>
5 #include <unistd.h>
6 #include <stdio.h>
7 #include <string>
8 #include <iostream>
9 #include <sstream>
10 #include <fstream>
11 #include <vector>
12 #include <map>
13 #include <ctype.h>
14 
15 #include "JLang/Jpp.hh"
16 #include "JLang/JAbstractIO.hh"
17 #include "JLang/JException.hh"
18 #include "JLang/JSharedPointer.hh"
20 #include "JLang/JComparable.hh"
22 #include "JLang/JBool.hh"
23 #include "JLang/JResolve.hh"
24 
25 #include "Jeep/JStreamToolkit.hh"
26 #include "Jeep/JeepToolkit.hh"
27 #include "Jeep/JArgs.hh"
28 #include "Jeep/JMessage.hh"
29 #include "Jeep/JPrint.hh"
30 
31 
32 /**
33  * \file
34  * Utility class to parse command line options.
35  * \author mdejong
36  */
37 namespace JPARSER {}
38 namespace JPP { using namespace JPARSER; }
39 
40 class TString; //<! Forward declaration of ROOT class
41 
42 namespace JPARSER {
43 
44  using JLANG::JStreamInput;
49  using JLANG::JComparable;
50  using JLANG::JComparisonAvailable;
51  using JLANG::JBool;
52 
53  using JEEP::readObject;
54  using JEEP::writeObject;
55  using JEEP::writeArray;
56  using JEEP::getFilename;
57  using JEEP::JArgs;
58  using JEEP::JMessage;
59 
60 
61  /**
62  * Empty structure for specification of parser element that is initialised (i.e. does not require input).
63  */
64  struct initialised {};
65 
66 
67  /**
68  * Empty structure for specification of parser element that is not initialised (i.e. does require input).
69  */
70  struct not_initialised {};
71 
72 
73  /**
74  * Parser options.
75  */
76  static char START_OF_OPTION = '-'; //!< start of an option
77  static char END_OF_OPTIONS = '-'; //!< end of all options
78  static char HELP_OPTION = 'h'; //!< help option
79  static char REVISION_OPTION = 'v'; //!< revision option
80  static char PRINT_OPTION = '!'; //!< print option
81  static char PID_OPTION = 'P'; //!< print PID to file
82  static int NORMAL_EXIT_CODE = 0; //!< exit code of normal end
83 
84 
85  /**
86  * Check for stream state.
87  *
88  * Note that end-of-file is not defined as an error so to normally process e.g. std::string and std::vector.
89  *
90  * \param in input stream
91  * \return true if failure; else false
92  */
93  inline bool fail(std::istream& in)
94  {
95  return in.bad() || (in.fail() && !in.eof());
96  }
97 
98 
99  /**
100  * Auxiliary class to handle optional I/O.
101  */
102  template<class T>
103  class JOption {
104  public:
105  /**
106  * Default constructor.
107  */
109  __status(false),
110  __value()
111  {}
112 
113 
114  /**
115  * Constructor.
116  */
117  JOption(const T& value) :
118  __status(false),
119  __value(value)
120  {}
121 
122 
123  /**
124  * Get status.
125  *
126  * \return status
127  */
128  bool getStatus() const
129  {
130  return __status;
131  }
132 
133 
134  /**
135  * Type conversion operator.
136  *
137  * \return object
138  */
139  operator const T&() const
140  {
141  return __value;
142  }
143 
144 
145  /**
146  * Assignment to a value.
147  *
148  * \param value value
149  * \return this object
150  */
151  const JOption<T>& operator=(const T& value)
152  {
153  __status = true;
154  __value = value;
155 
156  return *this;
157  }
158 
159 
160  /**
161  * Get clone of this object.
162  *
163  * \return pointer to newly created object if status is okay; else NULL
164  */
165  T* clone() const
166  {
167  if (__status)
168  return new T(__value);
169  else
170  return NULL;
171  }
172 
173 
174  /**
175  * Read option from input.
176  *
177  * \param in input stream
178  * \param object option
179  * \return input stream
180  */
181  friend inline std::istream& operator>>(std::istream& in, JOption& object)
182  {
183  object.__status = true;
184 
185  if (!(in >> object.__value)) {
186  in.clear();
187  }
188 
189  return in;
190  }
191 
192 
193  /**
194  * Write options to output.
195  *
196  * \param out output stream
197  * \param object option
198  * \return output stream
199  */
200  friend inline std::ostream& operator<<(std::ostream& out, const JOption& object)
201  {
202  if (object.__status) {
203  out << object.__value;
204  }
205 
206  return out;
207  }
208 
209  protected:
210  bool __status;
212  };
213 
214 
215  /**
216  * Auxiliary class to handle multiple boolean-like I/O.
217  */
218  class JCounter :
219  public JAbstractObjectStatus,
220  public JComparable<JCounter, int>
221  {
222  public:
223  /**
224  * Default constructor.
225  */
227  counter(0)
228  {}
229 
230 
231  /**
232  * Get status of this counter.
233  *
234  * \return true if counter not zero; else false
235  */
236  virtual bool getStatus() const
237  {
238  return (this->counter != 0);
239  }
240 
241 
242  /**
243  * Compare value.
244  *
245  * \param value value
246  * \return true if this counter is less than given value; else false
247  */
248  inline bool less(const JCounter& value) const
249  {
250  return this->counter < value.counter;
251  }
252 
253 
254  /**
255  * Compare value.
256  *
257  * \param value value
258  * \return true if this counter is less than given value; else false
259  */
260  inline bool less(const int value) const
261  {
262  return this->counter < value;
263  }
264 
265 
266  /**
267  * Compare value.
268  *
269  * \param value value
270  * \return true if this counter is more than given value; else false
271  */
272  inline bool more(const int value) const
273  {
274  return this->counter > value;
275  }
276 
277 
278  /**
279  * Get counter.
280  *
281  * \return counter
282  */
283  int getCounter() const
284  {
285  return counter;
286  }
287 
288 
289  /**
290  * Set value.
291  *
292  * Note that no assignment actually takes place but the internal counter is set to one.
293  *
294  * \param value value
295  * \return this object
296  */
297  const JCounter& operator=(const bool value)
298  {
299  counter = 1;
300 
301  return *this;
302  }
303 
304 
305  /**
306  * Read option from input.
307  *
308  * Note that no value actually is read, only the internal counter is incremented.
309  *
310  * \param in input stream
311  * \param object option
312  * \return input stream
313  */
314  friend inline std::istream& operator>>(std::istream& in, JCounter& object)
315  {
316  ++object.counter;
317 
318  return in;
319  }
320 
321 
322  /**
323  * Write options to output.
324  *
325  * \param out output stream
326  * \param object option
327  * \return output stream
328  */
329  friend inline std::ostream& operator<<(std::ostream& out, const JCounter& object)
330  {
331  out << object.counter;
332 
333  return out;
334  }
335 
336  protected:
337  int counter;
338  };
339 
340 
341  /**
342  * Interface for I/O of parser element.
343  */
345  public JStreamInput,
346  public JStreamOutput
347  {
348  protected:
349  /**
350  * Constructor.
351  *
352  * \param name name of object
353  * \param help help of object
354  */
355  JParserElementInterface(const std::string& name = "arg",
356  const std::string& help = "") :
357  __name(name),
358  __help(help)
359  {}
360 
361 
362  public:
363  /**
364  * Get name of parameter.
365  *
366  * \return name
367  */
368  const std::string& getName() const
369  {
370  return __name;
371  }
372 
373 
374  /**
375  * Get help of parameter.
376  *
377  * \return help
378  */
379  const std::string& getHelp() const
380  {
381  return __help;
382  }
383 
384 
385  /**
386  * Get status of parameter.
387  *
388  * \return status
389  */
390  virtual bool getStatus() const = 0;
391 
392 
393  /**
394  * Get initialisation status of parameter.
395  *
396  * \return status
397  */
398  virtual bool getInitialisationStatus() const = 0;
399 
400 
401  /**
402  * Set initialisation status of parameter.
403  *
404  * \param value initialisation status
405  */
406  virtual void setInitialiationStatus(const bool value) = 0;
407 
408 
409  /**
410  * Print.
411  *
412  * \param out output stream
413  * \return output stream
414  */
415  virtual void print(std::ostream& out) const
416  {
417  out << "<" << getName() << ">";
418 
419  if (getStatus() && !getShortprint(out)) {
420 
421  out << " = ";
422 
423  write(out);
424  }
425 
426  if (getLongprint(out) && getHelp() != "") {
427  out << " \"" << getHelp() << "\"";
428  }
429  }
430 
431 
432  /**
433  * Read counter.
434  *
435  * \return true if at least one character to be read; else false
436  */
437  virtual bool gcount() const
438  {
439  return true;
440  }
441 
442 
443  protected:
444  std::string __name;
445  std::string __help;
446  };
447 
448 
449  /**
450  * Template class holder for I/O of parser element.
451  * This class implements the JPARSER::JParserElementInterface interface.
452  */
453  template<class JType_t, bool has_eq = JComparisonAvailable<JType_t>::has_eq>
455 
456 
457  /**
458  * Auxiliary class to assign the remainder of a sequence of Comma Separated Values.
459  */
460  template<class JType_t>
461  class JCSV {
462  public:
463  /**
464  * Constructor.
465  *
466  * \param element parser element
467  */
469  __element(element)
470  {}
471 
472 
473  /**
474  * Type conversion operator.
475  *
476  * \return parser element
477  */
478  operator const JParserTemplateElement<JType_t>&() const
479  {
480  return __element;
481  }
482 
483 
484  /**
485  * Parsing of additional possible values.
486  *
487  * \param value possible value
488  * \return this JCSV object
489  */
490  JCSV& operator,(JType_t value)
491  {
492  __element.possibleValues.push_back(value);
493 
494  return *this;
495  }
496 
497 
498  /**
499  * Parsing of additional possible values.
500  *
501  * \param values possible values
502  * \return this object
503  */
504  template<template<class, class> class JContainer_t, class JAllocator_t>
505  JCSV& operator,(const JContainer_t<JType_t, JAllocator_t>& values)
506  {
507  for (typename JContainer_t<JType_t, JAllocator_t>::const_iterator i = values.begin(); i != values.end(); ++i) {
508  __element.possibleValues.push_back(*i);
509  }
510 
511  return *this;
512  }
513 
514 
515  /**
516  * Parsing of additional possible values.
517  *
518  * \param values possible values
519  * \return this object
520  */
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)
523  {
524  for (typename JContainer_t<JType_t, JCompare_t, JAllocator_t>::const_iterator i = values.begin(); i != values.end(); ++i) {
525  __element.possibleValues.push_back(*i);
526  }
527 
528  return *this;
529  }
530 
531  private:
533  };
534 
535 
536  /**
537  * Template specialisation of JPARSER::JParserTemplateElement for data type without equal operator <tt>==</tt>.
538  */
539  template<class JType_t>
540  class JParserTemplateElement<JType_t, false> :
542  {
543  public:
544  /**
545  * Constructor.
546  *
547  * \param object reference to object
548  * \param name name of object
549  * \param help help of object
550  */
551  JParserTemplateElement(JType_t& object,
552  const std::string& name = "arg",
553  const std::string& help = "") :
554  JParserElementInterface(name, help),
555  object(object),
556  is_initialised(false)
557  {}
558 
559 
560  /**
561  * Set initialised status to true.
562  *
563  * \param value initialised object
564  * \return this object
565  */
567  {
568  setInitialiationStatus(true);
569 
570  return *this;
571  }
572 
573 
574  /**
575  * Set initialised status to false.
576  *
577  * \param value initialised object
578  * \return this object
579  */
581  {
582  setInitialiationStatus(false);
583 
584  return *this;
585  }
586 
587 
588  /**
589  * Assignment to a default value.
590  *
591  * \param value default value
592  * \return this object
593  */
595  {
596  object = value;
597 
598  setInitialiationStatus(true);
599 
600  return *this;
601  }
602 
603 
604  /**
605  * Get status of object.
606  *
607  * \return true if current value is ok, else false
608  */
609  virtual bool getStatus() const
610  {
611  return getInitialisationStatus();
612  }
613 
614 
615  /**
616  * Get initialisation status of parameter.
617  *
618  * \return status
619  */
620  virtual bool getInitialisationStatus() const
621  {
622  return is_initialised;
623  }
624 
625 
626  /**
627  * Set initialisation status of parameter.
628  *
629  * \param value initialisation status
630  */
631  virtual void setInitialiationStatus(const bool value)
632  {
633  is_initialised = value;
634  }
635 
636 
637  /**
638  * Stream input.
639  *
640  * \param in input stream
641  * \return input stream
642  */
643  virtual std::istream& read(std::istream& in)
644  {
645  if (in.peek() == EOF) {
646  THROW(JParserException, "JParser: error no data for parameter " << getName());
647  }
648 
649  readObject(in, object);
650 
651  if (fail(in)) {
652  THROW(JParserException, "JParser: error reading parameter " << getName());
653  }
654 
655  while (isspace(in.peek())) {
656  in.get();
657  }
658 
659  if (in.peek() != EOF) {
660  THROW(JParserException, "JParser: pending data after reading parameter " << getName());
661  }
662 
663  setInitialiationStatus(true);
664 
665  return in;
666  }
667 
668 
669  /**
670  * Stream output.
671  *
672  * \param out output stream
673  * \return output stream
674  */
675  virtual std::ostream& write(std::ostream& out) const
676  {
677  return writeObject(out, object);
678  }
679 
680  protected:
681  JType_t& object;
683  };
684 
685 
686  /**
687  * Template specialisation of JParserTemplateElement<std::string>::read to read complete line from stream input.
688  *
689  * \param in input stream
690  * \return input stream
691  */
692  template<>
693  inline std::istream& JParserTemplateElement<std::string, false>::read(std::istream& in)
694  {
695  std::getline(in, object);
696 
697  if (fail(in)) {
698  THROW(JParserException, "JParser: error reading parameter " << getName());
699  }
700 
701  if (in.peek() != EOF) {
702  THROW(JParserException, "JParser: pending data after reading parameter " << getName());
703  }
704 
705  setInitialiationStatus(true);
706 
707  return in;
708  }
709 
710 
711  /**
712  * Auxiliary method for reading if TString does not exist.
713  *
714  * \param in input stream
715  * \param object object
716  * \param option
717  * \return input stream
718  */
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)
721  {
722  THROW(JParserException, "JParser: invalid data type TString (include TString.h before JParser.hh)");
723  }
724 
725 
726  /**
727  * Auxiliary method for reading if TString exists.
728  *
729  * \param in input stream
730  * \param object object
731  * \param option
732  * \return input stream
733  */
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)
736  {
737  for (std::string buffer; in >> buffer; ) {
738  object.push_back(TString(buffer.c_str()));
739  }
740 
741  return in;
742  }
743 
744 
745  /**
746  * Template specialisation of JParserTemplateElement< std::vector<TString> >::read to read tokens from stream input.
747  *
748  * \param in input stream
749  * \return input stream
750  */
751  template<>
752  inline std::istream& JParserTemplateElement<std::vector<TString>, false>::read(std::istream& in)
753  {
754  using namespace JPP;
755 
756  JPARSER::read(in, object, JBool<JResolve<TString>::value>());
757 
758  setInitialiationStatus(true);
759 
760  return in;
761  }
762 
763 
764  /**
765  * Template specialisation of JPARSER::JParserTemplateElement for data type with equal operator <tt>==</tt>.
766  */
767  template<class JType_t>
768  class JParserTemplateElement<JType_t, true> :
769  public JParserTemplateElement<JType_t, false>
770  {
771  public:
772 
773  friend class JCSV<JType_t>;
774 
775  /**
776  * Constructor.
777  *
778  * \param object reference to object
779  * \param name name of object
780  * \param help help of object
781  */
782  JParserTemplateElement(JType_t& object,
783  const std::string& name = "arg",
784  const std::string& help = "") :
785  JParserTemplateElement<JType_t, false>(object, name, help)
786  {}
787 
788 
789  /**
790  * Constructor.
791  *
792  * \param object reference to object
793  * \param name name of object
794  * \param __begin begin of possible values
795  * \param __end end of possible values
796  */
797  template<class T>
798  JParserTemplateElement(JType_t& object,
799  const std::string& name,
800  T __begin,
801  T __end) :
802  JParserTemplateElement<JType_t, false>(object, name)
803  {
804  setPossibleValues(__begin, __end);
805  }
806 
807 
808  /**
809  * Constructor.
810  *
811  * \param object reference to object
812  * \param name name of object
813  * \param help help of object
814  * \param __begin begin of possible values
815  * \param __end end of possible values
816  */
817  template<class T>
818  JParserTemplateElement(JType_t& object,
819  const std::string& name,
820  const std::string& help,
821  T __begin,
822  T __end) :
823  JParserTemplateElement<JType_t, false>(object, name, help)
824  {
825  setPossibleValues(__begin, __end);
826  }
827 
828 
829  /**
830  * Set initialised status to true.
831  *
832  * \param value initialised object
833  * \return this object
834  */
836  {
837  this->setInitialiationStatus(true);
838 
839  return *this;
840  }
841 
842 
843  /**
844  * Set initialised status to false.
845  *
846  * \param value initialised object
847  * \return this object
848  */
850  {
851  this->setInitialiationStatus(false);
852 
853  return *this;
854  }
855 
856 
857  /**
858  * Assignment to a default value and possible other values.
859  *
860  * \param value default value
861  * \return comma separated values parser
862  */
863  JCSV<JType_t> operator=(const JType_t& value)
864  {
865  this->object = value;
866 
867  this->setInitialiationStatus(true);
868 
869  possibleValues.push_back(value);
870 
871  return JCSV<JType_t>(*this);
872  }
873 
874 
875  /**
876  * Assignment to a default value and possible other values.
877  *
878  * \param values default values
879  * \return this object
880  */
881  template<template<class, class> class JContainer_t, class JAllocator_t>
882  JCSV<JType_t> operator=(const JContainer_t<JType_t, JAllocator_t>& values)
883  {
884  setPossibleValues(values.begin(), values.end());
885 
886  return JCSV<JType_t>(*this);
887  }
888 
889 
890  /**
891  * Assignment to a default value and possible other values.
892  *
893  * \param values default values
894  * \return this object
895  */
896  template<template<class, class, class> class JContainer_t, class JCompare_t, class JAllocator_t>
897  JCSV<JType_t> operator=(const JContainer_t<JType_t, JCompare_t, JAllocator_t>& values)
898  {
899  setPossibleValues(values.begin(), values.end());
900 
901  return JCSV<JType_t>(*this);
902  }
903 
904 
905  /**
906  * Get status of object.
907  *
908  * If more than one possible values are provided,
909  * the current value should be equal to one of the possible values,
910  * else a value should have been set by the user.
911  *
912  * \return true if current value is ok, else false
913  */
914  virtual bool getStatus() const
915  {
916  if (possibleValues.size() > 1) {
917 
918  for (typename std::vector<JType_t>::const_iterator i = possibleValues.begin(); i != possibleValues.end(); ++i) {
919  if (this->object == *i) {
920  return true;
921  }
922  }
923 
924  return false;
925 
926  } else {
927 
928  return this->getInitialisationStatus();
929  }
930  }
931 
932 
933  /**
934  * Print.
935  *
936  * \param out output stream
937  * \return output stream
938  */
939  virtual void print(std::ostream& out) const
940  {
942 
943  if (possibleValues.size() > 1 && getLongprint(out)) {
944  writeArray(out, " [", "]", ", ", possibleValues.begin(), possibleValues.end());
945  }
946  }
947 
948  protected:
949  /**
950  * Set possible values.
951  *
952  * \param __begin begin of possible values
953  * \param __end end of possible values
954  */
955  template<class T>
956  void setPossibleValues(T __begin, T __end)
957  {
958  if (__begin != __end) {
959 
960  this->object = *__begin;
961 
962  this->setInitialiationStatus(true);
963 
964  for (T i = __begin; i != __end; ++i) {
965  possibleValues.push_back(*i);
966  }
967  }
968  }
969 
971  };
972 
973 
974  /**
975  * Template specialisation of JPARSER::JParserTemplateElement for type <tt>bool</tt>.
976  * The value is by default set to false and set to true in method read() without reading any data.
977  * This makes it possible to parse mutiple options in one go (e.g. <tt>-abc</tt>).
978  * This class implements the JPARSER::JParserElementInterface interface.
979  */
980  template<>
981  class JParserTemplateElement<bool> :
983  {
984  public:
985  /**
986  * Constructor.
987  *
988  * The constructor assigns the default value false to the referenced parameter.
989  *
990  * \param object reference to object
991  * \param name name of object
992  * \param help help of object
993  */
994  JParserTemplateElement(bool& object, const std::string& name = "arg", const std::string& help = "") :
995  JParserElementInterface(name, help),
996  object(object)
997  {
998  this->object = false;
999  }
1000 
1001 
1002  /**
1003  * Stream input.
1004  * This method sets the value to true, without reading any data.
1005  *
1006  * \param in input stream
1007  * \return input stream
1008  */
1009  virtual std::istream& read(std::istream& in)
1010  {
1011  this->object = true;
1012 
1013  return in;
1014  }
1015 
1016 
1017  /**
1018  * Stream output.
1019  *
1020  * \param out output stream
1021  * \return output stream
1022  */
1023  virtual std::ostream& write(std::ostream& out) const
1024  {
1025  return out << object;
1026  }
1027 
1028 
1029  /**
1030  * Status of object.
1031  *
1032  * \return true
1033  */
1034  virtual bool getStatus() const
1035  {
1036  return true;
1037  }
1038 
1039 
1040  /**
1041  * Get initialisation status of parameter.
1042  *
1043  * \return true
1044  */
1045  virtual bool getInitialisationStatus() const
1046  {
1047  return true;
1048  }
1049 
1050 
1051  /**
1052  * Set initialisation status of parameter.
1053  * This implementation doesn't do anything.
1054  *
1055  * \param value initialisation status
1056  */
1057  virtual void setInitialiationStatus(const bool value)
1058  {}
1059 
1060 
1061  /**
1062  * Read counter.
1063  *
1064  * \return true if at least one character to be read; else false
1065  */
1066  virtual bool gcount() const
1067  {
1068  return false;
1069  }
1070 
1071 
1072  private:
1073  bool& object;
1074  };
1075 
1076 
1077  /**
1078  * Template specialisation of JPARSER::JParserTemplateElement for type <tt>JCounter</tt>.
1079  * The value is by default set to zero and set incremented in method read() without reading any data.
1080  * This makes it possible to parse mutiple options in one go (e.g. <tt>-aaa</tt>).
1081  * This class implements the JPARSER::JParserElementInterface interface.
1082  */
1083  template<>
1085  public JParserElementInterface
1086  {
1087  public:
1088  /**
1089  * Constructor.
1090  *
1091  * The constructor assigns the default value false to the referenced parameter.
1092  *
1093  * \param object reference to object
1094  * \param name name of object
1095  * \param help help of object
1096  */
1097  JParserTemplateElement(JCounter& object, const std::string& name, const std::string& help = "") :
1098  JParserElementInterface(name, help),
1099  object(object)
1100  {
1101  this->object = JCounter();
1102  }
1103 
1104 
1105  /**
1106  * Stream input.
1107  * This method sets the value to true, without reading any data.
1108  *
1109  * \param in input stream
1110  * \return input stream
1111  */
1112  virtual std::istream& read(std::istream& in)
1113  {
1114  return in >> object;
1115  }
1116 
1117 
1118  /**
1119  * Stream output.
1120  *
1121  * \param out output stream
1122  * \return output stream
1123  */
1124  virtual std::ostream& write(std::ostream& out) const
1125  {
1126  return out << object;
1127  }
1128 
1129 
1130  /**
1131  * Status of object.
1132  *
1133  * \return true
1134  */
1135  virtual bool getStatus() const
1136  {
1137  return true;
1138  }
1139 
1140 
1141  /**
1142  * Get initialisation status of parameter.
1143  *
1144  * \return true
1145  */
1146  virtual bool getInitialisationStatus() const
1147  {
1148  return true;
1149  }
1150 
1151 
1152  /**
1153  * Set initialisation status of parameter.
1154  * This implementation doesn't do anything.
1155  *
1156  * \param value initialisation status
1157  */
1158  virtual void setInitialiationStatus(const bool value)
1159  {}
1160 
1161 
1162  /**
1163  * Read counter.
1164  *
1165  * \return true if at least one character to be read; else false
1166  */
1167  virtual bool gcount() const
1168  {
1169  return false;
1170  }
1171 
1172 
1173  private:
1175  };
1176 
1177 
1178  /**
1179  * Auxiliary class to handle pointer to JPARSER::JParserElementInterface.
1180  */
1182  public JSharedPointer<JParserElementInterface>
1183  {
1184  public:
1185 
1187 
1188 
1189  /**
1190  * Default constructor.
1191  */
1194  {}
1195 
1196 
1197  /**
1198  * Copy constructor.
1199  *
1200  * \param value reference to JParserElement
1201  */
1203  JSharedPointer_t(static_cast<const JSharedPointer_t&>(value))
1204  {}
1205 
1206 
1207  /**
1208  * Assignment operator.
1209  *
1210  * \param value reference to JParserElement
1211  * \return this JParserElement
1212  */
1214  {
1215  JSharedPointer_t::operator=(static_cast<JSharedPointer_t&>(value));
1216 
1217  return *this;
1218  }
1219 
1220 
1221  /**
1222  * Assignment operator.
1223  *
1224  * \param value reference to unnamed data object
1225  * \return corresponding new JParserTemplateElement object
1226  */
1227  template<class JType_t>
1229  {
1231 
1232  reset(__p);
1233 
1234  return *__p;
1235  }
1236 
1237 
1238  /**
1239  * Assignment operator.
1240  *
1241  * \param value reference to JParserTemplateElement object
1242  * \return corresponding new JParserTemplateElement object
1243  */
1244  template<class JType_t>
1246  {
1248 
1249  reset(__p);
1250 
1251  return *__p;
1252  }
1253 
1254 
1255  /**
1256  * Assignment operator.
1257  *
1258  * \param value reference to a corresponding JCSV object
1259  * \return corresponding new comma separated values parser
1260  */
1261  template<class JType_t>
1263  {
1265 
1266  reset(__p);
1267 
1268  return JCSV<JType_t>(*__p);
1269  }
1270 
1271 
1272  /**
1273  * Set initialised status to true.
1274  *
1275  * \param value initialised object
1276  * \return this object
1277  */
1278  const JParserElement& operator=(const initialised& value)
1279  {
1280  if (!is_valid())
1281  THROW(JParserException, "No parser object defined.");
1282  else
1283  (*this)->setInitialiationStatus(true);
1284 
1285  return *this;
1286  }
1287 
1288 
1289  /**
1290  * Set initialised status to false.
1291  *
1292  * \param value initialised object
1293  * \return this object
1294  */
1296  {
1297  (*this)->setInitialiationStatus(false);
1298 
1299  return *this;
1300  }
1301 
1302 
1303  /**
1304  * Stream input.
1305  *
1306  * \param in input stream
1307  * \param value parser element
1308  * \return input stream
1309  */
1310  friend inline std::istream& operator>>(std::istream& in, JParserElement& value)
1311  {
1312  if (value.is_valid())
1313  return value->read(in);
1314  else
1315  return in;
1316  }
1317 
1318 
1319  /**
1320  * Stream output.
1321  *
1322  * \param out output stream
1323  * \param value parser element
1324  * \return output stream
1325  */
1326  friend inline std::ostream& operator<<(std::ostream& out, const JParserElement& value)
1327  {
1328  if (value.is_valid())
1329  return value->write(out);
1330  else
1331  return out;
1332  }
1333 
1334 
1335  /**
1336  * Print.
1337  *
1338  * \param out output stream
1339  * \return output stream
1340  */
1341  void print(std::ostream& out) const
1342  {
1343  if (is_valid()) {
1344  return get()->print(out);
1345  }
1346  }
1347  };
1348 
1349 
1350  /**
1351  * Utility class to parse command line options.
1352  *
1353  * The mapping between a parameter (of any type) and a unique option
1354  * has to be defined in the user's application, e.g.
1355  * \code{.cpp}
1356 
1357  #include "Jeep/JParser.hh"
1358 
1359  int main(int argc, char**argv)
1360  {
1361  int aap;
1362  bool noot;
1363  bool mies;
1364 
1365  try {
1366 
1367  JParser<> zap;
1368 
1369  zap['i'] = make_field(aap) = 123; // set default value
1370  zap['b'] = make_field(noot); // default is false
1371  zap['B'] = make_field(mies);
1372 
1373  zap(argc, argv);
1374  }
1375  catch(const std::exception& error) {
1376  cerr << error.what() << endl;
1377  return 1;
1378  }
1379  }
1380  \endcode
1381  *
1382  * The behaviour of the parser is different for parameters of type <tt>bool</tt>.
1383  * By default, its value is set to <tt>false</tt>; it is set to <tt>true</tt>
1384  * when the corresponding option is parsed.
1385  * This implies that no data are read and that several options can be
1386  * parsed in sequence without repeating the '-' symbol.
1387  *
1388  *
1389  * The syntax for the command line is:
1390  *
1391  \verbatim
1392  program [-<option> <value> [-<option> <value>]]
1393  \endverbatim
1394 
1395  \verbatim
1396  program -h
1397  \endverbatim
1398  * will print the usage specification including all existing options.
1399 
1400  \verbatim
1401  program --!
1402  \endverbatim
1403  * will terminate the parsing of options and print the actual setting of all options.
1404  *
1405  * After the command line has been parsed, it is checked whether
1406  * each parameter has been assigned a value by default or at run time.
1407  * If not, an exception is thrown.
1408  */
1409  template<class JKey_t = char>
1410  class JParser :
1411  public std::map<JKey_t, JParserElement>,
1412  public JMessage< JParser<JKey_t> >
1413  {
1414  public:
1415 
1417  typedef JKey_t key_type;
1419 
1420  typedef typename map_type::iterator iterator;
1421  typedef typename map_type::const_iterator const_iterator;
1422 
1424 
1425 
1426  /**
1427  * Default constructor.
1428  *
1429  * \param debug debug level
1430  */
1431  JParser(const int debug = 0) :
1432  help ()
1433  {
1434  this->debug = debug;
1435  }
1436 
1437 
1438  /**
1439  * Constructor.
1440  *
1441  * \param message message printed with option <tt>-h</tt>
1442  * \param debug debug level
1443  */
1444  JParser(const std::string& message,
1445  const int debug = 0) :
1446  help (message)
1447  {
1448  this->debug = debug;
1449  }
1450 
1451 
1452  /**
1453  * Print the possible command line options.
1454  *
1455  * \param out output stream
1456  * \return output stream
1457  */
1458  void print(std::ostream& out) const
1459  {
1460  using namespace std;
1461 
1462  if (help != "") {
1463  out << help << endl;
1464  }
1465 
1466  out << "usage: " << getFilename(pid) << endl;
1467 
1468  out << ' ' << START_OF_OPTION << HELP_OPTION << ' ' << " \"help\"" << endl;
1469  out << ' ' << START_OF_OPTION << HELP_OPTION << PRINT_OPTION << " \"help with print of default and possible values\"" << endl;
1470  out << ' ' << START_OF_OPTION << REVISION_OPTION << ' ' << " \"print revision\"" << endl;
1471  out << ' ' << START_OF_OPTION << END_OF_OPTIONS << ' ' << " \"end of options; remainder will be discarded\"" << endl;
1472  out << ' ' << START_OF_OPTION << END_OF_OPTIONS << PRINT_OPTION << " \"end of options with print of actual values\"" << endl;
1473 
1474  for (const_iterator i = this->begin(); i != this->end(); ++i) {
1475 
1476  out << ' ' << START_OF_OPTION << i->first << ' ';
1477 
1478  i->second.print(out);
1479 
1480  out << endl;
1481  }
1482  }
1483 
1484 
1485  /**
1486  * Parse the program's command line options.
1487  *
1488  * \param argc number of arguments
1489  * \param argv argument list
1490  * \return argument list
1491  */
1492  JArgs operator()(const int argc, const char* const argv[])
1493  {
1494  return (*this)(JArgs(argc, argv));
1495  }
1496 
1497 
1498  /**
1499  * Parse the program's command line options.
1500  *
1501  * \param args argument list
1502  * \return argument list
1503  */
1504  JArgs operator()(const JArgs& args)
1505  {
1506  using namespace std;
1507  using namespace JLANG;
1508  using namespace JEEP;
1509 
1510  pid = args.PID;
1511 
1512  istringstream is;
1513 
1514  // argument passing
1515 
1516  for (JArgs::const_iterator i = args.begin(); i != args.end(); ++i) {
1517 
1518  DEBUG("Processing option <" << *i << ">" << endl);
1519 
1520  is.clear();
1521  is.str(*i);
1522 
1523  for (int c; (c = is.get()) != EOF; ) {
1524 
1525  if (c == START_OF_OPTION) {
1526 
1527  if (is.peek() == EOF) { // end-of-file
1528 
1529  THROW(JParserException, "stray " << START_OF_OPTION << " in <" << is.str() << "> at " << JArgs("", i, args.end()));
1530 
1531  } else if (isspace(is.peek())) { // white space
1532 
1533  THROW(JParserException, "stray " << START_OF_OPTION << " in <" << is.str() << "> at " << JArgs("", i, args.end()));;
1534  }
1535 
1536  while (is.peek() != EOF) { // read option(s)
1537 
1538  if (is.peek() == HELP_OPTION) { // help
1539 
1540  is.get();
1541 
1542  setPrintOption(cerr, SHORT_PRINT);
1543 
1544  if (is.peek() != EOF) {
1545 
1546  if (is.get() == PRINT_OPTION) {
1547 
1548  setPrintOption(cerr, LONG_PRINT);
1549 
1550  } else {
1551 
1552  THROW(JParserException, "invalid option at <" << is.str() << ">");
1553  }
1554  }
1555 
1556  print(cerr);
1557 
1558  exit(NORMAL_EXIT_CODE);
1559 
1560  } else if (is.peek() == REVISION_OPTION) { // revision
1561 
1562  cerr << "version: " << getGITVersion() << endl;
1563  cerr << "commit: " << getGITCommit() << endl;
1564  cerr << "date: " << getGITDate() << endl;
1565  cerr << "namespace: " << getNamespace() << endl;
1566 
1567  exit(NORMAL_EXIT_CODE);
1568 
1569  } else if (is.peek() == END_OF_OPTIONS) { // end of options
1570 
1571  is.get();
1572 
1573  if (is.peek() != EOF) {
1574 
1575  c = is.get();
1576 
1577  if (c == PRINT_OPTION) {
1578 
1580 
1581  print(cerr);
1582 
1583  } else if (c == PID_OPTION) {
1584 
1585  if (is.peek() == EOF && i + 1 != args.end()) {
1586  is.clear();
1587  is.str(*++i);
1588  }
1589 
1590  string file_name;
1591 
1592  getline(is, file_name);
1593 
1594  ofstream out(file_name.c_str());
1595 
1596  out << getpid() << endl;
1597 
1598  if (!out) {
1599  THROW(JParserException, "invalid option at <" << is.str() << ">");
1600  }
1601 
1602  out.close();
1603 
1604  } else {
1605 
1606  THROW(JParserException, "invalid option at <" << is.str() << ">");
1607  }
1608  }
1609 
1610  check_status();
1611 
1612  return JArgs(pid, ++i, args.end());
1613 
1614  } else {
1615 
1616  key_type option;
1617 
1618  is >> option;
1619 
1620  iterator p = this->find(option);
1621 
1622  DEBUG("Processing option <" << option << "> " << (p != this->end()) << endl);
1623 
1624  if (p != this->end()) {
1625 
1626  if (p->second->gcount()) {
1627 
1628  if (is.peek() == EOF && i + 1 != args.end()) {
1629  is.clear();
1630  is.str(*++i);
1631  }
1632  }
1633 
1634  try {
1635  is >> p->second;
1636  }
1637  catch(const exception& error) {
1638  THROW(JParserException, "read error " << error.what() << " at <" << is.str() << ">");
1639  }
1640 
1641  if (fail(is)) {
1642  THROW(JParserException, "read error at <" << is.str() << ">");
1643  }
1644 
1645  } else {
1646 
1647  THROW(JParserException, "unknown option <" << is.str() << "> at " << JArgs("", i, args.end()));
1648  }
1649  }
1650  }
1651 
1652  } else {
1653 
1654  THROW(JParserException, "illegal character <" << (char) c << "> at " << JArgs("", i, args.end()));
1655  }
1656  }
1657  }
1658 
1659  check_status();
1660 
1661  return JArgs();
1662  }
1663 
1664 
1665  /**
1666  * Parse the program's command line options.\n
1667  * This method is maintained for backward compatibility and will be deprecated.
1668  *
1669  * \param argc number of arguments
1670  * \param argv argument list
1671  * \return 0
1672  */
1673  int read(const int argc, const char* const argv[])
1674  {
1675  (*this)(argc, argv);
1676 
1677  return 0;
1678  }
1679 
1680 
1681  /**
1682  * Parse the program's command line options.\n
1683  * This method is maintained for backward compatibility and will be deprecated.
1684  *
1685  * \param args argument list
1686  * \return 0
1687  */
1688  int read(const JArgs& args)
1689  {
1690  (*this)(args);
1691 
1692  return 0;
1693  }
1694 
1695 
1696  /**
1697  * Print the current parameter values.
1698  *
1699  * \param out output stream
1700  * \return output stream
1701  */
1702  std::ostream& write(std::ostream& out) const
1703  {
1704  for (const_iterator i = this->begin(); i != this->end(); ++i) {
1705  out << i->second->getName() << '=' << i->second << std::endl;
1706  }
1707 
1708  return out;
1709  }
1710 
1711 
1712  /**
1713  * Stream output.
1714  *
1715  * \param out output stream
1716  * \param parser parser
1717  * \return output stream
1718  */
1719  friend inline std::ostream& operator<<(std::ostream& out, const JParser<key_type>& parser)
1720  {
1721  return parser.write(out);
1722  }
1723 
1724 
1725  protected:
1726  /**
1727  * Check if all required options have been set.\n
1728  * This method throws an exception in case of a non-compliance.
1729  */
1730  void check_status() const
1731  {
1732  for (const_iterator p = this->begin(); p != this->end(); ++p) {
1733 
1734  if (!p->second->getInitialisationStatus()) {
1735  THROW(JParserException, "option: " << START_OF_OPTION << p->first << " <" << p->second->getName() << ">" << " has no value");
1736  }
1737 
1738  if (!p->second->getStatus()) {
1739  THROW(JParserException, "option: " << START_OF_OPTION << p->first << " <" << p->second->getName() << ">" << " has illegal value");
1740  }
1741  }
1742  }
1743 
1744  std::string help; //!< help message
1745  std::string pid; //!< process name
1746  };
1747 
1748 
1749  /**
1750  * Auxiliary method for creation of template parser element object
1751  *
1752  * \param object object
1753  * \param name name of object
1754  * \param help help of object
1755  * \return parser element
1756  */
1757  inline JParserTemplateElement<bool> getOption(bool& object, const std::string& name, const std::string& help = "")
1758  {
1759  return JParserTemplateElement<bool>(object, name, help);
1760  }
1761 
1762 
1763  /**
1764  * Auxiliary method for creation of template parser element object
1765  *
1766  * \param object object
1767  * \param name name of object
1768  * \param help help of object
1769  * \return parser element
1770  */
1771  inline JParserTemplateElement<JCounter> getOption(JCounter& object, const std::string& name, const std::string& help = "")
1772  {
1773  return JParserTemplateElement<JCounter>(object, name, help);
1774  }
1775 
1776 
1777  /**
1778  * Auxiliary method for creation of template parser element object
1779  *
1780  * \param object object
1781  * \param name name of object
1782  * \param help help of object
1783  * \return parser element
1784  */
1785  template<class JType_t>
1786  inline JParserTemplateElement<JType_t> getOption(JType_t& object, const std::string& name, const std::string& help = "")
1787  {
1788  return JParserTemplateElement<JType_t>(object, name, help);
1789  }
1790 
1791 
1792  /**
1793  * Auxiliary method for creation of template parser element object
1794  *
1795  * \param object object
1796  * \param name name of object
1797  * \param help help of object
1798  * \param __begin begin of possible values
1799  * \param __end end of possible values
1800  * \return parser element
1801  */
1802  template<class JType_t, class T>
1804  const std::string& name,
1805  const std::string& help,
1806  T __begin,
1807  T __end)
1808  {
1809  return JParserTemplateElement<JType_t>(object, name, help, __begin, __end);
1810  }
1811 
1812 
1813  /**
1814  * Auxiliary method for creation of template parser element object
1815  *
1816  * \param object object
1817  * \param name name of object
1818  * \param __begin begin of possible values
1819  * \param __end end of possible values
1820  * \return parser element
1821  */
1822  template<class JType_t, class T>
1824  const std::string& name,
1825  T __begin,
1826  T __end)
1827  {
1828  return getOption(object, name, "", __begin, __end);
1829  }
1830 }
1831 
1832 
1833 /**
1834  * macro to convert parameter to JParserTemplateElement object
1835  */
1836 #define make_field(A, ...) JPARSER::getOption(A, #A, ##__VA_ARGS__)
1837 
1838 
1839 /**
1840  * macro to convert parameter to JParserTemplateElement object
1841  */
1842 #define gmake_option(A, ...) JPARSER::getOption(A, #A, ##__VA_ARGS__)
1843 
1844 
1845 using JPARSER::JParser;
1846 using JPARSER::JOption;
1847 using JPARSER::JCounter;
1848 using JPARSER::getOption;
1849 using JPARSER::JArgs;
1850 
1851 #endif
static int debug
debug level (default is off).
Definition: JMessage.hh:43
JArgs operator()(const JArgs &args)
Parse the program&#39;s command line options.
Definition: JParser.hh:1504
virtual void print(std::ostream &out) const
Print.
Definition: JParser.hh:939
virtual bool gcount() const
Read counter.
Definition: JParser.hh:1167
Utility class to parse command line options.
Definition: JParser.hh:1410
virtual bool getInitialisationStatus() const
Get initialisation status of parameter.
Definition: JParser.hh:620
JParser(const int debug=0)
Default constructor.
Definition: JParser.hh:1431
static char PID_OPTION
print PID to file
Definition: JParser.hh:81
Exceptions.
JParserTemplateElement< JType_t > & operator=(const JParserTemplateElement< JType_t > &value)
Assignment operator.
Definition: JParser.hh:1245
virtual void setInitialiationStatus(const bool value)
Set initialisation status of parameter.
Definition: JParser.hh:631
virtual bool getStatus() const =0
Get status of parameter.
virtual void setInitialiationStatus(const bool value)
Set initialisation status of parameter.
Definition: JParser.hh:1057
const JParserElement & operator=(const initialised &value)
Set initialised status to true.
Definition: JParser.hh:1278
virtual std::ostream & write(std::ostream &out) const
Stream output.
Definition: JParser.hh:675
const char * getGITCommit()
Get GIT commit.
Definition: Jpp.hh:68
Template specialisation of JPARSER::JParserTemplateElement for data type with equal operator ==...
Definition: JParser.hh:768
Interface for ASCII input using standard streams.
Definition: JAbstractIO.hh:21
static char PRINT_OPTION
print option
Definition: JParser.hh:80
const char * getGITDate()
Get GIT date.
Definition: Jpp.hh:83
virtual std::istream & read(std::istream &in)
Stream input.
Definition: JParser.hh:1112
std::ostream & write(std::ostream &out) const
Print the current parameter values.
Definition: JParser.hh:1702
std::string help
help message
Definition: JParser.hh:1744
JClass_t * __p
pointer to object
Definition: JPointer.hh:136
friend std::istream & operator>>(std::istream &in, JParserElement &value)
Stream input.
Definition: JParser.hh:1310
const JOption< T > & operator=(const T &value)
Assignment to a value.
Definition: JParser.hh:151
Template specialisation of JPARSER::JParserTemplateElement for data type without equal operator ==...
Definition: JParser.hh:540
JParserTemplateElement< JType_t > & operator=(JType_t &value)
Assignment operator.
Definition: JParser.hh:1228
JParserTemplateElement< bool > getOption(bool &object, const std::string &name, const std::string &help="")
Auxiliary method for creation of template parser element object.
Definition: JParser.hh:1757
JParserTemplateElement(JType_t &object, const std::string &name="arg", const std::string &help="")
Constructor.
Definition: JParser.hh:782
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:633
virtual void setInitialiationStatus(const bool value)
Set initialisation status of parameter.
Definition: JParser.hh:1158
Auxiliary class to handle pointer to JPARSER::JParserElementInterface.
Definition: JParser.hh:1181
Jpp meta data.
const JParserTemplateElement< JType_t, true > & operator=(const not_initialised &value)
Set initialised status to false.
Definition: JParser.hh:849
Empty structure for specification of parser element that is initialised (i.e.
Definition: JParser.hh:64
Auxiliary class to handle optional I/O.
Definition: JParser.hh:103
long print
Definition: JPrint.hh:40
void setPrintOption(std::ostream &out, const int option)
Set print option.
Definition: JPrint.hh:80
virtual bool getStatus() const
Get status of object.
Definition: JParser.hh:914
std::string getNamespace(const std::string &type_name)
Get name space, i.e.
Definition: JeepToolkit.hh:207
bool is_valid() const
Check validity of pointer.
virtual std::istream & read(std::istream &in)
Stream input.
Definition: JParser.hh:1009
JParser(const std::string &message, const int debug=0)
Constructor.
Definition: JParser.hh:1444
JParserElement()
Default constructor.
Definition: JParser.hh:1192
JSharedPointer< JParserElementInterface > JSharedPointer_t
Definition: JParser.hh:1186
const std::string & getName() const
Get name of parameter.
Definition: JParser.hh:368
virtual void print(std::ostream &out) const
Print.
Definition: JParser.hh:415
JParserTemplateElement< JType_t > & __element
Definition: JParser.hh:532
std::istream & readObject(std::istream &in, T &object)
Stream input of object.
bool getLongprint(std::ostream &out)
Get long print option.
Definition: JPrint.hh:138
virtual bool getInitialisationStatus() const =0
Get initialisation status of parameter.
const JCounter & operator=(const bool value)
Set value.
Definition: JParser.hh:297
virtual bool getStatus() const
Status of object.
Definition: JParser.hh:1135
virtual void setInitialiationStatus(const bool value)=0
Set initialisation status of parameter.
static char REVISION_OPTION
revision option
Definition: JParser.hh:79
JParserElement(const JParserElement &value)
Copy constructor.
Definition: JParser.hh:1202
bool more(const int value) const
Compare value.
Definition: JParser.hh:272
virtual std::istream & read(std::istream &in)
Stream input.
Definition: JParser.hh:643
void setPossibleValues(T __begin, T __end)
Set possible values.
Definition: JParser.hh:956
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.
Definition: JParser.hh:720
virtual bool getStatus() const
Status of object.
Definition: JParser.hh:1034
void print(const TH1 &h1, std::ostream &out)
Print histogram parameters.
void print(std::ostream &out) const
Print the possible command line options.
Definition: JParser.hh:1458
JParserTemplateElement(JType_t &object, const std::string &name, T __begin, T __end)
Constructor.
Definition: JParser.hh:798
JCSV & operator,(JType_t value)
Parsing of additional possible values.
Definition: JParser.hh:490
I/O formatting auxiliaries.
Auxiliary template class for type bool.
Definition: JBool.hh:20
The template JSharedPointer class can be used to share a pointer to an object.
JCSV(JParserTemplateElement< JType_t > &element)
Constructor.
Definition: JParser.hh:468
map_type::iterator iterator
Definition: JParser.hh:1420
JParserElement & operator=(JParserElement &value)
Assignment operator.
Definition: JParser.hh:1213
const JParserTemplateElement< JType_t, false > & operator=(const initialised &value)
Set initialised status to true.
Definition: JParser.hh:566
short print
Definition: JPrint.hh:38
Interface for I/O of parser element.
Definition: JParser.hh:344
JCounter()
Default constructor.
Definition: JParser.hh:226
Auxiliary methods for handling file names, type names and environment.
int read(const JArgs &args)
Parse the program&#39;s command line options.
Definition: JParser.hh:1688
virtual bool gcount() const
Read counter.
Definition: JParser.hh:1066
friend std::istream & operator>>(std::istream &in, JOption &object)
Read option from input.
Definition: JParser.hh:181
int getCounter() const
Get counter.
Definition: JParser.hh:283
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:468
friend std::istream & operator>>(std::istream &in, JCounter &object)
Read option from input.
Definition: JParser.hh:314
const char * getGITVersion()
Get GIT version.
Definition: Jpp.hh:53
JOption(const T &value)
Constructor.
Definition: JParser.hh:117
virtual std::ostream & write(std::ostream &out) const
Stream output.
Definition: JParser.hh:1124
void check_status() const
Check if all required options have been set.
Definition: JParser.hh:1730
Data structure to store command line arguments.
Definition: JArgs.hh:24
Exception when parsing a value.
Definition: JException.hh:504
JParserTemplateElement(JType_t &object, const std::string &name, const std::string &help, T __begin, T __end)
Constructor.
Definition: JParser.hh:818
const JParserTemplateElement< JType_t, true > & operator=(const initialised &value)
Set initialised status to true.
Definition: JParser.hh:835
Template definition of auxiliary base class for comparison of data structures.
Definition: JComparable.hh:24
General purpose messaging.
JLANG::JParserException JParserException
Definition: JParser.hh:1416
bool fail(std::istream &in)
Check for stream state.
Definition: JParser.hh:93
virtual std::ostream & write(std::ostream &out) const =0
Stream output.
JParserTemplateElement(bool &object, const std::string &name="arg", const std::string &help="")
Constructor.
Definition: JParser.hh:994
JCSV< JType_t > operator=(const JContainer_t< JType_t, JAllocator_t > &values)
Assignment to a default value and possible other values.
Definition: JParser.hh:882
virtual bool getStatus() const
Get status of object.
Definition: JParser.hh:609
virtual bool getInitialisationStatus() const
Get initialisation status of parameter.
Definition: JParser.hh:1146
Empty structure for specification of parser element that is not initialised (i.e. ...
Definition: JParser.hh:70
std::string PID
Definition: JArgs.hh:167
JParserElementInterface(const std::string &name="arg", const std::string &help="")
Constructor.
Definition: JParser.hh:355
std::map< key_type, JParserElement > map_type
Definition: JParser.hh:1418
Template specialisation of JPARSER::JParserTemplateElement for type bool.
Definition: JParser.hh:981
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.
Definition: JParser.hh:551
Interface for ASCII output using standard streams.
Definition: JAbstractIO.hh:56
virtual bool getStatus() const
Get status of this counter.
Definition: JParser.hh:236
int read(const int argc, const char *const argv[])
Parse the program&#39;s command line options.
Definition: JParser.hh:1673
JCSV & operator,(const JContainer_t< JType_t, JAllocator_t > &values)
Parsing of additional possible values.
Definition: JParser.hh:505
bool less(const int value) const
Compare value.
Definition: JParser.hh:260
virtual bool getInitialisationStatus() const
Get initialisation status of parameter.
Definition: JParser.hh:1045
JSharedPointer & operator=(const JSharedPointer &object)
Assignment operator.
JCSV< JType_t > operator=(const JCSV< JType_t > &value)
Assignment operator.
Definition: JParser.hh:1262
static char END_OF_OPTIONS
end of all options
Definition: JParser.hh:77
const JParserTemplateElement< JType_t, false > & operator=(const not_initialised &value)
Set initialised status to false.
Definition: JParser.hh:580
Auxiliary class to assign the remainder of a sequence of Comma Separated Values.
Definition: JParser.hh:461
JCSV< JType_t > operator=(const JType_t &value)
Assignment to a default value and possible other values.
Definition: JParser.hh:863
Template specialisation of JPARSER::JParserTemplateElement for type JCounter.
Definition: JParser.hh:1084
Auxiliary class to handle multiple boolean-like I/O.
Definition: JParser.hh:218
medium print
Definition: JPrint.hh:39
Interface for status of object.
static int NORMAL_EXIT_CODE
exit code of normal end
Definition: JParser.hh:82
const JParserTemplateElement< JType_t, false > & operator=(const JType_t &value)
Assignment to a default value.
Definition: JParser.hh:594
bool getShortprint(std::ostream &out)
Get short print option.
Definition: JPrint.hh:92
static char START_OF_OPTION
Parser options.
Definition: JParser.hh:76
std::string getFilename(const std::string &file_name)
Get file name part, i.e.
Definition: JeepToolkit.hh:85
map_type::const_iterator const_iterator
Definition: JParser.hh:1421
const JParserElement & operator=(const not_initialised &value)
Set initialised status to false.
Definition: JParser.hh:1295
const char * getName()
Get ROOT name of given data type.
void print(std::ostream &out) const
Print.
Definition: JParser.hh:1341
virtual bool gcount() const
Read counter.
Definition: JParser.hh:437
JArgs operator()(const int argc, const char *const argv[])
Parse the program&#39;s command line options.
Definition: JParser.hh:1492
T * clone() const
Get clone of this object.
Definition: JParser.hh:165
std::string pid
process name
Definition: JParser.hh:1745
Template class holder for I/O of parser element.
Definition: JParser.hh:454
virtual const char * what() const
Get error message.
Definition: JException.hh:65
virtual std::ostream & write(std::ostream &out) const
Stream output.
Definition: JParser.hh:1023
virtual void reset()
Reset pointer.
friend std::ostream & operator<<(std::ostream &out, const JParserElement &value)
Stream output.
Definition: JParser.hh:1326
JParserTemplateElement(JCounter &object, const std::string &name, const std::string &help="")
Constructor.
Definition: JParser.hh:1097
bool getStatus() const
Get status.
Definition: JParser.hh:128
const std::string & getHelp() const
Get help of parameter.
Definition: JParser.hh:379
JOption()
Default constructor.
Definition: JParser.hh:108
bool less(const JCounter &value) const
Compare value.
Definition: JParser.hh:248
std::istream & read(std::istream &in)
Definition: JParser.hh:693
friend std::ostream & operator<<(std::ostream &out, const JOption &object)
Write options to output.
Definition: JParser.hh:200
JCSV & operator,(const JContainer_t< JType_t, JCompare_t, JAllocator_t > &values)
Parsing of additional possible values.
Definition: JParser.hh:522
JCSV< JType_t > operator=(const JContainer_t< JType_t, JCompare_t, JAllocator_t > &values)
Assignment to a default value and possible other values.
Definition: JParser.hh:897
friend std::ostream & operator<<(std::ostream &out, const JCounter &object)
Write options to output.
Definition: JParser.hh:329
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:60
Auxiliary class for handling debug parameter within a class.
Definition: JMessage.hh:42
std::ostream & writeObject(std::ostream &out, const T &object)
Stream output of object.
static char HELP_OPTION
help option
Definition: JParser.hh:78