Commit 13e27c57 authored by Micha Mueller's avatar Micha Mueller
Browse files

SysFS: switch to boost::regex to stay compatible with GCC versions < 4.9

parent 1955eec8
......@@ -76,7 +76,7 @@ src/sensors/%.o: CXXFLAGS+= $(PLUGINFLAGS) -I$(DCDBDEPSPATH)/bacnet-stack-$(BACN
#src/sensors/*/%.o: %.cpp
libdcdbplugin_sysfs.$(LIBEXT): src/sensors/sysfs/SysfsSensorGroup.o src/sensors/sysfs/SysfsConfigurator.o
$(CXX) $(LIBFLAGS)$@ -o $@ $^ -L$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system
$(CXX) $(LIBFLAGS)$@ -o $@ $^ -L$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system -lboost_regex
libdcdbplugin_perfevent.$(LIBEXT): src/sensors/perfevent/PerfSensorGroup.o src/sensors/perfevent/PerfeventConfigurator.o
$(CXX) $(LIBFLAGS)$@ -o $@ $^ -L$(DCDBDEPLOYPATH)/lib/ -lboost_log -lboost_system
......
......@@ -10,7 +10,7 @@
#include "../../includes/SensorBase.h"
#include <regex>
#include <boost/regex.hpp>
class SysfsSensorBase : public SensorBase {
public:
......@@ -24,7 +24,7 @@ public:
virtual ~SysfsSensorBase() {}
bool hasFilter() const { return _filter; }
std::regex getRegex() const { return _regx; }
boost::regex getRegex() const { return _regx; }
const std::string& getSubstitution() const { return _substitution; }
void setFilter(bool filter) { _filter = filter; }
......@@ -32,25 +32,25 @@ public:
setFilter(true);
//check if input has sed format of "s/.../.../" for substitution
std::regex checkSubstitute("s([^\\\\]{1})([\\S|\\s]*)\\1([\\S|\\s]*)\\1");
std::smatch matchResults;
boost::regex checkSubstitute("s([^\\\\]{1})([\\S|\\s]*)\\1([\\S|\\s]*)\\1");
boost::smatch matchResults;
if(regex_match(filter, matchResults, checkSubstitute)) {
//input has substitute format
setRegex(std::regex(matchResults[2].str(), std::regex_constants::extended));
setRegex(boost::regex(matchResults[2].str(), boost::regex_constants::extended));
setSubstitution(matchResults[3].str());
} else {
//input is only a regex
setRegex(std::regex(filter, std::regex_constants::extended));
setRegex(boost::regex(filter, boost::regex_constants::extended));
setSubstitution("&");
}
}
void setRegex(std::regex regx) { _regx = regx; }
void setRegex(boost::regex regx) { _regx = regx; }
void setSubstitution(const std::string& substitution) { _substitution = substitution; }
protected:
bool _filter;
std::regex _regx;
boost::regex _regx;
std::string _substitution;
};
......
......@@ -7,6 +7,7 @@
#include "timestamp.h"
#include <functional>
#include <cstring>
#include "SysfsSensorGroup.h"
using namespace std;
......@@ -70,7 +71,13 @@ void SysfsSensorGroup::read() {
//substitution must have sed format
//if no substitution is defined the whole regex-match is copied as is.
//parts which do not match are not copied --> filter
reading.value = stoll(regex_replace(buf, s->getRegex(), s->getSubstitution(), regex_constants::format_sed | regex_constants::format_no_copy));
//reading.value = stoll(regex_replace(buf, s->getRegex(), s->getSubstitution(), boost::regex_constants::format_sed | boost::regex_constants::format_no_copy));
//there is no 1:1 match for the std::regex_replace function used previously, but the code below should have the same outcome
std::string input(buf);
std::string result;
boost::regex_replace(std::back_inserter(result), input.begin(), input.end(), s->getRegex(), s->getSubstitution().c_str(), boost::regex_constants::format_sed | boost::regex_constants::format_no_copy);
reading.value = stoll(result);
} else {
reading.value = stoll(buf);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment