Some BOOST_FOREACH.
authorCarl Hetherington <cth@carlh.net>
Thu, 30 Apr 2015 22:19:51 +0000 (23:19 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 30 Apr 2015 22:19:51 +0000 (23:19 +0100)
src/cpl.cc
src/dcp.cc
src/decrypted_kdm.cc

index b0fc8d77bd8ef3a7f0bebf8a7221caf14928b55b..b11452d935a9468736b3b86cbfc119c312f605a8 100644 (file)
@@ -30,6 +30,7 @@
 #include "dcp_assert.h"
 #include "compose.hpp"
 #include <libxml/parser.h>
+#include <boost/foreach.hpp>
 
 using std::string;
 using std::stringstream;
@@ -135,9 +136,9 @@ CPL::write_xml (boost::filesystem::path file, Standard standard, shared_ptr<cons
        root->add_child("RatingList");
 
        xmlpp::Element* reel_list = root->add_child ("ReelList");
-       
-       for (list<shared_ptr<Reel> >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) {
-               (*i)->write_to_cpl (reel_list, standard);
+
+       BOOST_FOREACH (shared_ptr<Reel> i, _reels) {
+               i->write_to_cpl (reel_list, standard);
        }
 
        if (signer) {
@@ -155,15 +156,15 @@ CPL::reel_assets () const
 {
        list<shared_ptr<const ReelAsset> > c;
 
-       for (list<shared_ptr<Reel> >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) {
-               if ((*i)->main_picture ()) {
-                       c.push_back ((*i)->main_picture());
+       BOOST_FOREACH (shared_ptr<Reel> i, _reels) {
+               if (i->main_picture ()) {
+                       c.push_back (i->main_picture());
                }
-               if ((*i)->main_sound ()) {
-                       c.push_back ((*i)->main_sound());
+               if (i->main_sound ()) {
+                       c.push_back (i->main_sound());
                }
-               if ((*i)->main_subtitle ()) {
-                       c.push_back ((*i)->main_subtitle());
+               if (i->main_subtitle ()) {
+                       c.push_back (i->main_subtitle());
                }
        }
 
@@ -213,8 +214,8 @@ CPL::equals (shared_ptr<const Asset> other, EqualityOptions opt, NoteHandler not
 bool
 CPL::encrypted () const
 {
-       for (list<shared_ptr<Reel> >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) {
-               if ((*i)->encrypted ()) {
+       BOOST_FOREACH (shared_ptr<Reel> i, _reels) {
+               if (i->encrypted ()) {
                        return true;
                }
        }
@@ -229,16 +230,16 @@ CPL::encrypted () const
 void
 CPL::add (DecryptedKDM const & kdm)
 {
-       for (list<shared_ptr<Reel> >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) {
-               (*i)->add (kdm);
+       BOOST_FOREACH (shared_ptr<Reel> i, _reels) {
+               i->add (kdm);
        }
 }
 
 void
 CPL::resolve_refs (list<shared_ptr<Object> > objects)
 {
-       for (list<shared_ptr<Reel> >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) {
-               (*i)->resolve_refs (objects);
+       BOOST_FOREACH (shared_ptr<Reel> i, _reels) {
+               i->resolve_refs (objects);
        }
 }
 
index dd360edd5f22f21d5095fa3cf30b88cea753368f..f98fa1d3e7b36ee28d051d999aa163510d6abf22 100644 (file)
@@ -44,6 +44,7 @@
 #include <libxml++/libxml++.h>
 #include <boost/filesystem.hpp>
 #include <boost/algorithm/string.hpp>
+#include <boost/foreach.hpp>
 #include <iostream>
 
 using std::string;
@@ -98,15 +99,15 @@ DCP::read (bool keep_going, ReadErrors* errors)
        asset_map.read_file (asset_map_file);
        list<shared_ptr<cxml::Node> > asset_nodes = asset_map.node_child("AssetList")->node_children ("Asset");
        map<string, boost::filesystem::path> paths;
-       for (list<shared_ptr<cxml::Node> >::const_iterator i = asset_nodes.begin(); i != asset_nodes.end(); ++i) {
-               if ((*i)->node_child("ChunkList")->node_children("Chunk").size() != 1) {
+       BOOST_FOREACH (shared_ptr<cxml::Node> i, asset_nodes) {
+               if (i->node_child("ChunkList")->node_children("Chunk").size() != 1) {
                        boost::throw_exception (XMLError ("unsupported asset chunk count"));
                }
-               string p = (*i)->node_child("ChunkList")->node_child("Chunk")->string_child ("Path");
+               string p = i->node_child("ChunkList")->node_child("Chunk")->string_child ("Path");
                if (starts_with (p, "file://")) {
                        p = p.substr (7);
                }
-               paths.insert (make_pair ((*i)->string_child ("Id"), p));
+               paths.insert (make_pair (i->string_child ("Id"), p));
        }
 
        /* Read all the assets from the asset map */
@@ -166,9 +167,8 @@ DCP::read (bool keep_going, ReadErrors* errors)
                }
        }
 
-       list<shared_ptr<CPL> > cpl = cpls ();
-       for (list<shared_ptr<CPL> >::const_iterator i = cpl.begin(); i != cpl.end(); ++i) {
-               (*i)->resolve_refs (list_of_type<Asset, Object> (assets ()));
+       BOOST_FOREACH (shared_ptr<CPL> i, cpls ()) {
+               i->resolve_refs (list_of_type<Asset, Object> (assets ()));
        }
 }
 
@@ -185,9 +185,9 @@ DCP::equals (DCP const & other, EqualityOptions opt, NoteHandler note) const
 
        bool r = true;
 
-       for (list<shared_ptr<CPL> >::const_iterator i = a.begin(); i != a.end(); ++i) {
+       BOOST_FOREACH (shared_ptr<CPL> i, a) {
                list<shared_ptr<CPL> >::const_iterator j = b.begin ();
-               while (j != b.end() && !(*j)->equals (*i, opt, note)) {
+               while (j != b.end() && !(*j)->equals (i, opt, note)) {
                        ++j;
                }
 
@@ -208,9 +208,8 @@ DCP::add (boost::shared_ptr<Asset> asset)
 bool
 DCP::encrypted () const
 {
-       list<shared_ptr<CPL> > cpl = cpls ();
-       for (list<shared_ptr<CPL> >::const_iterator i = cpl.begin(); i != cpl.end(); ++i) {
-               if ((*i)->encrypted ()) {
+       BOOST_FOREACH (shared_ptr<CPL> i, cpls ()) {
+               if (i->encrypted ()) {
                        return true;
                }
        }
@@ -222,12 +221,11 @@ void
 DCP::add (DecryptedKDM const & kdm)
 {
        list<DecryptedKDMKey> keys = kdm.keys ();
-       list<shared_ptr<CPL> > cpl = cpls ();
-       
-       for (list<shared_ptr<CPL> >::iterator i = cpl.begin(); i != cpl.end(); ++i) {
-               for (list<DecryptedKDMKey>::iterator j = keys.begin(); j != keys.end(); ++j) {
-                       if (j->cpl_id() == (*i)->id()) {
-                               (*i)->add (kdm);
+
+       BOOST_FOREACH (shared_ptr<CPL> i, cpls ()) {
+               BOOST_FOREACH (DecryptedKDMKey const & j, kdm.keys ()) {
+                       if (j.cpl_id() == i->id()) {
+                               i->add (kdm);
                        }                               
                }
        }
@@ -262,8 +260,8 @@ DCP::write_pkl (Standard standard, string pkl_uuid, XMLMetadata metadata, shared
        pkl->add_child("Creator")->add_child_text (metadata.creator);
 
        xmlpp::Element* asset_list = pkl->add_child("AssetList");
-       for (list<shared_ptr<Asset> >::const_iterator i = _assets.begin(); i != _assets.end(); ++i) {
-               (*i)->write_to_pkl (asset_list, standard);
+       BOOST_FOREACH (shared_ptr<Asset> i, _assets) {
+               i->write_to_pkl (asset_list, standard);
        }
 
        if (signer) {
@@ -371,9 +369,9 @@ DCP::write_assetmap (Standard standard, string pkl_uuid, int pkl_length, XMLMeta
        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> (pkl_length));
-       
-       for (list<shared_ptr<Asset> >::const_iterator i = _assets.begin(); i != _assets.end(); ++i) {
-               (*i)->write_to_assetmap (asset_list, _directory);
+
+       BOOST_FOREACH (shared_ptr<Asset> i, _assets) {
+               i->write_to_assetmap (asset_list, _directory);
        }
 
        /* This must not be the _formatted version otherwise signature digests will be wrong */
@@ -392,10 +390,9 @@ DCP::write_xml (
        shared_ptr<const Signer> signer
        )
 {
-       list<shared_ptr<CPL> > cpl = cpls ();
-       for (list<shared_ptr<CPL> >::const_iterator i = cpl.begin(); i != cpl.end(); ++i) {
-               string const filename = (*i)->id() + "_cpl.xml";
-               (*i)->write_xml (_directory / filename, standard, signer);
+       BOOST_FOREACH (shared_ptr<CPL> i, cpls ()) {
+               string const filename = i->id() + "_cpl.xml";
+               i->write_xml (_directory / filename, standard, signer);
        }
 
        string const pkl_uuid = make_uuid ();
index 5f374dc7d8083863c7c4fe80bec7215c3679f196..bf9daa1a8d1a999df9bc232c053ec8fff3b06691 100644 (file)
@@ -33,6 +33,7 @@
 #include <openssl/rsa.h>
 #include <openssl/pem.h>
 #include <openssl/err.h>
+#include <boost/foreach.hpp>
 
 using std::list;
 using std::string;
@@ -116,12 +117,10 @@ DecryptedKDM::DecryptedKDM (EncryptedKDM const & kdm, string private_key)
 
        /* Use the private key to decrypt the keys */
 
-       list<string> const encrypted_keys = kdm.keys ();
-       for (list<string>::const_iterator i = encrypted_keys.begin(); i != encrypted_keys.end(); ++i) {
-
+       BOOST_FOREACH (string const & i, kdm.keys ()) {
                /* Decode the base-64-encoded cipher value from the KDM */
                unsigned char cipher_value[256];
-               int const cipher_value_len = base64_decode (*i, cipher_value, sizeof (cipher_value));
+               int const cipher_value_len = base64_decode (i, cipher_value, sizeof (cipher_value));
 
                /* Decrypt it */
                unsigned char * decrypted = new unsigned char[RSA_size(rsa)];
@@ -200,10 +199,9 @@ DecryptedKDM::DecryptedKDM (
        , _issue_date (issue_date)
 {
        /* Create DecryptedKDMKey objects for each MXF asset */
-       list<shared_ptr<const ReelAsset> > assets = cpl->reel_assets ();
-       for (list<shared_ptr<const ReelAsset> >::iterator i = assets.begin(); i != assets.end(); ++i) {
+       BOOST_FOREACH(shared_ptr<const ReelAsset> i, cpl->reel_assets ()) {
                /* XXX: do non-MXF assets need keys? */
-               shared_ptr<const ReelMXFAsset> mxf = boost::dynamic_pointer_cast<const ReelMXFAsset> (*i);
+               shared_ptr<const ReelMXFAsset> mxf = boost::dynamic_pointer_cast<const ReelMXFAsset> (i);
                if (mxf) {
                        if (mxf->key_id().empty ()) {
                                throw NotEncryptedError (mxf->id());
@@ -218,9 +216,8 @@ DecryptedKDM::encrypt (shared_ptr<const Signer> signer, Certificate recipient, F
 {
        list<pair<string, string> > key_ids;
        list<string> keys;
-       for (list<DecryptedKDMKey>::const_iterator i = _keys.begin(); i != _keys.end(); ++i) {
-
-               key_ids.push_back (make_pair (i->type(), i->id ()));
+       BOOST_FOREACH (DecryptedKDMKey const & i, _keys) {
+               key_ids.push_back (make_pair (i.type(), i.id ()));
 
                /* XXX: SMPTE only */
                uint8_t block[138];
@@ -233,12 +230,12 @@ DecryptedKDM::encrypt (shared_ptr<const Signer> signer, Certificate recipient, F
                base64_decode (signer->certificates().leaf().thumbprint (), p, 20);
                p += 20;
                
-               put_uuid (&p, i->cpl_id ());
-               put (&p, i->type ());
-               put_uuid (&p, i->id ());
+               put_uuid (&p, i.cpl_id ());
+               put (&p, i.type ());
+               put_uuid (&p, i.id ());
                put (&p, _not_valid_before.as_string ());
                put (&p, _not_valid_after.as_string ());
-               put (&p, i->key().value(), ASDCP::KeyLen);
+               put (&p, i.key().value(), ASDCP::KeyLen);
                
                /* Encrypt using the projector's public key */
                RSA* rsa = recipient.public_key ();