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:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user