1 #ifndef __JEEP__JPROPERTIES__
2 #define __JEEP__JPROPERTIES__
32 namespace JPP {
using namespace JEEP; }
45 using JLANG::JComparisonAvailable;
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
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
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);
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);
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)
override
1119 virtual std::ostream&
write(std::ostream& out,
1121 const char postfix)
const
1133 virtual std::ostream&
write(std::ostream& out)
const override
1180 virtual std::istream&
read(std::istream&
in)
override
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 override
1269 const int debug = 1)
1271 using namespace JPP;
1291 #define gmake_property(A) JProperties::value_type(JProperties::getKey(#A,".>/:"), JEEP::JPropertiesElement(A))
Exception for opening of file.
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.
virtual std::ostream & write(std::ostream &out) const override
Stream output.
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::istream & read(std::istream &in) override
Stream input.
virtual std::istream & read(std::istream &in) override
Stream input.
JProperties & getProperties(T &object, const JEquationParameters ¶meters=JEquationParameters(), const int debug=1)
Get properties of a given object.
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 std::ostream & write(std::ostream &out) const override
Stream output.
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.
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
virtual std::istream & read(std::istream &in) override
Stream input.
void setEndMarker(const bool marker)
Set end marker.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
virtual std::istream & read(std::istream &in) override
Stream input.
void setValue(const T &value)
Set value of this JPropertiesElement.
Auxiliary class to handle input from file.
const T & getValue() const
Get value.
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 override
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.
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.
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.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
JPropertiesElement & operator=(T &value)
Assignment operator.
virtual bool equals(const JPropertiesElementInterface &element) const override
Equality between property element interfaces.
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 bool equals(const JPropertiesElementInterface &element) const override
Equality between property element interfaces.
JFileReader & operator=(const std::string &file_name)
Assignment operator.
virtual bool is_properties() const override
Get properties type.
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.
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 std::ostream & write(std::ostream &out, const char *prefix, const char postfix) const =0
Stream output.
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).
JPropertiesElement()
Default constructor.
virtual std::ostream & write(std::ostream &out) const override
Stream output.
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
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
friend class JPropertiesElement
Interface for ASCII output with prefix and postfix using standard streams.
virtual JClass_t * get() const override
Get pointer.
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 bool equals(const JPropertiesElementInterface &element) const override
Equality between property element interfaces.
#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.