Commit 93422309 authored by Ilya Prokhorov's avatar Ilya Prokhorov

Great cleanup

parent d07ca2c7
#include "Data.h"
#include "FSCUtils.h"
#include <sstream>
using namespace FlameSteelCore;
using namespace FlameSteelCore::Utils;
Data::Data() {
size = 0;
data = nullptr;
};
shared_ptr<Data> Data::fromFilePath(shared_ptr<string> filePath) {
auto data = make_shared<Data>();
char *buffer = nullptr;
auto file = fopen (filePath->c_str(), "rb");
if (file != nullptr) {
fseek (file, 0, SEEK_END);
auto length = ftell (file);
data->size = length;
fseek (file, 0, SEEK_SET);
buffer = (char *) malloc (length);
if (buffer)
{
auto readBytes = fread (buffer, 1, length, file);
if (readBytes != length) {
string errorString = "FlameSteelCore::Data read from file:";
stringstream stderrString;
stderrString << stderr << endl;
errorString += stderrString.str();
throwRuntimeException(errorString);
}
}
data->data = buffer;
fclose (file);
}
return data;
};
#ifndef FLAMESTEELCOREDATA
#define FLAMESTEELCOREDATA
#include <string>
#include <memory>
using namespace std;
namespace FlameSteelCore {
class Data {
public:
Data();
static shared_ptr<Data> fromFilePath(shared_ptr<string> filePath);
size_t size;
char *data;
};
};
#endif
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment