Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JLoadProperty.hh
Go to the documentation of this file.
1#ifndef __JLANG__JLOADPROPERTY__
2#define __JLANG__JLOADPROPERTY__
3
4#include <string>
5#include <iostream>
6
7
8/**
9 * \author bjjung
10 */
11
12namespace JLANG {}
13namespace JPP { using namespace JLANG; }
14
15namespace JLANG {
16
17
18 /**
19 * Data structure for object properties which require reloading whenever the property is reread.
20 *
21 * The first template parameter refers to the loadable object.\n
22 * This object needs to have an implementation of the method `void load()`\n.
23 * The second template parameter refers to the property type.\n
24 */
25 template<class JLoadableObject_t, class T>
27 public T
28 {
29 public:
30
32
33
34 /**
35 * Constructor.
36 *
37 * \param object pointer to loadable object
38 */
39 JLoadProperty(JLoadableObject_t& object) :
40 T (),
41 object(object)
42 {}
43
44
45 /**
46 * Constructor.
47 *
48 * \param object pointer to loadable object
49 * \param value property value
50 */
51 JLoadProperty(JLoadableObject_t& object,
52 const T& value) :
53 T (value),
54 object(object)
55 {}
56
57
58 /**
59 * Read property from input.
60 *
61 * \param in input stream.
62 * \return input stream
63 */
64 inline std::istream& read(std::istream& in)
65 {
66 in >> static_cast<T&>(*this);
67
68 object.load();
69
70 return in;
71 }
72
73
74 /**
75 * Assignment operator.
76 *
77 * \param buffer buffer
78 * \return property
79 */
80 inline JLoadProperty_t& operator=(const T& buffer)
81 {
82 static_cast<T&>(*this) = buffer;
83
84 return *this;
85 }
86
87
88 /**
89 * Input stream.
90 *
91 * \param in input stream
92 * \param property property
93 * \return input stream
94 */
95 friend inline std::istream& operator>>(std::istream& in, JLoadProperty& property)
96 {
97 return property.read(in);
98 }
99
100
101 /**
102 * Output stream
103 *
104 * \param out output stream
105 * \param property property
106 * \return output stream
107 */
108 friend inline std::ostream& operator<<(std::ostream& out, const JLoadProperty& property)
109 {
110 return out << static_cast<const T&>(property);
111 }
112
113
114 private:
115
116 JLoadableObject_t& object; // Reference to loadable object
117 };
118}
119
120#endif
Data structure for object properties which require reloading whenever the property is reread.
std::istream & read(std::istream &in)
Read property from input.
JLoadProperty< JLoadableObject_t, T > JLoadProperty_t
friend std::istream & operator>>(std::istream &in, JLoadProperty &property)
Input stream.
friend std::ostream & operator<<(std::ostream &out, const JLoadProperty &property)
Output stream.
JLoadProperty(JLoadableObject_t &object, const T &value)
Constructor.
JLoadProperty_t & operator=(const T &buffer)
Assignment operator.
JLoadProperty(JLoadableObject_t &object)
Constructor.
JLoadableObject_t & object
Auxiliary classes and methods for language specific functionality.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).