DeviceManager: Initial class with DeviceSpecParser

Hopefully by the end of tonight we should be done with the dev
spec parser.
This commit is contained in:
2025-01-05 14:19:53 -04:00
parent f16d3b24b3
commit 6307d2869e
9 changed files with 128 additions and 2 deletions
+46
View File
@@ -0,0 +1,46 @@
#include <iostream>
#include <fstream>
#include <stdexcept>
#include <string>
#include <vector>
#include <sstream>
#include <utility>
#include <deviceManager/deviceSpecParser.h>
std::vector<std::string> readDeviceFile(const std::string& filename)
{
std::vector<std::string> deviceStrings;
std::cerr <<"Here in readDeviceFile" << std::endl;
std::ifstream file(filename);
std::cerr <<"Here in readDeviceFile after opening ifstream" << std::endl;
if (!file.is_open()) {
throw std::runtime_error("Could not open device file: " + filename);
}
std::string line;
while (std::getline(file, line)) {
if (!line.empty()) {
deviceStrings.push_back(line);
}
}
return deviceStrings;
}
std::vector<std::pair<std::string, std::string>> parseDeviceSpecifiers(
const std::vector<std::string>& deviceStrings)
{
std::vector<std::pair<std::string, std::string>> deviceSpecifiers;
for (const auto& deviceString : deviceStrings) {
auto pos = deviceString.find(':');
if (pos != std::string::npos) {
std::string deviceName = deviceString.substr(0, pos);
std::string deviceSpec = deviceString.substr(pos + 1);
deviceSpecifiers.emplace_back(deviceName, deviceSpec);
} else {
throw std::invalid_argument("Invalid device specifier: " +
deviceString);
}
}
return deviceSpecifiers;
}