129dbfa6dSBrad Bishop /** 229dbfa6dSBrad Bishop * Copyright © 2016 IBM Corporation 329dbfa6dSBrad Bishop * 429dbfa6dSBrad Bishop * Licensed under the Apache License, Version 2.0 (the "License"); 529dbfa6dSBrad Bishop * you may not use this file except in compliance with the License. 629dbfa6dSBrad Bishop * You may obtain a copy of the License at 729dbfa6dSBrad Bishop * 829dbfa6dSBrad Bishop * http://www.apache.org/licenses/LICENSE-2.0 929dbfa6dSBrad Bishop * 1029dbfa6dSBrad Bishop * Unless required by applicable law or agreed to in writing, software 1129dbfa6dSBrad Bishop * distributed under the License is distributed on an "AS IS" BASIS, 1229dbfa6dSBrad Bishop * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1329dbfa6dSBrad Bishop * See the License for the specific language governing permissions and 1429dbfa6dSBrad Bishop * limitations under the License. 1529dbfa6dSBrad Bishop */ 166292aeedSMatthew Barth #include <regex> 176292aeedSMatthew Barth #include <iostream> 186292aeedSMatthew Barth #include "sensorset.hpp" 196292aeedSMatthew Barth #include "directory.hpp" 206292aeedSMatthew Barth 216292aeedSMatthew Barth // TODO: Issue#2 - STL regex generates really bloated code. Use POSIX regex 226292aeedSMatthew Barth // interfaces instead. 236292aeedSMatthew Barth static const std::regex sensors_regex = 246292aeedSMatthew Barth std::regex("^(fan|in|temp)([0-9]+)_([a-z]*)", std::regex::extended); 256292aeedSMatthew Barth static const auto sensor_regex_match_count = 4; 266292aeedSMatthew Barth 276292aeedSMatthew Barth SensorSet::SensorSet(const std::string& path) 286292aeedSMatthew Barth { 296292aeedSMatthew Barth Directory d(path); 306292aeedSMatthew Barth std::string file; 316292aeedSMatthew Barth 326292aeedSMatthew Barth while (d.next(file)) 336292aeedSMatthew Barth { 346292aeedSMatthew Barth std::smatch match; 356292aeedSMatthew Barth std::regex_search(file, match, sensors_regex); 366292aeedSMatthew Barth 376bb97a97SBrad Bishop if (match.size() != sensor_regex_match_count) 386bb97a97SBrad Bishop { 396bb97a97SBrad Bishop continue; 406bb97a97SBrad Bishop } 416292aeedSMatthew Barth 426292aeedSMatthew Barth container[make_pair(match[1], match[2])].emplace(match[3]); 436292aeedSMatthew Barth } 446292aeedSMatthew Barth } 45*03476f11SBrad Bishop 46*03476f11SBrad Bishop // vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 47