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