2018-09-05 06:49:02 +00:00
|
|
|
#include "Util.h"
|
|
|
|
|
|
|
|
#include <fstream>
|
2018-09-05 15:47:09 +00:00
|
|
|
#include <string>
|
2018-09-05 06:49:02 +00:00
|
|
|
|
2018-09-05 15:47:09 +00:00
|
|
|
#include "Exception.h"
|
|
|
|
|
|
|
|
std::string Util::load_file(const std::string& path)
|
2018-09-05 06:49:02 +00:00
|
|
|
{
|
2018-09-05 15:47:09 +00:00
|
|
|
std::ifstream input_stream;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
input_stream.open(path);
|
|
|
|
}
|
|
|
|
catch (std::ios::failure& e)
|
2018-09-05 06:49:02 +00:00
|
|
|
{
|
2018-09-05 15:47:09 +00:00
|
|
|
throw Exception(std::string("Error Opening File: ") + e.what(), "class Util");
|
|
|
|
}
|
|
|
|
if (input_stream.is_open())
|
|
|
|
{
|
|
|
|
input_stream.seekg(0, std::ios::end);
|
|
|
|
size_t size = input_stream.tellg();
|
|
|
|
std::string buffer(size, ' ');
|
2018-09-05 06:49:02 +00:00
|
|
|
input_stream.seekg(std::ios::beg);
|
2018-09-05 15:47:09 +00:00
|
|
|
input_stream.read(&buffer[0], size);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw Exception("Unable to access file: " + path, "class Util");
|
2018-09-05 06:49:02 +00:00
|
|
|
}
|
|
|
|
}
|