Jpp  17.3.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JProperties.hh
Go to the documentation of this file.
1 #ifndef __JEEP__JPROPERTIES__
2 #define __JEEP__JPROPERTIES__
3 
4 #include <string>
5 #include <istream>
6 #include <ostream>
7 #include <fstream>
8 #include <sstream>
9 #include <map>
10 #include <vector>
11 
12 #include "JLang/JAbstractIO.hh"
13 #include "JLang/JException.hh"
14 #include "JLang/JSharedPointer.hh"
16 #include "JLang/JEquationFacet.hh"
17 #include "JLang/JEquation.hh"
19 #include "JLang/JCategory.hh"
20 #include "JLang/JClass.hh"
21 #include "Jeep/JStreamToolkit.hh"
23 #include "Jeep/JMessage.hh"
24 
25 
26 /**
27  * \file
28  * Utility class to parse parameter values.
29  * \author mdejong
30  */
31 namespace JEEP {}
32 namespace JPP { using namespace JEEP; }
33 
34 namespace JEEP {
35 
36  using JLANG::JStreamInput;
44  using JLANG::JEquation;
45  using JLANG::JComparisonAvailable;
47 
48 
49  /**
50  * Check for stream state.
51  *
52  * Note that end-of-file is not defined as an error so to normally process e.g.\ std::string and std::vector.
53  *
54  * \param in input stream
55  * \return true if failure; else false
56  */
57  inline bool fail(std::istream& in)
58  {
59  return in.bad() || (in.fail() && !in.eof());
60  }
61 
62 
63  /**
64  * Interface for I/O of properties element.
65  */
67  public JStreamInput,
68  public JStreamOutput,
69  public JStreamSuffixOutput
70  {
71  public:
72 
75 
76 
77  /**
78  * Get properties type.
79  *
80  * \return false
81  */
82  virtual bool is_properties() const
83  {
84  return false;
85  }
86 
87 
88  /**
89  * Equality between property element interfaces.
90  *
91  * \param element properties element interface
92  * \return false
93  */
94  virtual bool equals(const JPropertiesElementInterface& element) const
95  {
96  return false;
97  }
98  };
99 
100 
101  class JPropertiesElement; // Forward declaration.
102 
103 
104  /**
105  * Template class for I/O of properties element.
106  *
107  * This class implements the JPropertiesElementInterface interface.
108  */
109  template<class T>
112  {
113 
114  friend class JPropertiesElement;
115 
116  public:
117  /**
118  * Constructor.
119  *
120  * \param value reference of template object
121  */
124  object(value)
125  {}
126 
127 
128  /**
129  * Stream input.
130  *
131  * \param in input stream
132  * \return input stream
133  */
134  virtual std::istream& read(std::istream& in) override
135  {
136  using namespace std;
137 
138  readObject(in, object);
139 
140  string buffer;
141 
142  in >> buffer;
143 
144  if (!buffer.empty()) {
145  THROW(JPropertiesException, "JProperties: pending data <" << buffer << (in.peek() != EOF ? "..." : "") << ">");
146  }
147 
148  return in;
149  }
150 
151 
152  /**
153  * Stream output.
154  *
155  * \param out output stream
156  * \param prefix prefix
157  * \param postfix postfix
158  * \return output stream
159  */
160  virtual std::ostream& write(std::ostream& out,
161  const char* prefix,
162  const char postfix) const override
163  {
164  return writeObject(out, prefix, object, postfix);
165  }
166 
167 
168  /**
169  * Stream output.
170  *
171  * \param out output stream
172  * \return output stream
173  */
174  virtual std::ostream& write(std::ostream& out) const override
175  {
176  return writeObject(out, object);
177  }
178 
179 
180  /**
181  * Equality between property element interfaces.
182  *
183  * \param element properties element interface
184  * \return true if equal; else false
185  */
186  virtual bool equals(const JPropertiesElementInterface& element) const override
187  {
188  const JPropertiesTemplateElement<T>* p = dynamic_cast<const JPropertiesTemplateElement<T>*>(&element);
189 
190  if (p != NULL)
191  return compareObjects(object, p->object);
192  else
193  return false;
194  }
195 
196 
197  protected:
199  };
200 
201 
202  /**
203  * Template specialisation of JPropertiesTemplateElement for const data type.
204  *
205  * This class implements the JPropertiesElementInterface interface.
206  */
207  template<class T>
210  {
211 
212  friend class JPropertiesElement;
213 
214  public:
215  /**
216  * Constructor.
217  *
218  * \param value reference of template object
219  */
220  JPropertiesTemplateElement(const T& value) :
222  object(value)
223  {}
224 
225 
226  /**
227  * Stream input.
228  *
229  * \param in input stream
230  * \return input stream
231  */
232  virtual std::istream& read(std::istream& in) override
233  {
234  THROW(JPropertiesException, "JPropertiesTemplateElement<>::read() reading of const data type.");
235  }
236 
237 
238  /**
239  * Stream output.
240  *
241  * \param out output stream
242  * \return output stream
243  */
244  virtual std::ostream& write(std::ostream& out) const override
245  {
246  return writeObject(out, object);
247  }
248 
249 
250  /**
251  * Stream output.
252  *
253  * \param out output stream
254  * \param prefix prefix
255  * \param postfix postfix
256  * \return output stream
257  */
258  virtual std::ostream& write(std::ostream& out,
259  const char* prefix,
260  const char postfix) const
261  {
262  return writeObject(out, prefix, object, postfix);
263  }
264 
265 
266  /**
267  * Equality between property element interfaces.
268  *
269  * \param element properties element interface
270  * \return true if equal; else false
271  */
272  virtual bool equals(const JPropertiesElementInterface& element) const override
273  {
274  const JPropertiesTemplateElement<const T>* p = dynamic_cast<const JPropertiesTemplateElement<const T>*>(&element);
275 
276  if (p != NULL)
277  return compareObjects(object, p->object);
278  else
279  return false;
280  }
281 
282 
283  protected:
284  const T& object;
285  };
286 
287 
288  /**
289  * The property value class.
290  * This class consists of a pointer to the JPropertiesElementInterface.
291  * This class implements the assignment and type conversion operators.
292  */
294  public JSharedPointer<JPropertiesElementInterface>
295  {
296  public:
297  /**
298  * Default constructor.
299  */
301  end_marker(false)
302  {}
303 
304 
305  /**
306  * Constructor.
307  *
308  * \param value reference to template object
309  */
310  template<class T>
312  end_marker(false)
313  {
315  }
316 
317 
318  /**
319  * Equality between property elements.
320  *
321  * \param element properties element
322  * \return true if equal; else false
323  */
324  bool equals(const JPropertiesElement& element) const
325  {
326  return get()->equals(*element.get());
327  }
328 
329 
330  /**
331  * Assignment operator.
332  *
333  * \param value reference to template object
334  * \return this JPropertiesElement
335  */
336  template<class T>
338  {
340 
341  return *this;
342  }
343 
344 
345  /**
346  * Get value.
347  *
348  * \return value of this JPropertiesElement
349  */
350  template<class T>
351  const T& getValue() const
352  {
353  const JPropertiesTemplateElement<T>* p = dynamic_cast<const JPropertiesTemplateElement<T>*>(this->get());
354 
355  if (p != NULL)
356  return p->object;
357  else
358  THROW(JPropertiesException, "Inconsistent data type.");
359  }
360 
361 
362  /**
363  * Get value.
364  *
365  * \return value of this JPropertiesElement
366  */
367  template<class T>
369  {
370  JPropertiesTemplateElement<T>* p = dynamic_cast<JPropertiesTemplateElement<T>*>(this->get());
371 
372  if (p != NULL)
373  return p->object;
374  else
375  THROW(JPropertiesException, "Inconsistent data type.");
376  }
377 
378 
379 
380  /**
381  * Set value of this JPropertiesElement.
382  *
383  * \param value value
384  */
385  template<class T>
386  void setValue(const T& value)
387  {
388  JPropertiesTemplateElement<T>* p = dynamic_cast<JPropertiesTemplateElement<T>*>(this->get());
389 
390  if (p != NULL)
391  p->object = value;
392  else
393  THROW(JPropertiesException, "Inconsistent data type.");
394  }
395 
396 
397  /**
398  * Convert to string.
399  *
400  * \return value of this JPropertiesElement
401  */
403  {
404  std::ostringstream os;
405 
406  get()->write(os, "", '\0');
407 
408  return os.str();
409  }
410 
411 
412  /**
413  * Convert to template type.
414  *
415  * \return value of this JPropertiesElement
416  */
417  template<class T>
418  T toValue() const
419  {
420  T value;
421 
422  std::istringstream in(this->toString());
423 
424  in >> value;
425 
426  return value;
427  }
428 
429 
430  /**
431  * Type conversion operator.
432  *
433  * \return value of this JPropertiesElement
434  */
435  template<class T>
436  operator const T&() const
437  {
438  return getValue<T>();
439  }
440 
441 
442  /**
443  * Get end marker.
444  *
445  * \return end marker
446  */
447  bool getEndMarker() const
448  {
449  return end_marker;
450  }
451 
452 
453  /**
454  * Set end marker.
455  *
456  * \param marker if true stop reading after this properties element, else continue
457  */
458  void setEndMarker(const bool marker)
459  {
460  end_marker = marker;
461  }
462 
463 
464  private:
466  };
467 
468 
469  /**
470  * Utility class to parse parameter values.
471  *
472  * The mapping between a parameter (of any type) and a value
473  * has to be defined in the user's program, e.g.
474  *
475  *\code{.cpp}
476 
477  #include "Jeep/JProperties.hh"
478 
479  ifstream in(filename.c_str());
480 
481  JProperties zap;
482 
483  int integer_value;
484  double double_value;
485  string string_value;
486 
487  zap.insert(make_property(integer_value)); // key == parameter name
488  zap.insert(make_property(double_value)); // key == parameter name
489 
490  zap["mies"] = string_value;
491 
492  zap.read(in);
493  zap.write(cout);
494  \endcode
495  */
496  class JProperties :
497  public std::map<std::string, JPropertiesElement>,
498  public JEquationParameters,
499  public JMessage<JProperties>
500  {
501  public:
502 
504 
506 
507 
508  /**
509  * Utility method to strip off all leading characters from a string until specified character(s).
510  *
511  * \param buffer input string
512  * \param sep last character(s) to strip
513  * \return modified string
514  */
515  static inline std::string getKey(const std::string& buffer, const std::string& sep)
516  {
517  using namespace std;
518 
519  const size_type pos = buffer.find_last_of(sep);
520 
521  if (pos != string::npos)
522  return buffer.substr(pos + 1);
523  else
524  return buffer;
525  }
526 
527 
528  /**
529  * Auxiliary class to handle input from file.
530  *
531  * The assignment of a value will cause the file with the corresponding name to be opened and read.
532  * The contents of the file are processed in the same way as any input to the associated JProperties object.
533  */
534  class JFileReader {
535  public:
536  JFileReader(JProperties& __properties) :
537  properties(__properties)
538  {}
539 
540 
541  /**
542  * Assignment operator.
543  *
544  * \param file_name file name
545  * \return this JFileReader
546  */
547  JFileReader& operator=(const std::string& file_name)
548  {
549  read(file_name);
550 
551  return *this;
552  }
553 
554 
555  /**
556  * Stream input.
557  *
558  * \param in input stream
559  * \param fileReader file reader object
560  * \return input stream
561  */
562  friend inline std::istream& operator>>(std::istream& in, JProperties::JFileReader& fileReader)
563  {
564  std::string file_name;
565 
566  in >> file_name;
567 
568  fileReader.read(file_name);
569 
570  return in;
571  }
572 
573 
574  /**
575  * Stream output.
576  *
577  * \param out output stream
578  * \param fileReader file reader
579  * \return output stream
580  */
581  friend inline std::ostream& operator<<(std::ostream& out, const JProperties::JFileReader& fileReader)
582  {
583  return out;
584  }
585 
586 
587  private:
588  /**
589  * Read properties from file.
590  *
591  * \param file_name file name
592  */
593  void read(const std::string& file_name)
594  {
595  std::ifstream in(file_name.c_str());
596 
597  if (!in) {
598  THROW(JFileOpenException, "JFileReader: error opening file " << file_name);
599  }
600 
601  properties.read(in);
602 
603  if (in.bad()) {
604  THROW(JFileReadException, "JFileReader: error reading file " << file_name);
605  }
606 
607  in.close();
608  }
609 
610 
612  };
613 
614 
615  /**
616  * Constructor.
617  *
618  * \param debug debug level
619  */
620  JProperties(const int debug = 0) :
621  JMap_t(),
623  {
624  this->debug = debug;
625  }
626 
627 
628  /**
629  * Constructor.
630  *
631  * \param parameters equation parameters
632  * \param debug debug level
633  */
635  const int debug = 0) :
636  JMap_t(),
637  JEquationParameters(parameters)
638  {
639  this->debug = debug;
640  }
641 
642 
643  /**
644  * Put object at given key.
645  *
646  * \param key key
647  * \param object object
648  */
649  template<class T>
650  void put(const std::string& key, T& object)
651  {
652  this->insert(value_type(key, JPropertiesElement(object)));
653  }
654 
655 
656  /**
657  * Join properties objects.
658  *
659  * \param properties properties
660  */
661  JProperties& join(const JProperties& properties)
662  {
663  JEquationParameters::join(properties);
664 
665  insert(properties.begin(), properties.end());
666 
667  return *this;
668  }
669 
670 
671  /**
672  * Read equation.
673  *
674  * \param equation equation
675  * \return status
676  */
677  bool read(const JEquation& equation)
678  {
679  using namespace std;
680 
681  iterator p = find(equation.getKey());
682 
683  DEBUG("Processing key: " << equation.getKey() << ' ' << (p != end()) << endl);
684 
685  if (p != end()) {
686 
687  istringstream is(equation.getValue());
688 
689  if (isDivision(equation.getSeparator())) {
690 
691  if (p->second->is_properties()) {
692 
693  p->second->read(is);
694 
695  } else {
696 
697  ERROR("JProperties::read(): no properties object after division <" << equation.getKey() << ">" << endl);
698  }
699 
700  } else if (isSeparator(equation.getSeparator())) {
701 
702  try {
703  p->second->read(is);
704  }
705  catch(const exception& error) {
706  ERROR("JProperties::read(): read error at key <" << equation.getKey() << "> " << error.what() << endl);
707  }
708 
709  } else {
710 
711  ERROR("JProperties::read(): illegal character following key <" << equation.getKey() << "> " << equation.getSeparator() << endl);
712  }
713 
714  if (p->second.getEndMarker()) {
715  return false;
716  }
717 
718  if (fail(is)) {
719 
720  ERROR("JProperties::read(): error reading data for key <" << equation.getKey() << "> " << equation.getValue() << endl);
721  }
722 
723  } else {
724 
725  WARNING("JProperties::read(): unknown key <" << equation.getKey() << ">" << endl);
726  }
727 
728  return true;
729  }
730 
731 
732  /**
733  * Read from input string.
734  *
735  * \param buffer input string
736  * \return read status
737  */
738  bool read(const std::string& buffer)
739  {
740  std::istringstream in(buffer);
741 
742  return !fail(read(in));
743  }
744 
745 
746  /**
747  * Read from input stream.
748  *
749  * The input format is:
750  * <pre>
751  * [<key><sub>]<key><sep><value><eol>
752  * [<key><sub>]<key><sep><value><eol>
753  * </pre>
754  * In this, white spaces are ignored.
755  * The reading of key and value pairs is controlled by the JLANG::JEquationFacet class.
756  *
757  * \param in input stream
758  * \return input stream
759  */
760  std::istream& read(std::istream& in)
761  {
762  using namespace std;
763 
764  in.imbue(locale(in.getloc(), new JEquationFacet(*this)));
765 
766  for (JEquation equation; in >> equation && read(equation); ) {}
767 
768  return in;
769  }
770 
771 
772  /**
773  * Read from input stream according given format.
774  *
775  * For each key in the format specification,
776  * a corresponding value will be read from the input stream.
777  *
778  * \param in input stream
779  * \param format format
780  * \return input stream
781  */
782  std::istream& read(std::istream& in, const std::string& format)
783  {
784  using namespace std;
785 
786  istringstream is(format);
787 
788  vector<string> buffer;
789 
790  for (string key; is >> key; ) {
791  buffer.push_back(key);
792  }
793 
794  return read(in, buffer.begin(), buffer.end());
795  }
796 
797 
798  /**
799  * Read from input stream according given format.
800  *
801  * For each key in the format specification,
802  * a corresponding value will be read from the input stream.
803  *
804  * \param in input stream
805  * \param __begin begin of format
806  * \param __end end of format
807  * \return input stream
808  */
809  template<class T>
810  std::istream& read(std::istream& in, T __begin, T __end)
811  {
812  using namespace std;
813 
814  for (T i = __begin; i != __end; ++i) {
815 
816  iterator p = find(*i);
817 
818  if (p != end()) {
819 
820  p->second->read(in);
821 
822  } else {
823 
824  WARNING("JProperties::read(): unknown key <" << *i << ">" << endl);
825  }
826  }
827 
828  return in;
829  }
830 
831 
832  /**
833  * Write the current parameter values.
834  *
835  * The output format is
836  *
837  * [<key><sub>]<key><sep><value><eol>
838  * [<key><sub>]<key><sep><value><eol>
839  *
840  * in this, white spaces are omitted.
841  *
842  * \param out output stream
843  * \return output stream
844  */
845  std::ostream& write(std::ostream& out) const
846  {
847  using namespace std;
848 
849  for (const_iterator i = begin(); i != end(); ++i) {
850 
851  char c = ' ';
852 
853  if (i->second->is_properties()) {
854  c = getDefaultDivision ();
855  } else {
856  c = getDefaultSeparator();
857  }
858 
859  i->second->write(out, (i->first + c).c_str(), getDefaultEndOfLine());
860  }
861 
862  out << flush;
863 
864  return out;
865  }
866 
867 
868  /**
869  * Write to output stream according given format.
870  *
871  * For each key in the format specification,
872  * a corresponding value will be written to the output stream.
873  *
874  * \param out output stream
875  * \param format format
876  * \return output stream
877  */
878  std::ostream& write(std::ostream& out, const std::string& format)
879  {
880  using namespace std;
881 
882  istringstream is(format);
883 
884  vector<string> buffer;
885 
886  for (string key; is >> key; ) {
887  buffer.push_back(key);
888  }
889 
890  return write(out, buffer.begin(), buffer.end());
891  }
892 
893 
894  /**
895  * Write to output stream according given format.
896  *
897  * For each key in the format specification,
898  * a corresponding value will be written to the output stream.
899  *
900  * \param out output stream
901  * \param __begin begin of format
902  * \param __end end of format
903  * \return output stream
904  */
905  template<class T>
906  std::ostream& write(std::ostream& out, T __begin, T __end)
907  {
908  using namespace std;
909 
910  for (T i = __begin; i != __end; ++i) {
911 
912  iterator p = find(*i);
913 
914  if (p != end()) {
915 
916  out << getDefaultWhiteSpace();
917 
918  p->second->write(out);
919 
920  } else {
921 
922  WARNING("JProperties::write(): unknown key <" << *i << ">" << endl);
923  }
924  }
925 
926  return out;
927  }
928 
929 
930  /**
931  * Stream editing of input format.
932  *
933  * For each key in the format specification,
934  * a corresponding value will be written to the output stream.
935  *
936  * \param format format
937  * \param prefix prefix key word
938  * \param postfix postfix key word
939  * \return output stream
940  */
941  std::string sed(const std::string& format,
942  const std::string& prefix = "",
943  const std::string& postfix = "")
944  {
945  using namespace std;
946 
947  string buffer = format;
948 
949  for (iterator i = begin(); i != end(); ++i) {
950 
951  string::size_type ipos = 0;
952 
953  while ((ipos = buffer.find(prefix + i->first + postfix, ipos)) != string::npos) {
954 
955  ostringstream out;
956 
957  i->second->write(out);
958 
959  buffer.replace(ipos, prefix.length() + i->first.length() + postfix.length(), out.str());
960  }
961  }
962 
963  return buffer;
964  }
965 
966 
967  /**
968  * Get value.
969  *
970  * \param key key
971  * \return value of this JPropertiesElement
972  */
973  template<class T>
974  const T& getValue(const std::string& key) const
975  {
976  const_iterator i = find(key);
977 
978  if (i != end())
979  return i->second.getValue<T>();
980  else
981  THROW(JPropertiesException, "Key <" << key << "> not found at JPropertiesElement::getValue()");
982  }
983 
984 
985  /**
986  * Get value.
987  *
988  * \param key key
989  * \return value of this JPropertiesElement
990  */
991  template<class T>
992  T& getValue(const std::string& key)
993  {
994  iterator i = find(key);
995 
996  if (i != end())
997  return i->second.getValue<T>();
998  else
999  THROW(JPropertiesException, "Key <" << key << "> not found at JPropertiesElement::getValue()");
1000  }
1001 
1002 
1003  /**
1004  * Set value.
1005  *
1006  * \param key key
1007  * \param value value
1008  */
1009  template<class T>
1010  void setValue(const std::string& key, const T& value)
1011  {
1012  iterator i = find(key);
1013 
1014  if (i != end())
1015  return i->second.setValue<T>(value);
1016  else
1017  THROW(JPropertiesException, "Key <" << key << "> not found at JPropertiesElement::setValue()");
1018  }
1019 
1020 
1021  /**
1022  * Get string value.
1023  *
1024  * \param key key
1025  * \return value
1026  */
1028  {
1029  const_iterator i = find(key);
1030 
1031  if (i != end())
1032  return i->second.toString();
1033  else
1034  THROW(JPropertiesException, "Key <" << key << "> not found at JPropertiesElement::getString()");
1035  }
1036 
1037 
1038  /**
1039  * Print the current parameter values.
1040  *
1041  * \param out output stream
1042  * \return output stream
1043  */
1044  std::ostream& print(std::ostream& out) const
1045  {
1046  write(out);
1047 
1048  return out;
1049  }
1050 
1051 
1052  /**
1053  * Stream input.
1054  *
1055  * \param in input stream
1056  * \param properties properties
1057  * \return input stream
1058  */
1059  friend inline std::istream& operator>>(std::istream& in, JProperties& properties)
1060  {
1061  return properties.read(in);
1062  }
1063 
1064 
1065  /**
1066  * Stream output.
1067  *
1068  * \param out output stream
1069  * \param properties properties
1070  * \return output stream
1071  */
1072  friend inline std::ostream& operator<<(std::ostream& out, const JProperties& properties)
1073  {
1074  return properties.write(out);
1075  }
1076  };
1077 
1078 
1079  /**
1080  * Template specialisation for JFileReader.
1081  * This class will not produce ASCII output.
1082  */
1083  template<>
1086  {
1087  public:
1088  /**
1089  * Constructor.
1090  *
1091  * \param value reference of template bject
1092  */
1095  object(value)
1096  {}
1097 
1098 
1099  /**
1100  * Stream input.
1101  *
1102  * \param in input stream
1103  * \return input stream
1104  */
1105  virtual std::istream& read(std::istream& in) override
1106  {
1107  return in >> object;
1108  }
1109 
1110 
1111  /**
1112  * Stream output.
1113  *
1114  * \param out output stream
1115  * \param prefix prefix
1116  * \param postfix postfix
1117  * \return output stream
1118  */
1119  virtual std::ostream& write(std::ostream& out,
1120  const char* prefix,
1121  const char postfix) const override
1122  {
1123  return out;
1124  }
1125 
1126 
1127  /**
1128  * Stream output.
1129  *
1130  * \param out output stream
1131  * \return output stream
1132  */
1133  virtual std::ostream& write(std::ostream& out) const override
1134  {
1135  return out;
1136  }
1137 
1138 
1139  /**
1140  * Equality between property element interfaces.
1141  *
1142  * \param element properties element interface
1143  * \return true if equal; else false
1144  */
1145  virtual bool equals(const JPropertiesElementInterface& element) const override
1146  {
1147  return false;
1148  }
1149 
1150  private:
1152  };
1153 
1154 
1155  /**
1156  * Template specialisation for JProperties.
1157  */
1158  template<>
1161  {
1162  public:
1163  /**
1164  * Constructor.
1165  *
1166  * \param value reference of template bject
1167  */
1170  object(value)
1171  {}
1172 
1173 
1174  /**
1175  * Stream input.
1176  *
1177  * \param in input stream
1178  * \return input stream
1179  */
1180  virtual std::istream& read(std::istream& in) override
1181  {
1182  object.read(in);
1183 
1184  return in;
1185  }
1186 
1187 
1188  /**
1189  * Stream output.
1190  *
1191  * \param out output stream
1192  * \param prefix prefix
1193  * \param postfix postfix
1194  * \return output stream
1195  */
1196  virtual std::ostream& write(std::ostream& out,
1197  const char* prefix,
1198  const char postfix) const override
1199  {
1200  using namespace std;
1201 
1202  for (JProperties::const_iterator i = object.begin(); i != object.end(); ++i) {
1203 
1204  char c = ' ';
1205 
1206  if (i->second->is_properties()) {
1207  c = object.getDefaultDivision ();
1208  } else {
1209  c = object.getDefaultSeparator();
1210  }
1211 
1212  i->second->write(out, (prefix + i->first + c).c_str(), postfix);
1213  }
1214 
1215  out << flush;
1216 
1217  return out;
1218  }
1219 
1220 
1221  /**
1222  * Stream output.
1223  *
1224  * \param out output stream
1225  * \return output stream
1226  */
1227  virtual std::ostream& write(std::ostream& out) const override
1228  {
1229  return writeObject(out, object);
1230  }
1231 
1232 
1233  /**
1234  * Get properties type.
1235  *
1236  * \return true
1237  */
1238  virtual bool is_properties() const override
1239  {
1240  return true;
1241  }
1242 
1243 
1244  private:
1246  };
1247 
1248 
1249  /**
1250  * Get properties of a given object.
1251  *
1252  * This method transfers the making of the property object to the corresponding class
1253  * whilst preserving the constness of the argument.\n
1254  * The corresponding class should implement the method:
1255  * <pre>
1256  * template<bool is_constant>
1257  * static JProperties getProperties(typename JCategory<T, is_constant>::reference_type object,
1258  * const JEquationParameters& equation,
1259  * const int debug)
1260  * </pre>
1261  *
1262  * \param object object
1263  * \param parameters equation parameters
1264  * \param debug debug level
1265  */
1266  template<class T>
1267  inline JProperties& getProperties(T& object,
1269  const int debug = 1)
1270  {
1271  using namespace JPP;
1272 
1273  static JProperties properties;
1274 
1275  properties = T::template getProperties<JClass<T>::is_constant>(object, parameters, debug);
1276 
1277  return properties;
1278  }
1279 }
1280 
1281 
1283 using JLANG::JCategory;
1284 using JEEP::JProperties;
1285 using JEEP::getProperties;
1286 
1287 
1288 /**
1289  * macro to convert (template) parameter to JPropertiesElement object
1290  */
1291 #define gmake_property(A) JProperties::value_type(JProperties::getKey(#A,".>/:"), JEEP::JPropertiesElement(A))
1292 
1293 
1294 #endif
Exception for opening of file.
Definition: JException.hh:342
virtual std::ostream & write(std::ostream &out, const char *prefix, const char postfix) const override
Stream output.
const std::string & getKey() const
Get key.
Definition: JEquation.hh:163
JProperties(const JEquationParameters &parameters, const int debug=0)
Constructor.
Definition: JProperties.hh:634
Exception for reading of file.
Definition: JException.hh:378
bool read(const JEquation &equation)
Read equation.
Definition: JProperties.hh:677
Exceptions.
std::istream & read(std::istream &in, const std::string &format)
Read from input stream according given format.
Definition: JProperties.hh:782
const std::string & getValue() const
Get value.
Definition: JEquation.hh:185
Facet class to specify parsing of equations in currect locale (see class JLANG::JEquation).
JEquationParameters & join(const JEquationParameters &value)
Join equation parameters.
virtual std::ostream & write(std::ostream &out) const override
Stream output.
Definition: JProperties.hh:174
void put(const std::string &key, T &object)
Put object at given key.
Definition: JProperties.hh:650
bool equals(const JPropertiesElement &element) const
Equality between property elements.
Definition: JProperties.hh:324
virtual std::istream & read(std::istream &in) override
Stream input.
Definition: JProperties.hh:134
Interface for ASCII input using standard streams.
Definition: JAbstractIO.hh:21
virtual std::istream & read(std::istream &in) override
Stream input.
JProperties & getProperties(T &object, const JEquationParameters &parameters=JEquationParameters(), const int debug=1)
Get properties of a given object.
std::map< std::string, JPropertiesElement > JMap_t
Definition: JProperties.hh:503
Exception when parsing a value.
Definition: JException.hh:558
Template specialisation of JPropertiesTemplateElement for const data type.
Definition: JProperties.hh:208
friend std::istream & operator>>(std::istream &in, JProperties::JFileReader &fileReader)
Stream input.
Definition: JProperties.hh:562
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:696
virtual std::ostream & write(std::ostream &out) const override
Stream output.
virtual std::ostream & write(std::ostream &out, const char *prefix, const char postfix) const override
Stream output.
Definition: JProperties.hh:160
virtual bool equals(const JPropertiesElementInterface &element) const
Equality between property element interfaces.
Definition: JProperties.hh:94
Utility class to parse parameter values.
Definition: JProperties.hh:496
friend std::istream & operator>>(std::istream &in, JProperties &properties)
Stream input.
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
virtual std::istream & read(std::istream &in) override
Stream input.
void setEndMarker(const bool marker)
Set end marker.
Definition: JProperties.hh:458
Simple data structure to support I/O of equations (see class JLANG::JEquation).
virtual std::istream & read(std::istream &in) override
Stream input.
Definition: JProperties.hh:232
void setValue(const T &value)
Set value of this JPropertiesElement.
Definition: JProperties.hh:386
Auxiliary class to handle input from file.
Definition: JProperties.hh:534
is
Definition: JDAQCHSM.chsm:167
const T & getValue() const
Get value.
Definition: JProperties.hh:351
JPropertiesTemplateElement(const JProperties &value)
Constructor.
virtual std::ostream & write(std::ostream &out, const char *prefix, const char postfix) const
Stream output.
Definition: JProperties.hh:258
virtual std::ostream & write(std::ostream &out) const override
Stream output.
Definition: JProperties.hh:244
std::istream & readObject(std::istream &in, T &object)
Stream input of object.
bool read(const std::string &buffer)
Read from input string.
Definition: JProperties.hh:738
JPropertiesTemplateElement(const T &value)
Constructor.
Definition: JProperties.hh:220
JPropertiesTemplateElement(T &value)
Constructor.
Definition: JProperties.hh:122
General purpose equation class.
Definition: JEquation.hh:47
virtual std::ostream & write(std::ostream &out, const char *prefix, const char postfix) const override
Stream output.
const T & getValue(const std::string &key) const
Get value.
Definition: JProperties.hh:974
std::string sed(const std::string &format, const std::string &prefix="", const std::string &postfix="")
Stream editing of input format.
Definition: JProperties.hh:941
std::ostream & print(std::ostream &out) const
Print the current parameter values.
The template JSharedPointer class can be used to share a pointer to an object.
JFileReader(JProperties &__properties)
Definition: JProperties.hh:536
std::ostream & write(std::ostream &out) const
Write the current parameter values.
Definition: JProperties.hh:845
std::string getString(const std::string &key) const
Get string value.
JProperties(const int debug=0)
Constructor.
Definition: JProperties.hh:620
bool getEndMarker() const
Get end marker.
Definition: JProperties.hh:447
virtual bool is_properties() const
Get properties type.
Definition: JProperties.hh:82
JPropertiesElement(T &value)
Constructor.
Definition: JProperties.hh:311
do set_variable OUTPUT_DIRECTORY $WORKDIR T
JPropertiesElement & operator=(T &value)
Assignment operator.
Definition: JProperties.hh:337
virtual bool equals(const JPropertiesElementInterface &element) const override
Equality between property element interfaces.
Definition: JProperties.hh:272
#define ERROR(A)
Definition: JMessage.hh:66
then awk string
JProperties & join(const JProperties &properties)
Join properties objects.
Definition: JProperties.hh:661
Template class for I/O of properties element.
Definition: JProperties.hh:110
std::istream & read(std::istream &in)
Read from input stream.
Definition: JProperties.hh:760
virtual bool equals(const JPropertiesElementInterface &element) const override
Equality between property element interfaces.
Definition: JProperties.hh:186
JFileReader & operator=(const std::string &file_name)
Assignment operator.
Definition: JProperties.hh:547
virtual bool is_properties() const override
Get properties type.
bool compareObjects(const T &first, const T &second, JBool< true >)
Comparison of comparable objects.
General purpose messaging.
T & getValue(const std::string &key)
Get value.
Definition: JProperties.hh:992
void setValue(const std::string &key, const T &value)
Set value.
bool fail(std::istream &in)
Check for stream state.
Definition: JParser.hh:113
virtual std::ostream & write(std::ostream &out) const =0
Stream output.
friend std::ostream & operator<<(std::ostream &out, const JProperties::JFileReader &fileReader)
Stream output.
Definition: JProperties.hh:581
std::string toString() const
Convert to string.
Definition: JProperties.hh:402
$WORKDIR ev_configure_dqsimulator txt echo process $DQ_SIMULATOR $i $SOURCE_HOST[$index] csh c(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&($DQ_SIMULATOR\-u\$NAME\$\-H\$SERVER\$\-M\$LOGGER\$\-d $DEBUG</dev/null > &/dev/null &))'
void reset(T &value)
Reset value.
The property value class.
Definition: JProperties.hh:293
Interface for ASCII output using standard streams.
Definition: JAbstractIO.hh:56
JPropertiesTemplateElement(JProperties::JFileReader &value)
Constructor.
friend std::ostream & operator<<(std::ostream &out, const JProperties &properties)
Stream output.
T & getValue()
Get value.
Definition: JProperties.hh:368
std::ostream & write(std::ostream &out, const std::string &format)
Write to output stream according given format.
Definition: JProperties.hh:878
T toValue() const
Convert to template type.
Definition: JProperties.hh:418
virtual std::ostream & write(std::ostream &out, const char *prefix, const char postfix) const =0
Stream output.
std::ostream & write(std::ostream &out, T __begin, T __end)
Write to output stream according given format.
Definition: JProperties.hh:906
const char getSeparator() const
Get separator.
Definition: JEquation.hh:174
static std::string getKey(const std::string &buffer, const std::string &sep)
Utility method to strip off all leading characters from a string until specified character(s).
Definition: JProperties.hh:515
JPropertiesElement()
Default constructor.
Definition: JProperties.hh:300
virtual std::ostream & write(std::ostream &out) const override
Stream output.
std::istream & read(std::istream &in, T __begin, T __end)
Read from input stream according given format.
Definition: JProperties.hh:810
void read(const std::string &file_name)
Read properties from file.
Definition: JProperties.hh:593
Interface for I/O of properties element.
Definition: JProperties.hh:66
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
then echo WARNING
Definition: JTuneHV.sh:91
Interface for ASCII output with prefix and postfix using standard streams.
Definition: JAbstractIO.hh:91
virtual JClass_t * get() const override
Get pointer.
Definition: JPointer.hh:64
Auxiliary class to define value, reference and pointer types for given data type and category...
Definition: JCategory.hh:18
virtual bool equals(const JPropertiesElementInterface &element) const override
Equality between property element interfaces.
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
Auxiliary class for handling debug parameter within a class.
Definition: JMessage.hh:44
std::ostream & writeObject(std::ostream &out, const T &object)
Stream output of object.