MCPcopy Create free account
hub / github.com/OpenHD/OpenHD / opt_read_file

Method opt_read_file

OpenHD/ohd_common/src/openhd_util_filesystem.cpp:140–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

138}
139
140std::optional<std::string> OHDFilesystemUtil::opt_read_file(
141 const std::string &filename, bool log_debug) {
142 if (!exists(filename)) {
143 if (log_debug)
144 openhd::log::get_default()->debug("File [{}] doesn't exist", filename);
145 return std::nullopt;
146 }
147 try {
148 std::ifstream f(filename);
149 std::string str((std::istreambuf_iterator<char>(f)),
150 std::istreambuf_iterator<char>());
151 return str;
152 } catch (std::exception &e) {
153 if (log_debug)
154 openhd::log::get_default()->warn("Cannot read file [{}]", filename);
155 return std::nullopt;
156 }
157}
158
159std::string OHDFilesystemUtil::read_file(const std::string &filename) {
160 const auto content = opt_read_file(filename);

Callers

nothing calls this directly

Calls 1

debugMethod · 0.80

Tested by

no test coverage detected