blob: 1edabad477cc14d2e30a7a822e0af456eeeded26 [file] [log] [blame]
Patrick Williams3667cf32015-10-20 22:39:11 -05001#include <regex>
2#include <iostream>
Matthew Barth6292aee2016-10-06 10:15:48 -05003#include "sensorset.hpp"
4#include "directory.hpp"
Patrick Williams3667cf32015-10-20 22:39:11 -05005
6// TODO: Issue#2 - STL regex generates really bloated code. Use POSIX regex
7// interfaces instead.
8static const std::regex sensors_regex =
9 std::regex("^(fan|in|temp)([0-9]+)_([a-z]*)", std::regex::extended);
10static const auto sensor_regex_match_count = 4;
11
12SensorSet::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}