1#ifndef __JEEP__JPROPERTIES__
2#define __JEEP__JPROPERTIES__
32namespace 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
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
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);
565 std::string file_name;
569 fileReader.
read(file_name);
594 void read(
const std::string& file_name)
596 std::ifstream in(file_name.c_str());
636 const int debug = 0) :
651 void put(
const std::string& key, T&
object)
667 insert(properties.begin(), properties.end());
685 DEBUG(
"Processing key: " << equation.
getKey() <<
' ' << (p != end()) << endl);
689 istringstream is(equation.
getValue());
693 if (p->second->is_properties()) {
699 ERROR(
"JProperties::read(): no properties object after division <" << equation.
getKey() <<
">" << endl);
707 catch(
const exception& error) {
708 ERROR(
"JProperties::read(): read error at key <" << equation.
getKey() <<
"> " << error.what() << endl);
713 ERROR(
"JProperties::read(): illegal character following key <" << equation.
getKey() <<
"> " << equation.
getSeparator() << endl);
716 if (p->second.getEndMarker()) {
722 ERROR(
"JProperties::read(): error reading data for key <" << equation.
getKey() <<
"> " << equation.
getValue() << endl);
727 WARNING(
"JProperties::read(): unknown key <" << equation.
getKey() <<
">" << endl);
740 bool read(
const std::string& buffer)
742 std::istringstream in(buffer);
762 std::istream&
read(std::istream& in)
768 for (
JEquation equation; in >> equation &&
read(equation); ) {}
784 std::istream&
read(std::istream& in,
const std::string& format)
788 istringstream is(format);
792 for (
string key; is >> key; ) {
793 buffer.push_back(key);
796 return read(in, buffer.begin(), buffer.end());
812 std::istream&
read(std::istream& in, T __begin, T __end)
816 for (T i = __begin; i != __end; ++i) {
826 WARNING(
"JProperties::read(): unknown key <" << *i <<
">" << endl);
847 std::ostream&
write(std::ostream& out)
const
851 for (const_iterator i = begin(); i != end(); ++i) {
855 if (i->second->is_properties()) {
880 std::ostream&
write(std::ostream& out,
const std::string& format)
884 istringstream is(format);
888 for (
string key; is >> key; ) {
889 buffer.push_back(key);
892 return write(out, buffer.begin(), buffer.end());
908 std::ostream&
write(std::ostream& out, T __begin, T __end)
912 for (T i = __begin; i != __end; ++i) {
920 p->second->write(out);
924 WARNING(
"JProperties::write(): unknown key <" << *i <<
">" << endl);
943 std::string
sed(
const std::string& format,
944 const std::string& prefix =
"",
945 const std::string& postfix =
"")
949 string buffer = format;
951 for (
iterator i = begin(); i != end(); ++i) {
953 string::size_type ipos = 0;
955 while ((ipos = buffer.find(prefix + i->first + postfix, ipos)) != string::npos) {
959 i->second->write(out);
961 buffer.replace(ipos, prefix.length() + i->first.length() + postfix.length(), out.str());
978 const_iterator i = find(key);
981 return i->second.getValue<T>();
999 return i->second.getValue<T>();
1017 return i->second.setValue<T>(value);
1031 const_iterator i = find(key);
1034 return i->second.toString();
1046 std::ostream&
print(std::ostream& out)
const
1063 return properties.
read(in);
1076 return properties.
write(out);
1107 virtual std::istream&
read(std::istream& in)
override
1121 virtual std::ostream&
write(std::ostream& out,
1123 const char postfix)
const override
1135 virtual std::ostream&
write(std::ostream& out)
const override
1182 virtual std::istream&
read(std::istream& in)
override
1198 virtual std::ostream&
write(std::ostream& out,
1200 const char postfix)
const override
1202 using namespace std;
1204 for (JProperties::const_iterator i =
object.begin(); i !=
object.end(); ++i) {
1208 if (i->second->is_properties()) {
1209 c =
object.getDefaultDivision ();
1211 c =
object.getDefaultSeparator();
1214 i->second->write(out, (prefix + i->first + c).c_str(), postfix);
1229 virtual std::ostream&
write(std::ostream& out)
const override
1271 const int debug = 1)
1273 using namespace JPP;
1277 properties = T::template getProperties<JClass<T>::is_constant>(object, parameters,
debug);
1293#define gmake_property(A) JProperties::value_type(JProperties::getKey(#A,".>/:"), JEEP::JPropertiesElement(A))
1294#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 bool equals(const JPropertiesElementInterface &element) const override
Equality between property element interfaces.
virtual std::ostream & write(std::ostream &out, const char *prefix, const char postfix) const override
Stream output.
JPropertiesTemplateElement(JProperties::JFileReader &value)
Constructor.
virtual std::ostream & write(std::ostream &out) const override
Stream output.
JProperties::JFileReader & object
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 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.
Auxiliary class to handle input from file.
void read(const std::string &file_name)
Read properties from file.
JFileReader(JProperties &__properties)
friend std::istream & operator>>(std::istream &in, JProperties::JFileReader &fileReader)
Stream input.
JFileReader & operator=(const std::string &file_name)
Assignment operator.
friend std::ostream & operator<<(std::ostream &out, const JProperties::JFileReader &fileReader)
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.
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.