xref: /openbmc/phosphor-hwmon/sensorset.cpp (revision 6292aeed)
1 #include <regex>
2 #include <iostream>
3 #include "sensorset.hpp"
4 #include "directory.hpp"
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 }
27