#include #include #include #include #include #include #include #include #include #include "deviceSpecp.hh" #include "deviceSpecl.hh" std::string DeviceManager::readDeviceFile(const std::string& filename) { std::ifstream file(filename); if (!file.is_open()) { throw std::runtime_error( std::string(__func__) + ": Couldn't open deviceSpec file: " + filename); } std::string content( (std::istreambuf_iterator(file)), std::istreambuf_iterator()); return content; } void DeviceManager::collateAllDeviceSpecs(void) { OptionParser &options = OptionParser::getOptions(); allDeviceSpecs = options.deviceSpecs; for (const auto& file : options.deviceSpecFiles) { std::string fileContent = readDeviceFile(file); if (!allDeviceSpecs.empty()) { allDeviceSpecs += "||"; } allDeviceSpecs += fileContent; } } void DeviceManager::parseAllDeviceSpecs(void) { std::unique_ptr input( fmemopen((void*)allDeviceSpecs.c_str(), allDeviceSpecs.size(), "r"), &fclose); if (!input) { throw std::runtime_error( std::string(__func__) + ": Failed to fmemopen() a FILE* for " "parsing device specs"); } deviceSpeclin = input.get(); if (deviceSpecpparse()) { throw std::runtime_error( std::string(__func__) + ": Failed to parse device specs. " "Check specs for errors"); } }