diff options
Diffstat (limited to 'src/main/util')
| -rw-r--r-- | src/main/util/util.cpp | 23 | ||||
| -rw-r--r-- | src/main/util/util.h | 18 |
2 files changed, 41 insertions, 0 deletions
diff --git a/src/main/util/util.cpp b/src/main/util/util.cpp new file mode 100644 index 0000000..46038aa --- /dev/null +++ b/src/main/util/util.cpp @@ -0,0 +1,23 @@ +// +// Created by thecharlesblake on 11/13/17. +// + +#include <fstream> +#include <sstream> + +#include "util.h" + +using namespace std; +using namespace boost; + +const optional<string> util::read_file(const string& filename) { + ifstream ifstr(filename); + stringstream buf; + buf << ifstr.rdbuf(); + + if (ifstr.fail()) { + return none; + } else { + return buf.str(); + } +} diff --git a/src/main/util/util.h b/src/main/util/util.h new file mode 100644 index 0000000..1721daa --- /dev/null +++ b/src/main/util/util.h @@ -0,0 +1,18 @@ +// +// Created by thecharlesblake on 11/13/17. +// + +#ifndef SOLVITAIRE_UTIL_H +#define SOLVITAIRE_UTIL_H + +#include <string> + +#include <boost/optional.hpp> + +class util { +public: + static const boost::optional<std::string> read_file(const std::string&); +}; + + +#endif //SOLVITAIRE_UTIL_H |
