SysfsSensorBase.h 1.48 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/*
 * SysfsSensorBase.h
 *
 *  Created on: 13.08.2018
 *      Author: Micha Mueller
 */

#ifndef SYSFS_SYSFSSENSORBASE_H_
#define SYSFS_SYSFSSENSORBASE_H_

11
#include "../../includes/SensorBase.h"
12

13
#include <boost/regex.hpp>
14

15
class SysfsSensorBase : public SensorBase {
16
17
18
19
20
21
22
23
24
25
26
public:
	SysfsSensorBase(const std::string& name) :
		SensorBase(name),
		_filter(false),
		_substitution("") {
		//_regx = "";
	}

	virtual ~SysfsSensorBase() {}

	bool 				hasFilter()	const { return _filter; }
27
	boost::regex		getRegex()	const { return _regx;	}
28
29
30
	const std::string&	getSubstitution()	const { return _substitution; }

	void setFilter(bool filter)				{ _filter = filter; }
31
32
33
34
	void setFilter(const std::string& filter) {
		setFilter(true);

		//check if input has sed format of "s/.../.../" for substitution
35
36
		boost::regex checkSubstitute("s([^\\\\]{1})([\\S|\\s]*)\\1([\\S|\\s]*)\\1");
		boost::smatch matchResults;
37
38
39

		if(regex_match(filter, matchResults, checkSubstitute)) {
			//input has substitute format
40
			setRegex(boost::regex(matchResults[2].str(), boost::regex_constants::extended));
41
42
43
			setSubstitution(matchResults[3].str());
		} else {
			//input is only a regex
44
			setRegex(boost::regex(filter, boost::regex_constants::extended));
45
46
47
			setSubstitution("&");
		}
	}
48
	void setRegex(boost::regex regx)			{ _regx = regx; }
49
50
51
52
	void setSubstitution(const std::string& substitution)	{ _substitution = substitution; }

protected:
	bool _filter;
53
	boost::regex _regx;
54
55
56
57
	std::string _substitution;
};

#endif /* SYSFS_SYSFSSENSORBASE_H_ */