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