Use optional<> for _hash and make it private.
authorCarl Hetherington <cth@carlh.net>
Thu, 2 Jun 2016 08:14:15 +0000 (09:14 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 2 Jun 2016 08:14:15 +0000 (09:14 +0100)
src/asset.cc
src/asset.h

index 8753528b98005e2afea47953b9bffdaf1c56a032..60d3aab311d27c8a19c919e351f20ba36aff9e38 100644 (file)
@@ -115,11 +115,11 @@ Asset::hash (function<void (float)> progress) const
 {
        DCP_ASSERT (!_file.empty ());
 
-       if (_hash.empty ()) {
+       if (!_hash) {
                _hash = make_digest (_file, progress);
        }
 
-       return _hash;
+       return _hash.get();
 }
 
 bool
@@ -143,5 +143,5 @@ void
 Asset::set_file (boost::filesystem::path file) const
 {
        _file = boost::filesystem::absolute (file);
-       _hash.clear ();
+       _hash = optional<string> ();
 }
index 172373067ef3d87be3025a7f3bc3d6b55f2cd714..7adf009087d0870abd5ef33d03c14837fabff4cc 100644 (file)
@@ -29,6 +29,7 @@
 #include <boost/filesystem.hpp>
 #include <boost/function.hpp>
 #include <boost/bind.hpp>
+#include <boost/optional.hpp>
 
 namespace xmlpp {
        class Node;
@@ -79,14 +80,17 @@ public:
        std::string hash (boost::function<void (float)> progress = 0) const;
 
 protected:
+
+       /** The most recent disk file used to read or write this asset; may be empty */
+       mutable boost::filesystem::path _file;
+
+private:
        friend struct ::asset_test;
 
        virtual std::string pkl_type (Standard standard) const = 0;
 
-       /** The most recent disk file used to read or write this asset; may be empty */
-       mutable boost::filesystem::path _file;
-       /** Hash of _file, or empty if the hash has not yet been computed */
-       mutable std::string _hash;
+       /** Hash of _file if it has been computed */
+       mutable boost::optional<std::string> _hash;
 };
 
 }