Use an optional<> where there should be one.
authorCarl Hetherington <cth@carlh.net>
Wed, 17 Aug 2016 13:30:21 +0000 (14:30 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 17 Aug 2016 13:30:21 +0000 (14:30 +0100)
14 files changed:
examples/read_dcp.cc
src/asset.cc
src/asset.h
src/interop_subtitle_asset.cc
src/mono_picture_asset.cc
src/mono_picture_asset_reader.cc
src/picture_asset_writer_common.cc
src/reel_asset.cc
src/smpte_subtitle_asset.cc
src/sound_asset.cc
src/sound_asset_reader.cc
src/stereo_picture_asset.cc
src/stereo_picture_asset_reader.cc
test/rewrite_subs.cc

index 7bd1e2db686ce2133d0cfa755a537bf8e6ed75fb..a851f0bbc8a5d518f6a4c4ecc9569d5016e88bb4 100644 (file)
@@ -72,7 +72,7 @@ main ()
                } else if (boost::dynamic_pointer_cast<dcp::CPL> (*i)) {
                        std::cout << "CPL\n";
                }
-               std::cout << "\t" << (*i)->file().leaf().string() << "\n";
+               std::cout << "\t" << (*i)->file()->leaf().string() << "\n";
        }
 
        /* Take the first CPL */
index 1a3bd363e30e284e8d9b2ef429910246bf2db38d..7d3a9813aa81b8a5be5546a63527eb782d69059f 100644 (file)
@@ -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();
index 214cc227e930385b5b9311727e4866392d01ff80..143c62968bd2fe1349ec4e57088df8a413736f4b 100644 (file)
@@ -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;
index b0b9499540d58f6a62ca4ace99ca7661d05759c7..24b4cd00694c741e1a3d0924c844ef0c410da905 100644 (file)
@@ -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()));
                        }
                }
        }
index 194d3997ce2d3142466476a7643055d280709292..a6643bc053a1095e3158cf3b9f3fbf8b0912e584 100644 (file)
@@ -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;
index a732e020e81f57da1c593a572cd18b047a9f279c..f11ec7f4fb1867d190034adda7a582e669643202 100644 (file)
@@ -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));
        }
 }
 
index 7239cf878fbd3db4efb509ef235aba08fdb0a9e6..a0e66bea508ac7848b01cde80073ab2617627a0f 100644 (file)
@@ -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;
index 983876537fb21d464ccd60e7897e39f0e94da290..60c3242cdd2c5695aadd1614438457711104508b 100644 (file)
@@ -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)
index 239fff74c6184b0967e0b24073ef4eb0020dd86c..c58162b38ec770d6436404f92e8b50cd1020bb71 100644 (file)
@@ -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))
                                )
                        );
        }
index e3adff45d86dca0a432ef40555d8942111877995..11fd4b2fae685ec081f0221fe6ea35c98abcd134 100644 (file)
@@ -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;
index b656abd5bfae4f41728c88fc35ecb07b4590488f..78c0abe1af01c0de9173212bbbfcd55c8bf741d5 100644 (file)
@@ -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));
        }
 }
 
index cc197546e225da4e8c0e6af23f4384a74e73d0f7..9a21b72b152c947a6a767763dc375d9f09083a8c 100644 (file)
@@ -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;
index 00f4e6606c1fecd5999c6320a9de91737ae9e9e0..7348dfa9aff1a9c9a9d696250712b98138a979fd 100644 (file)
@@ -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));
        }
 }
 
index ba27d1902a39a8c6011dff4988e4faf4dc1c46ae..2f3cea545edcb7ad5355617ecd1a0f5647e69332 100644 (file)
@@ -52,7 +52,7 @@ main (int argc, char* argv[])
                        for (list<shared_ptr<Reel> >::iterator j = reels.begin(); j != reels.end(); ++j) {
 
                                if ((*j)->main_subtitle()) {
-                                       (*j)->main_subtitle()->asset()->write ((*j)->main_subtitle()->asset()->file ());
+                                       (*j)->main_subtitle()->asset()->write ((*j)->main_subtitle()->asset()->file().get());
                                }
                        }
                }