summaryrefslogtreecommitdiff
path: root/src
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
parent2ae92dcc97765deb2845dd07a338858aeb375cb3 (diff)
Give Data a loading constructor.
Diffstat (limited to 'src')
-rw-r--r--src/data.cc42
-rw-r--r--src/data.h4
-rw-r--r--src/subtitle_asset.cc16
-rw-r--r--src/subtitle_asset.h4
-rw-r--r--src/wscript3
5 files changed, 53 insertions, 16 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);
+ }
+}
diff --git a/src/data.h b/src/data.h
index d169c5c5..3cece1da 100644
--- a/src/data.h
+++ b/src/data.h
@@ -18,6 +18,8 @@
*/
#include <boost/shared_array.hpp>
+#include <boost/filesystem.hpp>
+#include <stdint.h>
namespace dcp {
@@ -31,6 +33,8 @@ public:
, size (size_)
{}
+ Data (boost::filesystem::path file);
+
boost::shared_array<uint8_t> data;
boost::uintmax_t size;
};
diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc
index 8d492727..367c3455 100644
--- a/src/subtitle_asset.cc
+++ b/src/subtitle_asset.cc
@@ -311,21 +311,7 @@ SubtitleAsset::subtitles_as_xml (xmlpp::Element* root, int time_code_rate, strin
void
SubtitleAsset::add_font_data (string id, boost::filesystem::path file)
{
- boost::uintmax_t size = boost::filesystem::file_size (file);
- FILE* f = fopen_boost (file, "rb");
- if (!f) {
- throw FileError ("could not open font file for reading", file, errno);
- }
-
- shared_array<uint8_t> data (new uint8_t[size]);
- size_t const read = fread (data.get(), 1, size, f);
- fclose (f);
-
- if (read != size) {
- throw FileError ("could not read font file", file, -1);
- }
-
- _fonts[id] = FileData (data, size);
+ _fonts[id] = FileData (file);
}
map<string, Data>
diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h
index cc27f958..31afecb3 100644
--- a/src/subtitle_asset.h
+++ b/src/subtitle_asset.h
@@ -98,6 +98,10 @@ protected:
: Data (data_, size_)
{}
+ FileData (boost::filesystem::path file_)
+ : Data (file_)
+ {}
+
/** .ttf file that this data was last written to */
mutable boost::optional<boost::filesystem::path> file;
};
diff --git a/src/wscript b/src/wscript
index bf28183e..a3f56b82 100644
--- a/src/wscript
+++ b/src/wscript
@@ -8,7 +8,8 @@ def build(bld):
colour_conversion.cc
colour_matrix.cc
cpl.cc
- dcp.cc
+ data.cc
+ dcp.cc
dcp_time.cc
decrypted_kdm.cc
decrypted_kdm_key.cc