1 #ifndef __JEEP__JPROPERTIES__
2 #define __JEEP__JPROPERTIES__
32 namespace JPP {
using namespace JEEP; }
45 using JLANG::JComparisonAvailable;
57 inline bool fail(std::istream& in)
59 return in.bad() || (in.fail() && !in.eof());
134 virtual std::istream&
read(std::istream& in)
148 virtual std::ostream&
write(std::ostream& out,
150 const char postfix)
const
162 virtual std::ostream&
write(std::ostream& out)
const
220 virtual std::istream&
read(std::istream& in)
232 virtual std::ostream&
write(std::ostream& out)
const
246 virtual std::ostream&
write(std::ostream& out,
248 const char postfix)
const
392 std::ostringstream os;
394 get()->write(os,
"",
'\0');
410 std::istringstream in(this->
toString());
424 operator const T&()
const
426 return getValue<T>();
485 public std::map<std::string, JPropertiesElement>,
503 static inline std::string
getKey(
const std::string& buffer,
const std::string&
sep)
507 const size_type pos = buffer.find_last_of(sep);
509 if (pos != string::npos)
510 return buffer.substr(pos + 1);
552 std::string file_name;
556 fileReader.
read(file_name);
581 void read(
const std::string& file_name)
583 std::ifstream in(file_name.c_str());
623 const int debug = 0) :
638 void put(
const std::string& key, T&
object)
653 insert(properties.begin(), properties.end());
671 DEBUG(
"Processing key: " << equation.
getKey() <<
' ' << (p != end()) << endl);
675 istringstream is(equation.
getValue());
679 if (p->second->is_properties()) {
685 ERROR(
"JProperties::read(): no properties object after division <" << equation.
getKey() <<
">" << endl);
693 catch(
const exception& error) {
694 ERROR(
"JProperties::read(): " << error.what() << endl);
699 ERROR(
"JProperties::read(): illegal character following key <" << equation.
getKey() <<
"> " << equation.
getSeparator() << endl);
702 if (p->second.getEndMarker()) {
708 ERROR(
"JProperties::read(): error reading data for key <" << equation.
getKey() <<
"> " << equation.
getValue() << endl);
713 WARNING(
"JProperties::read(): unknown key <" << equation.
getKey() <<
">" << endl);
726 bool read(
const std::string& buffer)
728 std::istringstream in(buffer);
748 std::istream&
read(std::istream& in)
754 for (
JEquation equation; in >> equation &&
read(equation); ) {}
770 std::istream&
read(std::istream& in,
const std::string& format)
774 istringstream is(format);
778 for (
string key; is >> key; ) {
779 buffer.push_back(key);
782 return read(in, buffer.begin(), buffer.end());
798 std::istream&
read(std::istream& in, T __begin, T __end)
802 for (T i = __begin; i != __end; ++i) {
812 WARNING(
"JProperties::read(): unknown key <" << *i <<
">" << endl);
833 std::ostream&
write(std::ostream& out)
const
837 for (const_iterator i = begin(); i != end(); ++i) {
841 if (i->second->is_properties()) {
866 std::ostream&
write(std::ostream& out,
const std::string& format)
870 istringstream is(format);
874 for (
string key; is >> key; ) {
875 buffer.push_back(key);
878 return write(out, buffer.begin(), buffer.end());
894 std::ostream&
write(std::ostream& out, T __begin, T __end)
898 for (T i = __begin; i != __end; ++i) {
906 p->second->write(out);
910 WARNING(
"JProperties::write(): unknown key <" << *i <<
">" << endl);
929 std::string
sed(
const std::string& format,
930 const std::string& prefix =
"",
931 const std::string& postfix =
"")
935 string buffer = format;
937 for (
iterator i = begin(); i != end(); ++i) {
939 string::size_type ipos = 0;
941 while ((ipos = buffer.find(prefix + i->first + postfix, ipos)) != string::npos) {
945 i->second->write(out);
947 buffer.replace(ipos, prefix.length() + i->first.length() + postfix.length(), out.str());
964 const_iterator i = find(key);
967 return i->second.getValue<T>();
985 return i->second.getValue<T>();
998 void setValue(
const std::string& key,
const T& value)
1003 return i->second.setValue<T>(value);
1017 const_iterator i = find(key);
1020 return i->second.toString();
1032 std::ostream&
print(std::ostream& out)
const
1049 return properties.
read(in);
1062 return properties.
write(out);
1093 virtual std::istream&
read(std::istream& in)
1095 return in >> object;
1107 virtual std::ostream&
write(std::ostream& out,
1109 const char postfix)
const
1121 virtual std::ostream&
write(std::ostream& out)
const
1168 virtual std::istream&
read(std::istream& in)
1184 virtual std::ostream&
write(std::ostream& out,
1186 const char postfix)
const
1188 using namespace std;
1190 for (JProperties::const_iterator i =
object.begin(); i !=
object.end(); ++i) {
1194 if (i->second->is_properties()) {
1195 c =
object.getDefaultDivision ();
1197 c =
object.getDefaultSeparator();
1200 i->second->write(out, (prefix + i->first + c).c_str(), postfix);
1215 virtual std::ostream&
write(std::ostream& out)
const
1257 const int debug = 1)
1261 properties = T::template getProperties<true>(object, parameters,
debug);
1287 const int debug = 1)
1291 properties = T::template getProperties<false>(object, parameters,
debug);
1307 #define gmake_property(A) JProperties::value_type(JProperties::getKey(#A,".>/:"), JEEP::JPropertiesElement(A))
Exception for opening of file.
virtual bool equals(const JPropertiesElementInterface &element) const
Equality between property element interfaces.
const std::string & getKey() const
Get key.
JProperties(const JEquationParameters ¶meters, const int debug=0)
Constructor.
Exception for reading of file.
bool read(const JEquation &equation)
Read equation.
std::istream & read(std::istream &in, const std::string &format)
Read from input stream according given format.
const std::string & getValue() const
Get value.
Facet class to specify parsing of equations in currect locale (see class JLANG::JEquation).
JEquationParameters & join(const JEquationParameters &value)
Join equation parameters.
const char getDefaultSeparator() const
Get default separator character.
virtual std::istream & read(std::istream &in)
Stream input.
void put(const std::string &key, T &object)
Put object at given key.
bool equals(const JPropertiesElement &element) const
Equality between property elements.
virtual std::ostream & write(std::ostream &out) const
Stream output.
JProperties & getProperties(T &object, const JEquationParameters ¶meters=JEquationParameters(), const int debug=1)
Get properties of a given object.
virtual std::ostream & write(std::ostream &out) const
Stream output.
std::map< std::string, JPropertiesElement > JMap_t
Exception when parsing a value.
Template specialisation of JPropertiesTemplateElement for const data type.
friend std::istream & operator>>(std::istream &in, JProperties::JFileReader &fileReader)
Stream input.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
virtual bool equals(const JPropertiesElementInterface &element) const
Equality between property element interfaces.
Utility class to parse parameter values.
friend std::istream & operator>>(std::istream &in, JProperties &properties)
Stream input.
void setEndMarker(const bool marker)
Set end marker.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
void setValue(const T &value)
Set value of this JPropertiesElement.
Auxiliary class to handle input from file.
const T & getValue() const
Get value.
const char getDefaultWhiteSpace() const
Get default white space character.
JPropertiesTemplateElement(const JProperties &value)
Constructor.
virtual std::ostream & write(std::ostream &out, const char *prefix, const char postfix) const
Stream output.
virtual std::ostream & write(std::ostream &out) const
Stream output.
std::istream & readObject(std::istream &in, T &object)
Stream input of object.
bool read(const std::string &buffer)
Read from input string.
JPropertiesTemplateElement(const T &value)
Constructor.
JPropertiesTemplateElement(T &value)
Constructor.
General purpose equation class.
const T & getValue(const std::string &key) const
Get value.
JEquationParameters()
Default constructor.
std::string sed(const std::string &format, const std::string &prefix="", const std::string &postfix="")
Stream editing of input format.
std::ostream & print(std::ostream &out) const
Print the current parameter values.
The template JSharedPointer class can be used to share a pointer to an object.
JFileReader(JProperties &__properties)
std::ostream & write(std::ostream &out) const
Write the current parameter values.
virtual std::ostream & write(std::ostream &out) const
Stream output.
std::string getString(const std::string &key) const
Get string value.
JProperties(const int debug=0)
Constructor.
bool getEndMarker() const
Get end marker.
virtual bool is_properties() const
Get properties type.
JPropertiesElement(T &value)
Constructor.
JPropertiesElement & operator=(T &value)
Assignment operator.
JProperties & join(const JProperties &properties)
Join properties objects.
Template class for I/O of properties element.
std::istream & read(std::istream &in)
Read from input stream.
virtual std::istream & read(std::istream &in)
Stream input.
const char getDefaultDivision() const
Get default division character.
virtual bool is_properties() const
Get properties type.
JFileReader & operator=(const std::string &file_name)
Assignment operator.
bool compareObjects(const T &first, const T &second, JBool< true >)
Comparison of comparable objects.
General purpose messaging.
T & getValue(const std::string &key)
Get value.
virtual bool equals(const JPropertiesElementInterface &element) const
Equality between property element interfaces.
virtual bool equals(const JPropertiesElementInterface &element) const
Equality between property element interfaces.
const char getDefaultEndOfLine() const
Get default end of line character.
void setValue(const std::string &key, const T &value)
Set value.
bool fail(std::istream &in)
Check for stream state.
virtual std::ostream & write(std::ostream &out) const =0
Stream output.
friend std::ostream & operator<<(std::ostream &out, const JProperties::JFileReader &fileReader)
Stream output.
std::string toString() const
Convert to string.
virtual std::ostream & write(std::ostream &out, const char *prefix, const char postfix) const
Stream output.
The property value class.
virtual std::ostream & write(std::ostream &out, const char *prefix, const char postfix) const
Stream output.
Interface for ASCII output using standard streams.
JPropertiesTemplateElement(JProperties::JFileReader &value)
Constructor.
friend std::ostream & operator<<(std::ostream &out, const JProperties &properties)
Stream output.
std::ostream & write(std::ostream &out, const std::string &format)
Write to output stream according given format.
T toValue() const
Convert to template type.
virtual JClass_t * get() const
Get pointer.
virtual std::ostream & write(std::ostream &out, const char *prefix, const char postfix) const =0
Stream output.
bool isSeparator(const char c) const
Test for separator character.
std::ostream & write(std::ostream &out, T __begin, T __end)
Write to output stream according given format.
const char getSeparator() const
Get separator.
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).
bool isDivision(const char c) const
Test for division character.
JPropertiesElement()
Default constructor.
std::istream & read(std::istream &in, T __begin, T __end)
Read from input stream according given format.
void read(const std::string &file_name)
Read properties from file.
Interface for I/O of properties element.
JProperties::JFileReader & object
virtual void reset()
Reset pointer.
Interface for ASCII output with prefix and postfix using standard streams.
virtual std::istream & read(std::istream &in)
Stream input.
virtual std::ostream & write(std::ostream &out, const char *prefix, const char postfix) const
Stream output.
Auxiliary class to define value, reference and pointer types for given data type and category...
virtual std::istream & read(std::istream &in)
Stream input.
#define DEBUG(A)
Message macros.
Auxiliary class for handling debug parameter within a class.
std::ostream & writeObject(std::ostream &out, const T &object)
Stream output of object.