summaryrefslogtreecommitdiff
path: root/src/data.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-06-24 14:14:02 +0100
committerCarl Hetherington <cth@carlh.net>2015-06-24 14:14:02 +0100
commit094117316524f12fc82adbdf721778eed04e66f6 (patch)
treeaaa2abd88a2aba64d53022554265f000c93be966 /src/data.cc
parent2ae92dcc97765deb2845dd07a338858aeb375cb3 (diff)
Give Data a loading constructor.
Diffstat (limited to 'src/data.cc')
-rw-r--r--src/data.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/data.cc b/src/data.cc
new file mode 100644
index 00000000..7f390ead
--- /dev/null
+++ b/src/data.cc
@@ -0,0 +1,42 @@
+/*
+ Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "data.h"
+#include "util.h"
+#include "exceptions.h"
+#include <cstdio>
+
+using namespace dcp;
+
+Data::Data (boost::filesystem::path file)
+{
+ FILE* f = fopen_boost (file, "rb");
+ if (!f) {
+ throw FileError ("could not open file for reading", file, errno);
+ }
+
+ size = boost::filesystem::file_size (file);
+ data.reset (new uint8_t[size]);
+ size_t const read = fread (data.get(), 1, size, f);
+ fclose (f);
+
+ if (read != size) {
+ throw FileError ("could not read file", file, -1);
+ }
+}