1#ifndef __JEEP__JPROPERTIES__
2#define __JEEP__JPROPERTIES__
34namespace JPP {
using namespace JEEP; }
58 inline bool fail(std::istream& in)
60 return in.bad() || (in.fail() && !in.eof());
135 virtual std::istream&
read(std::istream& in)
override
145 if (!buffer.empty()) {
161 virtual std::ostream&
write(std::ostream& out,
163 const char postfix)
const override
175 virtual std::ostream&
write(std::ostream& out)
const override
233 virtual std::istream&
read(std::istream& in)
override
245 virtual std::ostream&
write(std::ostream& out)
const override
259 virtual std::ostream&
write(std::ostream& out,
261 const char postfix)
const override
295 public std::shared_ptr<JPropertiesElementInterface>
327 return get()->equals(*element.get());
405 std::ostringstream os;
407 get()->write(os,
"",
'\0');
423 std::istringstream in(this->
toString());
437 operator const T&()
const
498 public std::map<std::string, JPropertiesElement>,
516 static inline std::string
getKey(
const std::string& buffer,
const std::string&
sep)
520 const size_type pos = buffer.find_last_of(
sep);
522 if (pos != string::npos)
523 return buffer.substr(pos + 1);
549 const int debug = 0) :
564 void put(
const std::string& key, T&
object)
580 insert(properties.begin(), properties.end());
598 DEBUG(
"Processing key: " << equation.
getKey() <<
' ' << (p != end()) << endl);
602 istringstream is(equation.
getValue());
606 if (p->second->is_properties()) {
612 ERROR(
"JProperties::read(): no properties object after division <" << equation.
getKey() <<
">" << endl);
620 catch(
const exception& error) {
621 ERROR(
"JProperties::read(): read error at key <" << equation.
getKey() <<
"> " << error.what() << endl);
626 ERROR(
"JProperties::read(): illegal character following key <" << equation.
getKey() <<
"> " << equation.
getSeparator() << endl);
629 if (p->second.getEndMarker()) {
635 ERROR(
"JProperties::read(): error reading data for key <" << equation.
getKey() <<
"> " << equation.
getValue() << endl);
640 WARNING(
"JProperties::read(): unknown key <" << equation.
getKey() <<
">" << endl);
653 bool read(
const std::string& buffer)
655 std::istringstream in(buffer);
675 std::istream&
read(std::istream& in)
682 if (getFileStatus(is.str().c_str())) {
688 for (
JEquation equation; is >> equation &&
read(equation); ) {}
704 std::istream&
read(std::istream& in,
const std::string& format)
708 istringstream is(format);
712 for (
string key; is >> key; ) {
713 buffer.push_back(key);
716 return read(in, buffer.begin(), buffer.end());
732 std::istream&
read(std::istream& in, T __begin, T __end)
736 for (T i = __begin; i != __end; ++i) {
746 WARNING(
"JProperties::read(): unknown key <" << *i <<
">" << endl);
767 std::ostream&
write(std::ostream& out)
const
771 for (const_iterator i = begin(); i != end(); ++i) {
775 if (i->second->is_properties()) {
800 std::ostream&
write(std::ostream& out,
const std::string& format)
const
804 istringstream is(format);
808 for (
string key; is >> key; ) {
809 buffer.push_back(key);
812 return write(out, buffer.begin(), buffer.end());
828 std::ostream&
write(std::ostream& out, T __begin, T __end)
const
832 for (T i = __begin; i != __end; ++i) {
834 const_iterator p = find(*i);
840 p->second->write(out);
844 WARNING(
"JProperties::write(): unknown key <" << *i <<
">" << endl);
863 std::string
sed(
const std::string& format,
864 const std::string& prefix =
"",
865 const std::string& postfix =
"")
869 string buffer = format;
871 for (
iterator i = begin(); i != end(); ++i) {
873 string::size_type ipos = 0;
875 while ((ipos = buffer.find(prefix + i->first + postfix, ipos)) != string::npos) {
879 i->second->write(out);
881 buffer.replace(ipos, prefix.length() + i->first.length() + postfix.length(), out.str());
898 const_iterator i = find(key);
901 return i->second.getValue<T>();
919 return i->second.getValue<T>();
932 void setValue(
const std::string& key,
const T& value)
937 return i->second.setValue<T>(value);
951 const_iterator i = find(key);
954 return i->second.toString();
966 std::ostream&
print(std::ostream& out)
const
983 return properties.
read(in);
996 return properties.
write(out);
1026 virtual std::istream&
read(std::istream& in)
override
1042 virtual std::ostream&
write(std::ostream& out,
1044 const char postfix)
const override
1046 using namespace std;
1048 for (JProperties::const_iterator i =
object.begin(); i !=
object.end(); ++i) {
1052 if (i->second->is_properties()) {
1053 c =
object.getDefaultDivision ();
1055 c =
object.getDefaultSeparator();
1058 i->second->write(out, (prefix + i->first + c).c_str(), postfix);
1073 virtual std::ostream&
write(std::ostream& out)
const override
1115 const int debug = 1)
1117 using namespace JPP;
1121 properties = T::template getProperties<JClass<T>::is_constant>(object, parameters,
debug);
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))
#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.
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 ¶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.