Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 1 | #include <regex> |
| 2 | #include <iostream> |
Matthew Barth | 6292aee | 2016-10-06 10:15:48 -0500 | [diff] [blame] | 3 | #include "sensorset.hpp" |
| 4 | #include "directory.hpp" |
Patrick Williams | 3667cf3 | 2015-10-20 22:39:11 -0500 | [diff] [blame] | 5 | |
| 6 | // TODO: Issue#2 - STL regex generates really bloated code. Use POSIX regex |
| 7 | // interfaces instead. |
| 8 | static const std::regex sensors_regex = |
| 9 | std::regex("^(fan|in|temp)([0-9]+)_([a-z]*)", std::regex::extended); |
| 10 | static const auto sensor_regex_match_count = 4; |
| 11 | |
| 12 | SensorSet::SensorSet(const std::string& path) |
| 13 | { |
| 14 | Directory d(path); |
| 15 | std::string file; |
| 16 | |
| 17 | while(d.next(file)) |
| 18 | { |
| 19 | std::smatch match; |
| 20 | std::regex_search(file, match, sensors_regex); |
| 21 | |
| 22 | if (match.size() != sensor_regex_match_count) continue; |
| 23 | |
| 24 | container[make_pair(match[1],match[2])].emplace(match[3]); |
| 25 | } |
| 26 | } |