1#ifndef __JEEP__JPROPERTIES__
2#define __JEEP__JPROPERTIES__
33namespace JPP {
using namespace JEEP; }
57 inline bool fail(std::istream& in)
59 return in.bad() || (in.fail() && !in.eof());
134 virtual std::istream&
read(std::istream& in)
override
144 if (!buffer.empty()) {
160 virtual std::ostream&
write(std::ostream& out,
162 const char postfix)
const override
174 virtual std::ostream&
write(std::ostream& out)
const override
232 virtual std::istream&
read(std::istream& in)
override
244 virtual std::ostream&
write(std::ostream& out)
const override
258 virtual std::ostream&
write(std::ostream& out,
260 const char postfix)
const override
294 public std::shared_ptr<JPropertiesElementInterface>
326 return get()->equals(*element.get());
404 std::ostringstream os;
406 get()->write(os,
"",
'\0');
422 std::istringstream in(this->
toString());
436 operator const T&()
const
497 public std::map<std::string, JPropertiesElement>,
515 static inline std::string
getKey(
const std::string& buffer,
const std::string&
sep)
519 const size_type pos = buffer.find_last_of(
sep);
521 if (pos != string::npos)
522 return buffer.substr(pos + 1);
548 const int debug = 0) :
563 void put(
const std::string& key, T&
object)
579 insert(properties.begin(), properties.end());
597 DEBUG(
"Processing key: " << equation.
getKey() <<
' ' << (p != end()) << endl);
601 istringstream is(equation.
getValue());
605 if (p->second->is_properties()) {
611 ERROR(
"JProperties::read(): no properties object after division <" << equation.
getKey() <<
">" << endl);
619 catch(
const exception& error) {
620 ERROR(
"JProperties::read(): read error at key <" << equation.
getKey() <<
"> " << error.what() << endl);
625 ERROR(
"JProperties::read(): illegal character following key <" << equation.
getKey() <<
"> " << equation.
getSeparator() << endl);
628 if (p->second.getEndMarker()) {
634 ERROR(
"JProperties::read(): error reading data for key <" << equation.
getKey() <<
"> " << equation.
getValue() << endl);
639 WARNING(
"JProperties::read(): unknown key <" << equation.
getKey() <<
">" << endl);
652 bool read(
const std::string& buffer)
654 std::istringstream in(buffer);
674 std::istream&
read(std::istream& in)
683 for (
JEquation equation; is >> equation &&
read(equation); ) {}
699 std::istream&
read(std::istream& in,
const std::string& format)
703 istringstream is(format);
707 for (
string key; is >> key; ) {
708 buffer.push_back(key);
711 return read(in, buffer.begin(), buffer.end());
727 std::istream&
read(std::istream& in, T __begin, T __end)
731 for (T i = __begin; i != __end; ++i) {
741 WARNING(
"JProperties::read(): unknown key <" << *i <<
">" << endl);
762 std::ostream&
write(std::ostream& out)
const
766 for (const_iterator i = begin(); i != end(); ++i) {
770 if (i->second->is_properties()) {
795 std::ostream&
write(std::ostream& out,
const std::string& format)
const
799 istringstream is(format);
803 for (
string key; is >> key; ) {
804 buffer.push_back(key);
807 return write(out, buffer.begin(), buffer.end());
823 std::ostream&
write(std::ostream& out, T __begin, T __end)
const
827 for (T i = __begin; i != __end; ++i) {
829 const_iterator p = find(*i);
835 p->second->write(out);
839 WARNING(
"JProperties::write(): unknown key <" << *i <<
">" << endl);
858 std::string
sed(
const std::string& format,
859 const std::string& prefix =
"",
860 const std::string& postfix =
"")
864 string buffer = format;
866 for (
iterator i = begin(); i != end(); ++i) {
868 string::size_type ipos = 0;
870 while ((ipos = buffer.find(prefix + i->first + postfix, ipos)) != string::npos) {
874 i->second->write(out);
876 buffer.replace(ipos, prefix.length() + i->first.length() + postfix.length(), out.str());
893 const_iterator i = find(key);
896 return i->second.getValue<T>();
914 return i->second.getValue<T>();
927 void setValue(
const std::string& key,
const T& value)
932 return i->second.setValue<T>(value);
946 const_iterator i = find(key);
949 return i->second.toString();
961 std::ostream&
print(std::ostream& out)
const
978 return properties.
read(in);
991 return properties.
write(out);
1021 virtual std::istream&
read(std::istream& in)
override
1037 virtual std::ostream&
write(std::ostream& out,
1039 const char postfix)
const override
1041 using namespace std;
1043 for (JProperties::const_iterator i =
object.begin(); i !=
object.end(); ++i) {
1047 if (i->second->is_properties()) {
1048 c =
object.getDefaultDivision ();
1050 c =
object.getDefaultSeparator();
1053 i->second->write(out, (prefix + i->first + c).c_str(), postfix);
1068 virtual std::ostream&
write(std::ostream& out)
const override
1110 const int debug = 1)
1112 using namespace JPP;
1116 properties = T::template getProperties<JClass<T>::is_constant>(object, parameters,
debug);
1132#define gmake_property(A) JProperties::value_type(JProperties::getKey(#A,".>/:"), JEEP::JPropertiesElement(A))
1133#define zmake_property(A) JProperties::value_type(#A, JEEP::JPropertiesElement(A))
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
General purpose messaging.
#define DEBUG(A)
Message macros.
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.
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 ¶meters, 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.
const std::string & getKey() const
Get key.
const std::string & getValue() const
Get value.
const char getSeparator() const
Get separator.
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 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.
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 ¶meters=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.
Auxiliary class to define value, reference and pointer types for given data type and category.