39static bool split(
const std::string& line, std::string& key, std::string& val)
44 const auto keyLen = line.find_first_of(
"\t:");
45 const auto sep = line.find(
':');
47 if (keyLen == std::string::npos || sep == std::string::npos)
52 const auto begVal = line.find_first_not_of(
" :", sep);
54 if (begVal == std::string::npos)
59 key = line.substr(0, keyLen);
60 val = line.substr(begVal);
63 for (
auto iter = key.begin(); iter < key.end(); ++iter)
112void Foam::cpuInfo::parse()
115 std::string line,
key, val;
117 std::ifstream is(
"/proc/cpuinfo");
118 while (is.good() && std::getline(is, line))
120 if (!
split(line, key, val))
125 if (key ==
"processor")
132 else if (key ==
"vendor_id") { vendor_id = val; }
133 else if (key ==
"model_name") { model_name = val; }
134 else if (key ==
"cpu_family") { cpu_family = std::stoi(val); }
135 else if (key ==
"model") { model = std::stoi(val); }
136 else if (key ==
"cpu_MHz") { cpu_MHz = std::stof(val); }
137 else if (key ==
"cpu_cores") { cpu_cores = std::stoi(val); }
138 else if (key ==
"siblings") { siblings = std::stoi(val); }
163 if (!vendor_id.empty())
167 if (!model_name.empty())
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
static bool split(const std::string &line, std::string &key, std::string &val)
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Ostream & writeEntryIfDifferent(const word &key, const T &value1, const T &value2)
Write a keyword/value entry only when the two values differ.
cpuInfo()
Construct and populate with information.
virtual bool write()
Write the output fields.
OBJstream os(runTime.globalPath()/outputName)
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type