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