Go to the documentation of this file. 1 #ifndef __JEEP__JPROPERTIES__
2 #define __JEEP__JPROPERTIES__
32 namespace 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)
144 if (!buffer.empty()) {
160 virtual std::ostream&
write(std::ostream& out,
162 const char postfix)
const
174 virtual std::ostream&
write(std::ostream& out)
const
232 virtual std::istream&
read(std::istream& in)
244 virtual std::ostream&
write(std::ostream& out)
const
258 virtual std::ostream&
write(std::ostream& out,
260 const char postfix)
const
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
438 return getValue<T>();
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);
537 properties(__properties)
564 std::string file_name;
568 fileReader.
read(file_name);
593 void read(
const std::string& file_name)
595 std::ifstream in(file_name.c_str());
635 const int debug = 0) :
650 void put(
const std::string& key, T&
object)
665 insert(properties.begin(), properties.end());
683 DEBUG(
"Processing key: " << equation.
getKey() <<
' ' << (p != end()) << endl);
687 istringstream is(equation.
getValue());
691 if (p->second->is_properties()) {
697 ERROR(
"JProperties::read(): no properties object after division <" << equation.
getKey() <<
">" << endl);
705 catch(
const exception& error) {
706 ERROR(
"JProperties::read(): read error at key <" << equation.
getKey() <<
"> " << error.what() << endl);
711 ERROR(
"JProperties::read(): illegal character following key <" << equation.
getKey() <<
"> " << equation.
getSeparator() << endl);
714 if (p->second.getEndMarker()) {
720 ERROR(
"JProperties::read(): error reading data for key <" << equation.
getKey() <<
"> " << equation.
getValue() << endl);
725 WARNING(
"JProperties::read(): unknown key <" << equation.
getKey() <<
">" << endl);
738 bool read(
const std::string& buffer)
740 std::istringstream in(buffer);
760 std::istream&
read(std::istream& in)
766 for (
JEquation equation; in >> equation &&
read(equation); ) {}
782 std::istream&
read(std::istream& in,
const std::string& format)
786 istringstream is(format);
790 for (
string key; is >> key; ) {
791 buffer.push_back(key);
794 return read(in, buffer.begin(), buffer.end());
810 std::istream&
read(std::istream& in, T __begin, T __end)
814 for (T i = __begin; i != __end; ++i) {
824 WARNING(
"JProperties::read(): unknown key <" << *i <<
">" << endl);
845 std::ostream&
write(std::ostream& out)
const
849 for (const_iterator i = begin(); i != end(); ++i) {
853 if (i->second->is_properties()) {
854 c = getDefaultDivision ();
856 c = getDefaultSeparator();
859 i->second->write(out, (i->first + c).c_str(), getDefaultEndOfLine());
878 std::ostream&
write(std::ostream& out,
const std::string& format)
882 istringstream is(format);
886 for (
string key; is >> key; ) {
887 buffer.push_back(key);
890 return write(out, buffer.begin(), buffer.end());
906 std::ostream&
write(std::ostream& out, T __begin, T __end)
910 for (T i = __begin; i != __end; ++i) {
916 out << getDefaultWhiteSpace();
918 p->second->write(out);
922 WARNING(
"JProperties::write(): unknown key <" << *i <<
">" << endl);
941 std::string
sed(
const std::string& format,
942 const std::string& prefix =
"",
943 const std::string& postfix =
"")
947 string buffer = format;
949 for (
iterator i = begin(); i != end(); ++i) {
951 string::size_type ipos = 0;
953 while ((ipos = buffer.find(prefix + i->first + postfix, ipos)) != string::npos) {
957 i->second->write(out);
959 buffer.replace(ipos, prefix.length() + i->first.length() + postfix.length(), out.str());
976 const_iterator i = find(key);
979 return i->second.getValue<T>();
997 return i->second.getValue<T>();
1015 return i->second.setValue<T>(value);
1029 const_iterator i = find(key);
1032 return i->second.toString();
1044 std::ostream&
print(std::ostream& out)
const
1061 return properties.
read(in);
1074 return properties.
write(out);
1105 virtual std::istream&
read(std::istream& in)
1119 virtual std::ostream&
write(std::ostream& out,
1121 const char postfix)
const
1133 virtual std::ostream&
write(std::ostream& out)
const
1180 virtual std::istream&
read(std::istream& in)
1196 virtual std::ostream&
write(std::ostream& out,
1198 const char postfix)
const
1200 using namespace std;
1202 for (JProperties::const_iterator i =
object.begin(); i !=
object.end(); ++i) {
1206 if (i->second->is_properties()) {
1207 c =
object.getDefaultDivision ();
1209 c =
object.getDefaultSeparator();
1212 i->second->write(out, (prefix + i->first + c).c_str(), postfix);
1227 virtual std::ostream&
write(std::ostream& out)
const
1269 const int debug = 1)
1273 properties = T::template getProperties<true>(
object, parameters,
debug);
1299 const int debug = 1)
1303 properties = T::template getProperties<false>(
object, parameters,
debug);
1319 #define gmake_property(A) JProperties::value_type(JProperties::getKey(#A,".>/:"), JEEP::JPropertiesElement(A))
std::ostream & write(std::ostream &out, const std::string &format)
Write to output stream according given format.
virtual std::istream & read(std::istream &in)
Stream input.
Test availability of comparison operators of non-composite data types.
Interface for ASCII output with prefix and postfix using standard streams.
Exception when parsing a value.
bool compareObjects(const T &first, const T &second, JBool< true >)
Comparison of comparable objects.
std::map< std::string, JPropertiesElement > JMap_t
friend std::istream & operator>>(std::istream &in, JProperties::JFileReader &fileReader)
Stream input.
std::ostream & write(std::ostream &out, T __begin, T __end)
Write to output stream according given format.
virtual std::ostream & write(std::ostream &out) const
Stream output.
std::ostream & print(std::ostream &out) const
Print the current parameter values.
virtual JClass_t * get() const
Get pointer.
JProperties & join(const JProperties &properties)
Join properties objects.
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).
friend std::istream & operator>>(std::istream &in, JProperties &properties)
Stream input.
JFileReader(JProperties &__properties)
std::istream & read(std::istream &in, T __begin, T __end)
Read from input stream according given format.
bool getEndMarker() const
Get end marker.
void setValue(const std::string &key, const T &value)
Set value.
bool fail(std::istream &in)
Check for stream state.
Exception for reading of file.
const std::string & getValue() const
Get value.
General puprpose classes and methods.
Auxiliary class to define value, reference and pointer types for given data type and category.
virtual bool is_properties() const
Get properties type.
Exception for opening of file.
The property value class.
virtual std::istream & read(std::istream &in)
Stream input.
JEquationParameters & join(const JEquationParameters &value)
Join equation parameters.
bool read(const JEquation &equation)
Read equation.
Interface for ASCII output using standard streams.
std::string sed(const std::string &format, const std::string &prefix="", const std::string &postfix="")
Stream editing of input format.
JFileReader & operator=(const std::string &file_name)
Assignment operator.
virtual std::ostream & write(std::ostream &out, const char *prefix, const char postfix) const
Stream output.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
virtual std::ostream & write(std::ostream &out) const
Stream output.
T toValue() const
Convert to template type.
JPropertiesElement(T &value)
Constructor.
JPropertiesTemplateElement(const T &value)
Constructor.
JProperties & getProperties(T &object, const JEquationParameters ¶meters=JEquationParameters(), const int debug=1)
Get properties of a given object.
bool read(const std::string &buffer)
Read from input string.
void setEndMarker(const bool marker)
Set end marker.
Template class for I/O of properties element.
General purpose equation class.
std::string getString(const std::string &key) const
Get string value.
std::istream & readObject(std::istream &in, T &object)
Stream input of object.
friend class JPropertiesElement
JPropertiesElement & operator=(T &value)
Assignment operator.
T & getValue(const std::string &key)
Get value.
const T & getValue(const std::string &key) const
Get value.
Facet class to specify parsing of equations in currect locale (see class JLANG::JEquation).
JPropertiesTemplateElement(const JProperties &value)
Constructor.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
std::istream & read(std::istream &in, const std::string &format)
Read from input stream according given format.
const char getSeparator() const
Get separator.
std::ostream & writeObject(std::ostream &out, const T &object)
Stream output of object.
void reset(JCLBInput &data, size_t size)
Reset CLB buffers.
friend std::ostream & operator<<(std::ostream &out, const JProperties::JFileReader &fileReader)
Stream output.
bool equals(const JPropertiesElement &element) const
Equality between property elements.
virtual std::istream & read(std::istream &in)
Stream input.
virtual std::istream & read(std::istream &in)
Stream input.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
Template specialisation of JPropertiesTemplateElement for const data type.
Utility class to parse parameter values.
std::ostream & write(std::ostream &out) const
Write the current parameter values.
JProperties(const int debug=0)
Constructor.
#define DEBUG(A)
Message macros.
JProperties & getProperties(const T &object, const JEquationParameters ¶meters=JEquationParameters(), const int debug=1)
Get properties of a given object.
virtual bool equals(const JPropertiesElementInterface &element) const
Equality between property element interfaces.
JPropertiesTemplateElement(JProperties::JFileReader &value)
Constructor.
virtual bool equals(const JPropertiesElementInterface &element) const
Equality between property element interfaces.
virtual std::ostream & write(std::ostream &out) const =0
Stream output.
JProperties::JFileReader & object
void put(const std::string &key, T &object)
Put object at given key.
JPropertiesElement()
Default constructor.
Auxiliary class to handle input from file.
std::string toString() const
Convert to string.
virtual std::ostream & write(std::ostream &out, const char *prefix, const char postfix) const =0
Stream output.
friend std::ostream & operator<<(std::ostream &out, const JProperties &properties)
Stream output.
virtual std::ostream & write(std::ostream &out) const
Stream output.
T get(const JHead &header)
Get object from header.
virtual std::ostream & write(std::ostream &out, const char *prefix, const char postfix) const
Stream output.
std::istream & read(std::istream &in)
Read from input stream.
const std::string & getKey() const
Get key.
void setValue(const T &value)
Set value of this JPropertiesElement.
virtual bool is_properties() const
Get properties type.
const T & getValue() const
Get value.
virtual std::ostream & write(std::ostream &out, const char *prefix, const char postfix) const
Stream output.
virtual std::ostream & write(std::ostream &out, const char *prefix, const char postfix) const
Stream output.
virtual bool equals(const JPropertiesElementInterface &element) const
Equality between property element interfaces.
JPropertiesTemplateElement(T &value)
Constructor.
virtual std::ostream & write(std::ostream &out) const
Stream output.
JProperties(const JEquationParameters ¶meters, const int debug=0)
Constructor.
Auxiliary class for handling debug parameter within a class.
void read(const std::string &file_name)
Read properties from file.
The template JSharedPointer class can be used to share a pointer to an object.
Interface for I/O of properties element.
virtual bool equals(const JPropertiesElementInterface &element) const
Equality between property element interfaces.