// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "fileconfigreader.h" #include #include #include #include #include #include namespace config { template FileConfigReader::FileConfigReader(const vespalib::string & fileName) : _fileName(fileName) { } template std::unique_ptr FileConfigReader::read(const ConfigFormatter & formatter) { ConfigDataBuffer buffer; std::ifstream file(_fileName.c_str()); if (!file.is_open()) throw ConfigReadException("error: unable to read file '%s'", _fileName.c_str()); std::stringstream buf; buf << file.rdbuf(); buffer.setEncodedString(buf.str()); formatter.decode(buffer); return std::make_unique(buffer); } template std::unique_ptr FileConfigReader::read() { StringVector lines; std::ifstream f(_fileName.c_str()); if (f.fail()) throw vespalib::IllegalArgumentException(std::string("Unable to open file ") + _fileName); std::string line; for (std::getline(f, line); f; std::getline(f, line)) { lines.push_back(line); } return std::make_unique(ConfigValue(std::move(lines))); } } // namespace config