From 2ae92dcc97765deb2845dd07a338858aeb375cb3 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 24 Jun 2015 14:13:37 +0100 Subject: No-op: whitespace. --- src/data.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/data.h') diff --git a/src/data.h b/src/data.h index d1f52b3b..d169c5c5 100644 --- a/src/data.h +++ b/src/data.h @@ -20,17 +20,17 @@ #include namespace dcp { - + class Data { public: Data () {} - + Data (boost::shared_array data_, boost::uintmax_t size_) : data (data_) , size (size_) {} - + boost::shared_array data; boost::uintmax_t size; }; -- cgit v1.2.3 From 094117316524f12fc82adbdf721778eed04e66f6 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 24 Jun 2015 14:14:02 +0100 Subject: Give Data a loading constructor. --- src/data.cc | 42 ++++++++++++++++++++++++++++++++++++++++++ src/data.h | 4 ++++ src/subtitle_asset.cc | 16 +--------------- src/subtitle_asset.h | 4 ++++ src/wscript | 3 ++- 5 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 src/data.cc (limited to 'src/data.h') 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 + + 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 + +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 +#include +#include namespace dcp { @@ -31,6 +33,8 @@ public: , size (size_) {} + Data (boost::filesystem::path file); + boost::shared_array 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 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 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 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 -- cgit v1.2.3