summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2016-08-17 14:30:21 +0100
committerCarl Hetherington <cth@carlh.net>2016-08-17 14:30:21 +0100
commit34f2b95c1638a2cfedf21de5a203d6c0b77abf11 (patch)
treebd78b7dbca7d975a89ef9628f6d4b2fd783a39f1 /src
parent81ed0ebb725a7b5fec00ae209ba8b0d70ebc4ee1 (diff)
Use an optional<> where there should be one.
Diffstat (limited to 'src')
-rw-r--r--src/asset.cc16
-rw-r--r--src/asset.h8
-rw-r--r--src/interop_subtitle_asset.cc4
-rw-r--r--src/mono_picture_asset.cc10
-rw-r--r--src/mono_picture_asset_reader.cc6
-rw-r--r--src/picture_asset_writer_common.cc4
-rw-r--r--src/reel_asset.cc4
-rw-r--r--src/smpte_subtitle_asset.cc8
-rw-r--r--src/sound_asset.cc9
-rw-r--r--src/sound_asset_reader.cc6
-rw-r--r--src/stereo_picture_asset.cc10
-rw-r--r--src/stereo_picture_asset_reader.cc6
12 files changed, 52 insertions, 39 deletions
diff --git a/src/asset.cc b/src/asset.cc
index 1a3bd363..7d3a9813 100644
--- a/src/asset.cc
+++ b/src/asset.cc
@@ -78,11 +78,11 @@ Asset::Asset (string id, boost::filesystem::path file)
void
Asset::write_to_pkl (xmlpp::Node* node, boost::filesystem::path root, Standard standard) const
{
- DCP_ASSERT (!_file.empty ());
+ DCP_ASSERT (_file);
optional<boost::filesystem::path> path = relative_to_root (
boost::filesystem::canonical (root),
- boost::filesystem::canonical (_file)
+ boost::filesystem::canonical (_file.get())
);
if (!path) {
@@ -96,18 +96,18 @@ Asset::write_to_pkl (xmlpp::Node* node, boost::filesystem::path root, Standard s
asset->add_child("Id")->add_child_text ("urn:uuid:" + _id);
asset->add_child("AnnotationText")->add_child_text (_id);
asset->add_child("Hash")->add_child_text (hash ());
- asset->add_child("Size")->add_child_text (raw_convert<string> (boost::filesystem::file_size (_file)));
+ asset->add_child("Size")->add_child_text (raw_convert<string> (boost::filesystem::file_size (_file.get())));
asset->add_child("Type")->add_child_text (pkl_type (standard));
}
void
Asset::write_to_assetmap (xmlpp::Node* node, boost::filesystem::path root) const
{
- DCP_ASSERT (!_file.empty ());
+ DCP_ASSERT (_file);
optional<boost::filesystem::path> path = relative_to_root (
boost::filesystem::canonical (root),
- boost::filesystem::canonical (_file)
+ boost::filesystem::canonical (_file.get())
);
if (!path) {
@@ -125,16 +125,16 @@ Asset::write_to_assetmap (xmlpp::Node* node, boost::filesystem::path root) const
chunk->add_child("Path")->add_child_text (path.get().generic_string());
chunk->add_child("VolumeIndex")->add_child_text ("1");
chunk->add_child("Offset")->add_child_text ("0");
- chunk->add_child("Length")->add_child_text (raw_convert<string> (boost::filesystem::file_size (_file)));
+ chunk->add_child("Length")->add_child_text (raw_convert<string> (boost::filesystem::file_size (_file.get())));
}
string
Asset::hash (function<void (float)> progress) const
{
- DCP_ASSERT (!_file.empty ());
+ DCP_ASSERT (_file);
if (!_hash) {
- _hash = make_digest (_file, progress);
+ _hash = make_digest (_file.get(), progress);
}
return _hash.get();
diff --git a/src/asset.h b/src/asset.h
index 214cc227..143c6296 100644
--- a/src/asset.h
+++ b/src/asset.h
@@ -83,8 +83,8 @@ public:
*/
void write_to_pkl (xmlpp::Node* node, boost::filesystem::path root, Standard standard) const;
- /** @return the most recent disk file used to read or write this asset; may be empty */
- boost::filesystem::path file () const {
+ /** @return the most recent disk file used to read or write this asset, if there is one */
+ boost::optional<boost::filesystem::path> file () const {
return _file;
}
@@ -97,8 +97,8 @@ public:
protected:
- /** The most recent disk file used to read or write this asset; may be empty */
- mutable boost::filesystem::path _file;
+ /** The most recent disk file used to read or write this asset */
+ mutable boost::optional<boost::filesystem::path> _file;
private:
friend struct ::asset_test;
diff --git a/src/interop_subtitle_asset.cc b/src/interop_subtitle_asset.cc
index b0b94995..24b4cd00 100644
--- a/src/interop_subtitle_asset.cc
+++ b/src/interop_subtitle_asset.cc
@@ -204,8 +204,8 @@ InteropSubtitleAsset::resolve_fonts (list<shared_ptr<Asset> > assets)
}
BOOST_FOREACH (shared_ptr<InteropLoadFontNode> j, _load_font_nodes) {
- if (j->uri == font->file().leaf().string ()) {
- _fonts.push_back (Font (j->id, i->id(), font->file ()));
+ if (font->file() && j->uri == font->file()->leaf().string ()) {
+ _fonts.push_back (Font (j->id, i->id(), font->file().get()));
}
}
}
diff --git a/src/mono_picture_asset.cc b/src/mono_picture_asset.cc
index 194d3997..a6643bc0 100644
--- a/src/mono_picture_asset.cc
+++ b/src/mono_picture_asset.cc
@@ -93,15 +93,17 @@ MonoPictureAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt, No
}
ASDCP::JP2K::MXFReader reader_A;
- Kumu::Result_t r = reader_A.OpenRead (_file.string().c_str());
+ DCP_ASSERT (_file);
+ Kumu::Result_t r = reader_A.OpenRead (_file->string().c_str());
if (ASDCP_FAILURE (r)) {
- boost::throw_exception (MXFFileError ("could not open MXF file for reading", _file.string(), r));
+ boost::throw_exception (MXFFileError ("could not open MXF file for reading", _file->string(), r));
}
ASDCP::JP2K::MXFReader reader_B;
- r = reader_B.OpenRead (other->file().string().c_str());
+ DCP_ASSERT (other->file ());
+ r = reader_B.OpenRead (other->file()->string().c_str());
if (ASDCP_FAILURE (r)) {
- boost::throw_exception (MXFFileError ("could not open MXF file for reading", other->file().string(), r));
+ boost::throw_exception (MXFFileError ("could not open MXF file for reading", other->file()->string(), r));
}
ASDCP::JP2K::PictureDescriptor desc_A;
diff --git a/src/mono_picture_asset_reader.cc b/src/mono_picture_asset_reader.cc
index a732e020..f11ec7f4 100644
--- a/src/mono_picture_asset_reader.cc
+++ b/src/mono_picture_asset_reader.cc
@@ -35,6 +35,7 @@
#include "mono_picture_asset.h"
#include "mono_picture_frame.h"
#include "exceptions.h"
+#include "dcp_assert.h"
#include <asdcp/AS_DCP.h>
using namespace dcp;
@@ -44,10 +45,11 @@ MonoPictureAssetReader::MonoPictureAssetReader (MonoPictureAsset const * asset)
: AssetReader (asset)
{
_reader = new ASDCP::JP2K::MXFReader ();
- Kumu::Result_t const r = _reader->OpenRead (asset->file().string().c_str());
+ DCP_ASSERT (asset->file ());
+ Kumu::Result_t const r = _reader->OpenRead (asset->file()->string().c_str());
if (ASDCP_FAILURE (r)) {
delete _reader;
- boost::throw_exception (FileError ("could not open MXF file for reading", asset->file(), r));
+ boost::throw_exception (FileError ("could not open MXF file for reading", asset->file().get(), r));
}
}
diff --git a/src/picture_asset_writer_common.cc b/src/picture_asset_writer_common.cc
index 7239cf87..a0e66bea 100644
--- a/src/picture_asset_writer_common.cc
+++ b/src/picture_asset_writer_common.cc
@@ -67,7 +67,7 @@ void dcp::start (PictureAssetWriter* writer, shared_ptr<P> state, Standard stand
asset->fill_writer_info (&state->writer_info, asset->id(), standard);
Kumu::Result_t r = state->mxf_writer.OpenWrite (
- asset->file().string().c_str(),
+ asset->file()->string().c_str(),
state->writer_info,
state->picture_descriptor,
16384,
@@ -75,7 +75,7 @@ void dcp::start (PictureAssetWriter* writer, shared_ptr<P> state, Standard stand
);
if (ASDCP_FAILURE (r)) {
- boost::throw_exception (MXFFileError ("could not open MXF file for writing", asset->file().string(), r));
+ boost::throw_exception (MXFFileError ("could not open MXF file for writing", asset->file()->string(), r));
}
writer->_started = true;
diff --git a/src/reel_asset.cc b/src/reel_asset.cc
index 98387653..60c3242c 100644
--- a/src/reel_asset.cc
+++ b/src/reel_asset.cc
@@ -74,7 +74,9 @@ ReelAsset::ReelAsset (shared_ptr<Asset> asset, Fraction edit_rate, int64_t intri
, _hash (asset->hash ())
{
/* default _annotation_text to the leaf name of our file */
- _annotation_text = asset->file().leaf().string ();
+ if (asset->file ()) {
+ _annotation_text = asset->file()->leaf().string ();
+ }
}
ReelAsset::ReelAsset (shared_ptr<const cxml::Node> node)
diff --git a/src/smpte_subtitle_asset.cc b/src/smpte_subtitle_asset.cc
index 239fff74..c58162b3 100644
--- a/src/smpte_subtitle_asset.cc
+++ b/src/smpte_subtitle_asset.cc
@@ -80,7 +80,7 @@ SMPTESubtitleAsset::SMPTESubtitleAsset (boost::filesystem::path file)
shared_ptr<cxml::Document> xml (new cxml::Document ("SubtitleReel"));
shared_ptr<ASDCP::TimedText::MXFReader> reader (new ASDCP::TimedText::MXFReader ());
- Kumu::Result_t r = reader->OpenRead (_file.string().c_str ());
+ Kumu::Result_t r = reader->OpenRead (_file->string().c_str ());
if (!ASDCP_FAILURE (r)) {
/* MXF-wrapped */
ASDCP::WriterInfo info;
@@ -201,7 +201,7 @@ SMPTESubtitleAsset::set_key (Key key)
{
MXF::set_key (key);
- if (!_key_id || _file.empty()) {
+ if (!_key_id || !_file) {
/* Either we don't have any data to read, or it wasn't
encrypted, so we don't need to do anything else.
*/
@@ -211,11 +211,11 @@ SMPTESubtitleAsset::set_key (Key key)
/* Our data was encrypted; now we can decrypt it */
shared_ptr<ASDCP::TimedText::MXFReader> reader (new ASDCP::TimedText::MXFReader ());
- Kumu::Result_t r = reader->OpenRead (_file.string().c_str ());
+ Kumu::Result_t r = reader->OpenRead (_file->string().c_str ());
if (ASDCP_FAILURE (r)) {
boost::throw_exception (
DCPReadError (
- String::compose ("Could not read encrypted subtitle MXF (%1)", _file, static_cast<int> (r))
+ String::compose ("Could not read encrypted subtitle MXF (%1)", static_cast<int> (r))
)
);
}
diff --git a/src/sound_asset.cc b/src/sound_asset.cc
index e3adff45..11fd4b2f 100644
--- a/src/sound_asset.cc
+++ b/src/sound_asset.cc
@@ -97,15 +97,16 @@ bool
SoundAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt, NoteHandler note) const
{
ASDCP::PCM::MXFReader reader_A;
- Kumu::Result_t r = reader_A.OpenRead (file().string().c_str());
+ DCP_ASSERT (file ());
+ Kumu::Result_t r = reader_A.OpenRead (file()->string().c_str());
if (ASDCP_FAILURE (r)) {
- boost::throw_exception (MXFFileError ("could not open MXF file for reading", file().string(), r));
+ boost::throw_exception (MXFFileError ("could not open MXF file for reading", file()->string(), r));
}
ASDCP::PCM::MXFReader reader_B;
- r = reader_B.OpenRead (other->file().string().c_str());
+ r = reader_B.OpenRead (other->file()->string().c_str());
if (ASDCP_FAILURE (r)) {
- boost::throw_exception (MXFFileError ("could not open MXF file for reading", file().string(), r));
+ boost::throw_exception (MXFFileError ("could not open MXF file for reading", other->file()->string(), r));
}
ASDCP::PCM::AudioDescriptor desc_A;
diff --git a/src/sound_asset_reader.cc b/src/sound_asset_reader.cc
index b656abd5..78c0abe1 100644
--- a/src/sound_asset_reader.cc
+++ b/src/sound_asset_reader.cc
@@ -35,6 +35,7 @@
#include "sound_asset.h"
#include "sound_frame.h"
#include "exceptions.h"
+#include "dcp_assert.h"
#include <asdcp/AS_DCP.h>
using boost::shared_ptr;
@@ -44,10 +45,11 @@ SoundAssetReader::SoundAssetReader (SoundAsset const * asset)
: AssetReader (asset)
{
_reader = new ASDCP::PCM::MXFReader ();
- Kumu::Result_t const r = _reader->OpenRead (asset->file().string().c_str());
+ DCP_ASSERT (asset->file ());
+ Kumu::Result_t const r = _reader->OpenRead (asset->file()->string().c_str());
if (ASDCP_FAILURE (r)) {
delete _reader;
- boost::throw_exception (FileError ("could not open MXF file for reading", asset->file(), r));
+ boost::throw_exception (FileError ("could not open MXF file for reading", asset->file().get(), r));
}
}
diff --git a/src/stereo_picture_asset.cc b/src/stereo_picture_asset.cc
index cc197546..9a21b72b 100644
--- a/src/stereo_picture_asset.cc
+++ b/src/stereo_picture_asset.cc
@@ -93,15 +93,17 @@ bool
StereoPictureAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt, NoteHandler note) const
{
ASDCP::JP2K::MXFSReader reader_A;
- Kumu::Result_t r = reader_A.OpenRead (file().string().c_str());
+ DCP_ASSERT (file ());
+ Kumu::Result_t r = reader_A.OpenRead (file()->string().c_str());
if (ASDCP_FAILURE (r)) {
- boost::throw_exception (MXFFileError ("could not open MXF file for reading", file().string(), r));
+ boost::throw_exception (MXFFileError ("could not open MXF file for reading", file()->string(), r));
}
ASDCP::JP2K::MXFSReader reader_B;
- r = reader_B.OpenRead (other->file().string().c_str());
+ DCP_ASSERT (other->file ());
+ r = reader_B.OpenRead (other->file()->string().c_str());
if (ASDCP_FAILURE (r)) {
- boost::throw_exception (MXFFileError ("could not open MXF file for reading", file().string(), r));
+ boost::throw_exception (MXFFileError ("could not open MXF file for reading", other->file()->string(), r));
}
ASDCP::JP2K::PictureDescriptor desc_A;
diff --git a/src/stereo_picture_asset_reader.cc b/src/stereo_picture_asset_reader.cc
index 00f4e660..7348dfa9 100644
--- a/src/stereo_picture_asset_reader.cc
+++ b/src/stereo_picture_asset_reader.cc
@@ -35,6 +35,7 @@
#include "stereo_picture_asset.h"
#include "stereo_picture_frame.h"
#include "exceptions.h"
+#include "dcp_assert.h"
#include <asdcp/AS_DCP.h>
using namespace dcp;
@@ -44,10 +45,11 @@ StereoPictureAssetReader::StereoPictureAssetReader (StereoPictureAsset const * a
: AssetReader (asset)
{
_reader = new ASDCP::JP2K::MXFSReader ();
- Kumu::Result_t const r = _reader->OpenRead (asset->file().string().c_str());
+ DCP_ASSERT (asset->file ());
+ Kumu::Result_t const r = _reader->OpenRead (asset->file()->string().c_str());
if (ASDCP_FAILURE (r)) {
delete _reader;
- boost::throw_exception (FileError ("could not open MXF file for reading", asset->file(), r));
+ boost::throw_exception (FileError ("could not open MXF file for reading", asset->file().get(), r));
}
}