Ref does not need to be a template since it's always used for Asset.
authorCarl Hetherington <cth@carlh.net>
Wed, 16 Dec 2015 20:20:47 +0000 (20:20 +0000)
committerCarl Hetherington <cth@carlh.net>
Wed, 16 Dec 2015 20:20:47 +0000 (20:20 +0000)
19 files changed:
src/cpl.cc
src/cpl.h
src/dcp.cc
src/dcp.h
src/interop_subtitle_asset.cc
src/interop_subtitle_asset.h
src/reel.cc
src/reel.h
src/reel_asset.cc
src/reel_asset.h
src/reel_mono_picture_asset.h
src/reel_picture_asset.h
src/reel_sound_asset.h
src/reel_stereo_picture_asset.h
src/reel_subtitle_asset.h
src/ref.h
src/util.h
src/wscript
test/dcp_font_test.cc

index 5f3d0291482861d9d82886669f827d21853fec58..24c8a18af0068939af0161330349a3ed31048fa2 100644 (file)
@@ -236,10 +236,10 @@ CPL::add (DecryptedKDM const & kdm)
 }
 
 void
-CPL::resolve_refs (list<shared_ptr<Object> > objects)
+CPL::resolve_refs (list<shared_ptr<Asset> > assets)
 {
        BOOST_FOREACH (shared_ptr<Reel> i, _reels) {
-               i->resolve_refs (objects);
+               i->resolve_refs (assets);
        }
 }
 
index fe123fd3d3cc5dc38281f89d49cf4da3c8e7918a..d38c0090bd451f999b959ba87d7f8bc0d81e25c3 100644 (file)
--- a/src/cpl.h
+++ b/src/cpl.h
@@ -111,7 +111,7 @@ public:
                boost::shared_ptr<const CertificateChain>
                ) const;
 
-       void resolve_refs (std::list<boost::shared_ptr<Object> >);
+       void resolve_refs (std::list<boost::shared_ptr<Asset> >);
 
 protected:
        /** @return type string for PKLs for this asset */
index 53d5dd39843f27fd0b91a97b6bedcb0a2f118f74..40d288b89781ad79ce24bbc3a3d0a38f64415779 100644 (file)
@@ -181,7 +181,15 @@ DCP::read (bool keep_going, ReadErrors* errors)
        }
 
        BOOST_FOREACH (shared_ptr<CPL> i, cpls ()) {
-               i->resolve_refs (list_of_type<Asset, Object> (other_assets));
+               i->resolve_refs (other_assets);
+       }
+}
+
+void
+DCP::resolve_refs (list<shared_ptr<Asset> > assets)
+{
+       BOOST_FOREACH (shared_ptr<CPL> i, cpls ()) {
+               i->resolve_refs (assets);
        }
 }
 
@@ -429,7 +437,7 @@ DCP::assets () const
        BOOST_FOREACH (shared_ptr<CPL> i, cpls ()) {
                assets.push_back (i);
                BOOST_FOREACH (shared_ptr<const ReelAsset> j, i->reel_assets ()) {
-                       shared_ptr<Asset> o = j->asset_ref().object ();
+                       shared_ptr<Asset> o = j->asset_ref().asset ();
                        assets.push_back (o);
                        /* More Interop special-casing */
                        shared_ptr<InteropSubtitleAsset> sub = dynamic_pointer_cast<InteropSubtitleAsset> (o);
index f852b6eba4bf324364878ee923d72e1a7ed39612..a723cebe988a87881f5b793d1b168961623080ed 100644 (file)
--- a/src/dcp.h
+++ b/src/dcp.h
@@ -97,6 +97,8 @@ public:
                boost::shared_ptr<const CertificateChain> signer = boost::shared_ptr<const CertificateChain> ()
        );
 
+       void resolve_refs (std::list<boost::shared_ptr<Asset> > assets);
+
 private:
 
        /** Write the PKL file.
index 4ba24a19595ef45a14e2fdfec0293e9e7fb5ecb0..a2742b78b2716663f0bb772b4a4d89c6acdb0f71 100644 (file)
@@ -181,9 +181,9 @@ InteropSubtitleAsset::write (boost::filesystem::path p) const
 }
 
 void
-InteropSubtitleAsset::resolve_fonts (list<shared_ptr<Object> > objects)
+InteropSubtitleAsset::resolve_fonts (list<shared_ptr<Asset> > assets)
 {
-       BOOST_FOREACH (shared_ptr<Object> i, objects) {
+       BOOST_FOREACH (shared_ptr<Asset> i, assets) {
                shared_ptr<FontAsset> font = dynamic_pointer_cast<FontAsset> (i);
                if (!font) {
                        continue;
index fe38a0c9916b5eb84676fa87cb5eafe494ca3b2b..399878d4afaf2cb740dd33cb088ea702cde161b9 100644 (file)
@@ -51,7 +51,7 @@ public:
 
        std::string xml_as_string () const;
        void write (boost::filesystem::path path) const;
-       void resolve_fonts (std::list<boost::shared_ptr<Object> > objects);
+       void resolve_fonts (std::list<boost::shared_ptr<Asset> > assets);
        void add_font_assets (std::list<boost::shared_ptr<Asset> >& assets);
 
        /** Set the reel number or sub-element identifier
index 3c3c78925bc1681fa870a669d635dd100731a738..ddab12d39481ae774c2cbfecd8142945cc31f62e 100644 (file)
@@ -165,23 +165,23 @@ Reel::add (shared_ptr<ReelAsset> asset)
 }
 
 void
-Reel::resolve_refs (list<shared_ptr<Object> > objects)
+Reel::resolve_refs (list<shared_ptr<Asset> > assets)
 {
        if (_main_picture) {
-               _main_picture->asset_ref().resolve (objects);
+               _main_picture->asset_ref().resolve (assets);
        }
 
        if (_main_sound) {
-               _main_sound->asset_ref().resolve (objects);
+               _main_sound->asset_ref().resolve (assets);
        }
 
        if (_main_subtitle) {
-               _main_subtitle->asset_ref().resolve (objects);
+               _main_subtitle->asset_ref().resolve (assets);
 
                /* Interop subtitle handling is all special cases */
-               shared_ptr<InteropSubtitleAsset> iop = dynamic_pointer_cast<InteropSubtitleAsset> (_main_subtitle->asset_ref().object ());
+               shared_ptr<InteropSubtitleAsset> iop = dynamic_pointer_cast<InteropSubtitleAsset> (_main_subtitle->asset_ref().asset ());
                if (iop) {
-                       iop->resolve_fonts (objects);
+                       iop->resolve_fonts (assets);
                }
        }
 }
index 010322c2a37a0ae87748de2f2acb0a1b0670b523..3b3673efb41f975bb1b2cca413e18bbf1137a0ee 100644 (file)
@@ -81,7 +81,7 @@ public:
 
        void add (DecryptedKDM const &);
 
-       void resolve_refs (std::list<boost::shared_ptr<Object> >);
+       void resolve_refs (std::list<boost::shared_ptr<Asset> >);
 
 private:
        boost::shared_ptr<ReelPictureAsset> _main_picture;
index 46e0bd3c9ce2600fc4d21f0028831522c24290f4..ecaaa1fc9f4e4afc102f7bd8222a60faab8938a5 100644 (file)
@@ -96,7 +96,7 @@ ReelAsset::write_to_cpl (xmlpp::Node* node, Standard standard) const
         a->add_child("IntrinsicDuration")->add_child_text (raw_convert<string> (_intrinsic_duration));
         a->add_child("EntryPoint")->add_child_text (raw_convert<string> (_entry_point));
         a->add_child("Duration")->add_child_text (raw_convert<string> (_duration));
-       a->add_child("Hash")->add_child_text (_asset_ref.object()->hash ());
+       a->add_child("Hash")->add_child_text (_asset_ref.asset()->hash ());
 }
 
 pair<string, string>
@@ -149,7 +149,7 @@ ReelAsset::equals (shared_ptr<const ReelAsset> other, EqualityOptions opt, NoteH
        }
 
        if (_asset_ref.resolved () && other->_asset_ref.resolved ()) {
-               return _asset_ref->equals (other->_asset_ref.object (), opt, note);
+               return _asset_ref->equals (other->_asset_ref.asset(), opt, note);
        }
 
        return true;
index 6c501abfa68a5836e7fa82d64e7f78aa8620ec96..9211fbd12788ab0de7f9cfc8c8f1fcf4cb5dd1da 100644 (file)
@@ -59,12 +59,12 @@ public:
        virtual bool equals (boost::shared_ptr<const ReelAsset>, EqualityOptions, NoteHandler) const;
 
        /** @return a Ref to our actual asset */
-       Ref<Asset> const & asset_ref () const {
+       Ref const & asset_ref () const {
                return _asset_ref;
        }
 
        /** @return a Ref to our actual asset */
-       Ref<Asset>& asset_ref () {
+       Ref & asset_ref () {
                return _asset_ref;
        }
 
@@ -98,7 +98,7 @@ protected:
        /** Reference to the asset (MXF or XML file) that this reel entry
         *  applies to.
         */
-       Ref<Asset> _asset_ref;
+       Ref _asset_ref;
 
 private:
        std::string _annotation_text; ///< The &lt;AnnotationText&gt; from the reel's entry for this asset
index 544502335a656baa14746c15c7baeb085f560f1f..da2eb087b0217b8e3fbd9d05861aefc21729cb2f 100644 (file)
@@ -25,6 +25,7 @@
 #define LIBDCP_REEL_MONO_PICTURE_ASSET_H
 
 #include "reel_picture_asset.h"
+#include "mono_picture_asset.h"
 
 namespace dcp {
 
@@ -40,6 +41,16 @@ public:
        ReelMonoPictureAsset (boost::shared_ptr<MonoPictureAsset> asset, int64_t entry_point);
        ReelMonoPictureAsset (boost::shared_ptr<const cxml::Node>);
 
+       /** @return the MonoPictureAsset that this object refers to */
+       boost::shared_ptr<const MonoPictureAsset> mono_asset () const {
+               return boost::dynamic_pointer_cast<const MonoPictureAsset> (_asset_ref.asset ());
+       }
+
+       /** @return the MonoPictureAsset that this object refers to */
+       boost::shared_ptr<MonoPictureAsset> mono_asset () {
+               return boost::dynamic_pointer_cast<MonoPictureAsset> (_asset_ref.asset ());
+       }
+
 private:
        std::string cpl_node_name () const;
 };
index 15b01b74bc1da9812569237ea0ae0a5484b63c85..39ef3431bfa846ba506ceefc709f7f24fc4ea730 100644 (file)
@@ -43,9 +43,14 @@ public:
        virtual void write_to_cpl (xmlpp::Node* node, Standard standard) const;
        virtual bool equals (boost::shared_ptr<const ReelAsset>, EqualityOptions, NoteHandler) const;
 
+       /** @return the PictureAsset that this object refers to */
+       boost::shared_ptr<const PictureAsset> asset () const {
+               return boost::dynamic_pointer_cast<const PictureAsset> (_asset_ref.asset ());
+       }
+
        /** @return the PictureAsset that this object refers to */
        boost::shared_ptr<PictureAsset> asset () {
-               return boost::dynamic_pointer_cast<PictureAsset> (_asset_ref.object ());
+               return boost::dynamic_pointer_cast<PictureAsset> (_asset_ref.asset ());
        }
 
        /** @return picture frame rate */
index 8f39e8a094c8f474f55f1033b98711a607e1ef18..3158f8a06891b9c2ba8da665397e61619da9d243 100644 (file)
@@ -42,12 +42,12 @@ public:
 
        /** @return the SoundAsset that this object refers to */
        boost::shared_ptr<SoundAsset> asset () {
-               return boost::dynamic_pointer_cast<SoundAsset> (_asset_ref.object ());
+               return boost::dynamic_pointer_cast<SoundAsset> (_asset_ref.asset ());
        }
 
        /** @return the SoundAsset that this object refers to */
        boost::shared_ptr<const SoundAsset> asset () const {
-               return boost::dynamic_pointer_cast<const SoundAsset> (_asset_ref.object ());
+               return boost::dynamic_pointer_cast<const SoundAsset> (_asset_ref.asset ());
        }
 
 private:
@@ -56,4 +56,3 @@ private:
 };
 
 }
-
index 72b225bcc9c7f6ef3cd68fe6b82679d81e0dfab2..3c68f8870cd0b1d0031619ad5722c1e5857a0f40 100644 (file)
@@ -25,6 +25,7 @@
 #define LIBDCP_REEL_STEREO_PICTURE_ASSET_H
 
 #include "reel_picture_asset.h"
+#include "stereo_picture_asset.h"
 
 namespace dcp {
 
@@ -40,6 +41,16 @@ public:
        ReelStereoPictureAsset (boost::shared_ptr<StereoPictureAsset> content, int64_t entry_point);
        ReelStereoPictureAsset (boost::shared_ptr<const cxml::Node>);
 
+       /** @return the StereoPictureAsset that this object refers to */
+       boost::shared_ptr<const StereoPictureAsset> stereo_asset () const {
+               return boost::dynamic_pointer_cast<const StereoPictureAsset> (_asset_ref.asset ());
+       }
+
+       /** @return the StereoPictureAsset that this object refers to */
+       boost::shared_ptr<StereoPictureAsset> stereo_asset () {
+               return boost::dynamic_pointer_cast<StereoPictureAsset> (_asset_ref.asset ());
+       }
+
 private:
        std::string cpl_node_name () const;
        std::pair<std::string, std::string> cpl_node_attribute (Standard standard) const;
@@ -48,4 +59,3 @@ private:
 }
 
 #endif
-
index d4f11cfa777d1a010c484daad48c6407ae54bda3..272b18f54c6c4cf987872fe9d37fa50ee562ddf1 100644 (file)
@@ -41,7 +41,7 @@ public:
        ReelSubtitleAsset (boost::shared_ptr<const cxml::Node>);
 
        boost::shared_ptr<SubtitleAsset> asset () const {
-               return boost::dynamic_pointer_cast<SubtitleAsset> (_asset_ref.object ());
+               return boost::dynamic_pointer_cast<SubtitleAsset> (_asset_ref.asset ());
        }
 
 private:
index e2e2aa01a150fda5545014cafcd10b6b49eefbd1..06daddcfcd765ba030a6676774c89146e23fa963 100644 (file)
--- a/src/ref.h
+++ b/src/ref.h
@@ -25,7 +25,7 @@
 #define LIBDCP_REF_H
 
 #include "exceptions.h"
-#include "object.h"
+#include "asset.h"
 #include "util.h"
 #include <boost/shared_ptr.hpp>
 #include <string>
 namespace dcp {
 
 /** @class Ref
- *  @brief A reference to an object which is identified by a universally-unique identifier (UUID).
+ *  @brief A reference to an asset which is identified by a universally-unique identifier (UUID).
  *
  *  This class is a `pointer' to a thing.  It will always know the
  *  UUID of the thing, and it may have a shared_ptr to the C++ object
  *  which represents the thing.
  *
  *  If the Ref does not have a shared_ptr it may be given one by
- *  calling resolve() with a list of objects.  The shared_ptr will be
+ *  calling resolve() with a list of assets.  The shared_ptr will be
  *  set up using any object on the list which has a matching ID.
  */
-template<class T>
 class Ref
 {
 public:
@@ -52,10 +51,10 @@ public:
                : _id (id)
        {}
 
-       /** Initialise a Ref with a shared_ptr to an object */
-       Ref (boost::shared_ptr<T> object)
-               : _id (object->id ())
-               , _object (object)
+       /** Initialise a Ref with a shared_ptr to an asset */
+       Ref (boost::shared_ptr<Asset> asset)
+               : _id (asset->id ())
+               , _asset (asset)
        {}
 
        /** Set the ID of this Ref */
@@ -64,20 +63,7 @@ public:
                _id = id;
        }
 
-       /** Look through a list of objects and copy a shared_ptr to any object
-        *  which matches the ID of this one.
-        */
-       void resolve (std::list<boost::shared_ptr<Object> > objects)
-       {
-               typename std::list<boost::shared_ptr<Object> >::iterator i = objects.begin();
-               while (i != objects.end() && !ids_equal ((*i)->id(), _id)) {
-                       ++i;
-               }
-
-               if (i != objects.end ()) {
-                       _object = boost::dynamic_pointer_cast<T> (*i);
-               }
-       }
+       void resolve (std::list<boost::shared_ptr<Asset> > assets);
 
        /** @return the ID of the thing that we are pointing to */
        std::string id () const {
@@ -87,33 +73,33 @@ public:
        /** @return a shared_ptr to the thing; an UnresolvedRefError is thrown
         *  if the shared_ptr is not known.
         */
-       boost::shared_ptr<T> object () const {
-               if (!_object) {
+       boost::shared_ptr<Asset> asset () const {
+               if (!_asset) {
                        throw UnresolvedRefError (_id);
                }
 
-               return _object;
+               return _asset;
        }
 
        /** operator-> to access the shared_ptr; an UnresolvedRefError is thrown
         *  if the shared_ptr is not known.
         */
-       T * operator->() const {
-               if (!_object) {
+       Asset * operator->() const {
+               if (!_asset) {
                        throw UnresolvedRefError (_id);
                }
 
-               return _object.get ();
+               return _asset.get ();
        }
 
        /** @return true if a shared_ptr is known for this Ref */
        bool resolved () const {
-               return static_cast<bool>(_object);
+               return static_cast<bool>(_asset);
        }
 
 private:
-       std::string _id;              ///< ID; will always be known
-       boost::shared_ptr<T> _object; ///< shared_ptr to the thing, may be null.
+       std::string _id;             ///< ID; will always be known
+       boost::shared_ptr<Asset> _asset; ///< shared_ptr to the thing, may be null.
 };
 
 }
index 29c5657b48cadc81cebab0d99feec696e41d1353..27afdfa2834f30bf373baf28ead1f0411f33a0b1 100644 (file)
@@ -65,21 +65,6 @@ extern std::string file_to_string (boost::filesystem::path, uintmax_t max_length
 extern std::string private_key_fingerprint (std::string key);
 extern xmlpp::Node* find_child (xmlpp::Node const * node, std::string name);
 
-template <class F, class T>
-std::list<boost::shared_ptr<T> >
-list_of_type (std::list<boost::shared_ptr<F> > const & from)
-{
-       std::list<boost::shared_ptr<T> > out;
-       for (typename std::list<boost::shared_ptr<F> >::const_iterator i = from.begin(); i != from.end(); ++i) {
-               boost::shared_ptr<T> check = boost::dynamic_pointer_cast<T> (*i);
-               if (check) {
-                       out.push_back (check);
-               }
-       }
-
-       return out;
-}
-
 }
 
 #endif
index 338027859b79ffe7dbb2215d10bfb67de7d4248a..16a173815a442403058ed4eb2c2463a3231f4347 100644 (file)
@@ -43,6 +43,7 @@ def build(bld):
              reel_sound_asset.cc
              reel_stereo_picture_asset.cc
              reel_subtitle_asset.cc
+             ref.cc
              rgb_xyz.cc
              smpte_load_font_node.cc
              smpte_subtitle_asset.cc
index 83aef25582d992c6ed5936e25d988981391f9816..9a482f0986084718062e3152f642f19ba0085667 100644 (file)
@@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE (interop_dcp_font_test)
        dcp::DCP dcp2 (directory);
        dcp2.read ();
        shared_ptr<dcp::SubtitleAsset> subs2 = dynamic_pointer_cast<dcp::SubtitleAsset> (
-               dcp2.cpls().front()->reels().front()->main_subtitle()->asset_ref().object()
+               dcp2.cpls().front()->reels().front()->main_subtitle()->asset_ref().asset()
                );
        BOOST_REQUIRE (subs2);
        BOOST_REQUIRE_EQUAL (subs2->_fonts.size(), 1);
@@ -94,7 +94,7 @@ BOOST_AUTO_TEST_CASE (smpte_dcp_font_test)
        dcp::DCP dcp2 (directory);
        dcp2.read ();
        shared_ptr<dcp::SubtitleAsset> subs2 = dynamic_pointer_cast<dcp::SubtitleAsset> (
-               dcp2.cpls().front()->reels().front()->main_subtitle()->asset_ref().object()
+               dcp2.cpls().front()->reels().front()->main_subtitle()->asset_ref().asset()
                );
        BOOST_REQUIRE (subs2);
        BOOST_REQUIRE_EQUAL (subs2->_fonts.size(), 1);