Skip to main content

BasicStringFileReader.ixx File

Basic file-to-string reader implementation. More...

Included Headers

#include <format> #include <fstream> #include <string> #include <stdexcept> #include <helios.engine.util.io.StringFileReader>

Namespaces Index

namespacehelios
namespaceengine
namespaceutil
namespaceio

Classes Index

classBasicStringFileReader

Basic implementation of a string file reader. More...

Description

Basic file-to-string reader implementation.

File Listing

The file content with the documentation metadata removed is:

1
5module;
6
7#include <format>
8#include <fstream>
9#include <string>
10#include <stdexcept>
11
12export module helios.engine.util.io.BasicStringFileReader;
13
14import helios.engine.util.io.StringFileReader;
15
16export namespace helios::engine::util::io {
17
18
23
24
25 public:
29 [[nodiscard]] std::string getContents(const std::string& filename) const override {
30 std::ifstream infile {filename};
31
32 if (!infile) {
33 std::string msg = std::format("Cannot open {0}", filename);
35 throw std::runtime_error(msg);
36 }
37
38 std::string line;
39 std::string fileContents;
40 while (getline(infile, line)) {
41 fileContents += line + "\n";
42 }
43 return fileContents;
44 }
45
49 [[nodiscard]] bool readInto( const std::string& filename, std::string& contents) const noexcept override {
50 std::ifstream infile{ filename };
51
52 if (!infile) {
53 logger_.error(std::format("Cannot open {0}", filename));
54 return false;
55 }
56 std::string line;
57 std::string fileContents;
58
59 while (getline(infile, line)) {
60 fileContents += line + "\n";
61 }
62
64 return true;
65 }
66 };
67
68
69}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.