Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
13e27c57
Commit
13e27c57
authored
Nov 12, 2018
by
Micha Mueller
Browse files
SysFS: switch to boost::regex to stay compatible with GCC versions < 4.9
parent
1955eec8
Changes
3
Show whitespace changes
Inline
Side-by-side
Makefile
View file @
13e27c57
...
...
@@ -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
...
...
src/sensors/sysfs/SysfsSensorBase.h
View file @
13e27c57
...
...
@@ -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
;
}
st
d
::
regex
getRegex
()
const
{
return
_regx
;
}
boo
st
::
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
st
d
::
regex
checkSubstitute
(
"s([^
\\\\
]{1})([
\\
S|
\\
s]*)
\\
1([
\\
S|
\\
s]*)
\\
1"
);
st
d
::
smatch
matchResults
;
boo
st
::
regex
checkSubstitute
(
"s([^
\\\\
]{1})([
\\
S|
\\
s]*)
\\
1([
\\
S|
\\
s]*)
\\
1"
);
boo
st
::
smatch
matchResults
;
if
(
regex_match
(
filter
,
matchResults
,
checkSubstitute
))
{
//input has substitute format
setRegex
(
st
d
::
regex
(
matchResults
[
2
].
str
(),
st
d
::
regex_constants
::
extended
));
setRegex
(
boo
st
::
regex
(
matchResults
[
2
].
str
(),
boo
st
::
regex_constants
::
extended
));
setSubstitution
(
matchResults
[
3
].
str
());
}
else
{
//input is only a regex
setRegex
(
st
d
::
regex
(
filter
,
st
d
::
regex_constants
::
extended
));
setRegex
(
boo
st
::
regex
(
filter
,
boo
st
::
regex_constants
::
extended
));
setSubstitution
(
"&"
);
}
}
void
setRegex
(
st
d
::
regex
regx
)
{
_regx
=
regx
;
}
void
setRegex
(
boo
st
::
regex
regx
)
{
_regx
=
regx
;
}
void
setSubstitution
(
const
std
::
string
&
substitution
)
{
_substitution
=
substitution
;
}
protected:
bool
_filter
;
st
d
::
regex
_regx
;
boo
st
::
regex
_regx
;
std
::
string
_substitution
;
};
...
...
src/sensors/sysfs/SysfsSensorGroup.cpp
View file @
13e27c57
...
...
@@ -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
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment