diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-07-29 16:21:13 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-07-29 16:21:13 +0100 |
| commit | 7e9ad089942bc3f1f9b461c87203b515c6d4a237 (patch) | |
| tree | c4af2873e366d2ca59210d74a14f9cfd5e2b42ac | |
| parent | 8ef91325f4e565d04493bc05202f8e066b5e3e0c (diff) | |
Simplify NameFormat classes a bit.
| -rw-r--r-- | src/dcp.cc | 8 | ||||
| -rw-r--r-- | src/filename_format.cc | 6 | ||||
| -rw-r--r-- | src/name_format.cc | 22 | ||||
| -rw-r--r-- | src/name_format.h | 24 |
4 files changed, 18 insertions, 42 deletions
@@ -464,15 +464,15 @@ DCP::write_xml ( { BOOST_FOREACH (shared_ptr<CPL> i, cpls ()) { NameFormat::Map values; - values["type"] = "cpl"; - values["id"] = i->id(); + values['t'] = "cpl"; + values['i'] = i->id(); i->write_xml (_directory / (filename_format.get(values) + ".xml"), standard, signer); } string const pkl_uuid = make_uuid (); NameFormat::Map values; - values["type"] = "pkl"; - values["id"] = pkl_uuid; + values['t'] = "pkl"; + values['i'] = pkl_uuid; boost::filesystem::path const pkl_path = write_pkl (filename_format.get(values) + ".xml", standard, pkl_uuid, metadata, signer); write_volindex (standard); diff --git a/src/filename_format.cc b/src/filename_format.cc index 37fc12a0..d1536c08 100644 --- a/src/filename_format.cc +++ b/src/filename_format.cc @@ -39,6 +39,8 @@ using namespace dcp; FilenameFormat::FilenameFormat (string specification) : NameFormat (specification) { - add ("type", 't', "asset type (j2c/pcm/sub/pkl/cpl)"); - add ("id", 'i', "unique ID"); + /* asset type */ + add ('t'); + /* unique ID */ + add ('i'); } diff --git a/src/name_format.cc b/src/name_format.cc index 1dc1135d..300ff315 100644 --- a/src/name_format.cc +++ b/src/name_format.cc @@ -65,21 +65,9 @@ filter (string c) } void -NameFormat::add (string name, char placeholder, string title) +NameFormat::add (char placeholder) { - _components.push_back (Component (name, placeholder, title)); -} - -optional<NameFormat::Component> -NameFormat::component_by_placeholder (char p) const -{ - BOOST_FOREACH (Component const & i, _components) { - if (i.placeholder == p) { - return i; - } - } - - return optional<Component> (); + _components.push_back (placeholder); } string @@ -89,9 +77,9 @@ NameFormat::get (Map values) const for (size_t i = 0; i < _specification.length(); ++i) { bool done = false; if (_specification[i] == '%' && (i < _specification.length() - 1)) { - optional<Component> c = component_by_placeholder (_specification[i + 1]); - if (c) { - result += filter (values[c->name]); + Map::const_iterator j = values.find(_specification[i + 1]); + if (j != values.end()) { + result += filter (j->second); ++i; done = true; } diff --git a/src/name_format.h b/src/name_format.h index c2a71280..7eb2713f 100644 --- a/src/name_format.h +++ b/src/name_format.h @@ -43,20 +43,7 @@ namespace dcp { class NameFormat { public: - struct Component - { - Component (std::string name_, char placeholder_, std::string title_) - : name (name_) - , placeholder (placeholder_) - , title (title_) - {} - - std::string name; - char placeholder; - std::string title; - }; - - std::list<Component> components () const { + std::list<char> components () const { return _components; } @@ -68,7 +55,7 @@ public: _specification = specification; } - typedef std::map<std::string, std::string> Map; + typedef std::map<char, std::string> Map; std::string get (Map) const; @@ -79,12 +66,11 @@ protected: : _specification (specification) {} - void add (std::string name, char placeholder, std::string title); + void add (char placeholder); private: - boost::optional<NameFormat::Component> component_by_placeholder (char p) const; - - std::list<Component> _components; + /** placeholders for each component */ + std::list<char> _components; std::string _specification; }; |
