diff options
author | Max Kellermann <max@duempel.org> | 2013-12-02 12:42:04 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-12-03 11:46:23 +0100 |
commit | 6325c3f14a4dd1442d69dc5716b33c9d5b410164 (patch) | |
tree | ff7f9800326726cc8f80db46736fe14200e25be8 | |
parent | 074a23e6b4c7968715cfcc52ab9305be8a9fe3ac (diff) |
TagBuilder: add Tag copy/move constructors
-rw-r--r-- | src/tag/TagBuilder.cxx | 25 | ||||
-rw-r--r-- | src/tag/TagBuilder.hxx | 3 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/tag/TagBuilder.cxx b/src/tag/TagBuilder.cxx index 02749cfd5..15e32bb01 100644 --- a/src/tag/TagBuilder.cxx +++ b/src/tag/TagBuilder.cxx @@ -29,6 +29,31 @@ #include <assert.h> #include <string.h> +TagBuilder::TagBuilder(const Tag &other) + :time(other.time), has_playlist(other.has_playlist) +{ + items.reserve(other.num_items); + + tag_pool_lock.lock(); + for (unsigned i = 0, n = other.num_items; i != n; ++i) + items.push_back(tag_pool_dup_item(other.items[i])); + tag_pool_lock.unlock(); +} + +TagBuilder::TagBuilder(Tag &&other) + :time(other.time), has_playlist(other.has_playlist) +{ + /* move all TagItem pointers from the Tag object; we don't + need to contact the tag pool, because all we do is move + references */ + std::copy_n(other.items, other.num_items, std::back_inserter(items)); + + /* discard the pointers from the Tag object */ + other.num_items = 0; + delete[] other.items; + other.items = nullptr; +} + void TagBuilder::Clear() { diff --git a/src/tag/TagBuilder.hxx b/src/tag/TagBuilder.hxx index ff6251014..5804a7940 100644 --- a/src/tag/TagBuilder.hxx +++ b/src/tag/TagBuilder.hxx @@ -65,6 +65,9 @@ public: TagBuilder(const TagBuilder &other) = delete; TagBuilder &operator=(const TagBuilder &other) = delete; + TagBuilder(const Tag &other); + TagBuilder(Tag &&other); + /** * Returns true if the tag contains no items. This ignores the "time" * attribute. |