diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-06-02 09:14:15 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-06-02 09:14:15 +0100 |
| commit | 51919d468831a876f31d5a6e2b25f8913314770d (patch) | |
| tree | b62e82991b9446498b7c6c71760aaec1bf09dbf3 /src | |
| parent | 8637a174f595f78070d88aadcc31a0216b58d857 (diff) | |
Use optional<> for _hash and make it private.
Diffstat (limited to 'src')
| -rw-r--r-- | src/asset.cc | 6 | ||||
| -rw-r--r-- | src/asset.h | 12 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/asset.cc b/src/asset.cc index 8753528b..60d3aab3 100644 --- a/src/asset.cc +++ b/src/asset.cc @@ -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> (); } diff --git a/src/asset.h b/src/asset.h index 17237306..7adf0090 100644 --- a/src/asset.h +++ b/src/asset.h @@ -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; }; } |
