bool Config::init(char* filePath) { std::ifstream fileStream (filePath, std::ifstream::in); // Check if file was opened successfully if (!fileStream.is_open()) return false; std::string line; std::cout << "===== Started reading config file =====" << std::endl; // Parse header lines, assuming they could be in a any order while (std::getline(fileStream, line)) { std::cout << line << std::endl; if (line == "") continue; if (line.length() >= 6 && !line.compare(0, 6, "CAMERA")) { unsigned int camParams = 5; for (unsigned int i = 0; i < camParams; ++i) { // Read next line std::getline(fileStream, line); std::istringstream valueStream(line.substr(4)); if (line.length() < 4) { std::cerr << "Incorrect camera description" << std::endl; return false; } if (!line.compare(0, 4, "RESO")) { valueStream >> m_resolution[0] >> m_resolution[1]; std::cout << "RESO " << m_resolution[0] << " " << m_resolution[1] << std::endl; } else if (!line.compare(0, 4, "EYEP")) { valueStream >> m_cameraPosition[0] >> m_cameraPosition[1] >> m_cameraPosition[2]; std::cout << "EYEP " << m_cameraPosition[0] << " " << m_cameraPosition[1] << " " << m_cameraPosition[2] << std::endl; }
bool Config::init(char* filePath) { std::ifstream fileStream (filePath, std::ifstream::in); // Check if file was opened successfully if (!fileStream.is_open()) return false; std::string line; // Parse header lines, assuming they could be in a any order while (std::getline(fileStream, line) && line.length() > 4) { std::cout << "Parsing line: " << line << std::endl; std::istringstream valueStream(line.substr(4)); if (!line.compare(0, 4, "STEP")) { valueStream >> m_step; } else if (!line.compare(0, 4, "XYZC"))
Table readTable(std::istream &in) { std::vector<std::vector<unsigned>> values; while (!in.eof()) { std::string line; std::getline(in, line); std::stringstream valueStream(line); std::vector<unsigned> row; while (valueStream.good()) { unsigned v; valueStream >> v; if (valueStream.fail()) { if (!valueStream.eof()) { throw std::logic_error("non numeric value encountered"); } } else { row.push_back(v); } } if (!row.empty()) { if (!values.empty() && values.front().size() != row.size()) { throw std::logic_error("invalid table shape"); } values.push_back(std::move(row)); } } if (values.empty() || values.size() != values.front().size()) { throw std::logic_error("invalid table shape"); } return Table(values); }