1#ifndef __JEEP__JPROPERTIES__
2#define __JEEP__JPROPERTIES__
34namespace JPP {
using namespace JEEP; }
59 inline bool fail(std::istream& in)
61 return in.bad() || (in.fail() && !in.eof());
136 virtual std::istream&
read(std::istream& in)
override
146 if (!buffer.empty()) {
162 virtual std::ostream&
write(std::ostream& out,
164 const char postfix)
const override
176 virtual std::ostream&
write(std::ostream& out)
const override
234 virtual std::istream&
read(std::istream& in)
override
246 virtual std::ostream&
write(std::ostream& out)
const override
260 virtual std::ostream&
write(std::ostream& out,
262 const char postfix)
const override
328 return get()->equals(*element.
get());
406 std::ostringstream os;
408 get()->write(os,
"",
'\0');
424 std::istringstream in(this->
toString());
438 operator const T&()
const
500 public std::map<std::string, JPropertiesElement>,
518 static inline std::string
getKey(
const std::string& buffer,
const std::string&
sep)
522 const size_type pos = buffer.find_last_of(
sep);
524 if (pos != string::npos)
525 return buffer.substr(pos + 1);
551 const int debug = 0) :
566 void put(
const std::string& key, T&
object)
582 insert(properties.begin(), properties.end());
600 DEBUG(
"Processing key: " << equation.
getKey() <<
' ' << (p != end()) << endl);
604 istringstream is(equation.
getValue());
608 if (p->second->is_properties()) {
614 ERROR(
"JProperties::read(): no properties object after division <" << equation.
getKey() <<
">" << endl);
622 catch(
const exception& error) {
623 ERROR(
"JProperties::read(): read error at key <" << equation.
getKey() <<
"> " << error.what() << endl);
628 ERROR(
"JProperties::read(): illegal character following key <" << equation.
getKey() <<
"> " << equation.
getSeparator() << endl);
631 if (p->second.getEndMarker()) {
637 ERROR(
"JProperties::read(): error reading data for key <" << equation.
getKey() <<
"> " << equation.
getValue() << endl);
642 WARNING(
"JProperties::read(): unknown key <" << equation.
getKey() <<
">" << endl);
655 bool read(
const std::string& buffer)
657 std::istringstream in(buffer);
677 std::istream&
read(std::istream& in)
684 if (getFileStatus(is.str().c_str())) {
690 for (
JEquation equation; is >> equation &&
read(equation); ) {}
706 std::istream&
read(std::istream& in,
const std::string& format)
710 istringstream is(format);
714 for (
string key; is >> key; ) {
715 buffer.push_back(key);
718 return read(in, buffer.begin(), buffer.end());
734 std::istream&
read(std::istream& in, T __begin, T __end)
738 for (T i = __begin; i != __end; ++i) {
748 WARNING(
"JProperties::read(): unknown key <" << *i <<
">" << endl);
769 std::ostream&
write(std::ostream& out)
const
773 for (const_iterator i = begin(); i != end(); ++i) {
777 if (i->second->is_properties()) {
802 std::ostream&
write(std::ostream& out,
const std::string& format)
806 istringstream is(format);
810 for (
string key; is >> key; ) {
811 buffer.push_back(key);
814 return write(out, buffer.begin(), buffer.end());
830 std::ostream&
write(std::ostream& out, T __begin, T __end)
834 for (T i = __begin; i != __end; ++i) {
842 p->second->write(out);
846 WARNING(
"JProperties::write(): unknown key <" << *i <<
">" << endl);
865 std::string
sed(
const std::string& format,
866 const std::string& prefix =
"",
867 const std::string& postfix =
"")
871 string buffer = format;
873 for (
iterator i = begin(); i != end(); ++i) {
875 string::size_type ipos = 0;
877 while ((ipos = buffer.find(prefix + i->first + postfix, ipos)) != string::npos) {
881 i->second->write(out);
883 buffer.replace(ipos, prefix.length() + i->first.length() + postfix.length(), out.str());
900 const_iterator i = find(key);
903 return i->second.getValue<T>();
921 return i->second.getValue<T>();
934 void setValue(
const std::string& key,
const T& value)
939 return i->second.setValue<T>(value);
953 const_iterator i = find(key);
956 return i->second.toString();
968 std::ostream&
print(std::ostream& out)
const
985 return properties.
read(in);
998 return properties.
write(out);
1028 virtual std::istream&
read(std::istream& in)
override
1044 virtual std::ostream&
write(std::ostream& out,
1046 const char postfix)
const override
1048 using namespace std;
1050 for (JProperties::const_iterator i =
object.begin(); i !=
object.end(); ++i) {
1054 if (i->second->is_properties()) {
1055 c =
object.getDefaultDivision ();
1057 c =
object.getDefaultSeparator();
1060 i->second->write(out, (prefix + i->first + c).c_str(), postfix);
1075 virtual std::ostream&
write(std::ostream& out)
const override
1117 const int debug = 1)
1119 using namespace JPP;
1123 properties = T::template getProperties<JClass<T>::is_constant>(object, parameters,
debug);
1139#define gmake_property(A) JProperties::value_type(JProperties::getKey(#A,".>/:"), JEEP::JPropertiesElement(A))
1140#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, T __begin, T __end)
Write to output stream according given format.
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 & write(std::ostream &out, const std::string &format)
Write to output stream according given format.
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.
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.
virtual JClass_t * get() const override
Get pointer.
Exception when parsing a value.
The template JSharedPointer class can be used to share a pointer to an object.
virtual void reset() override
Reset pointer.
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.
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.
bool compareObjects(const T &first, const T &second, JBool< true >)
Comparison of comparable objects.
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.