TagBuilder: add method Commit(Tag&)
For callers that already have a Tag instance.
This commit is contained in:
parent
84533b6cad
commit
a24589d46e
@ -43,27 +43,34 @@ TagBuilder::Clear()
|
|||||||
items.clear();
|
items.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
Tag *
|
void
|
||||||
TagBuilder::Commit()
|
TagBuilder::Commit(Tag &tag)
|
||||||
{
|
{
|
||||||
Tag *tag = new Tag();
|
tag.Clear();
|
||||||
tag->time = time;
|
|
||||||
tag->has_playlist = has_playlist;
|
tag.time = time;
|
||||||
|
tag.has_playlist = has_playlist;
|
||||||
|
|
||||||
/* move all TagItem pointers to the new Tag object without
|
/* move all TagItem pointers to the new Tag object without
|
||||||
touching the TagPool reference counters; the
|
touching the TagPool reference counters; the
|
||||||
vector::clear() call is important to detach them from this
|
vector::clear() call is important to detach them from this
|
||||||
object */
|
object */
|
||||||
const unsigned n_items = items.size();
|
const unsigned n_items = items.size();
|
||||||
tag->num_items = n_items;
|
tag.num_items = n_items;
|
||||||
tag->items = g_new(TagItem *, n_items);
|
tag.items = g_new(TagItem *, n_items);
|
||||||
std::copy_n(items.begin(), n_items, tag->items);
|
std::copy_n(items.begin(), n_items, tag.items);
|
||||||
items.clear();
|
items.clear();
|
||||||
|
|
||||||
/* now ensure that this object is fresh (will not delete any
|
/* now ensure that this object is fresh (will not delete any
|
||||||
items because we've already moved them out) */
|
items because we've already moved them out) */
|
||||||
Clear();
|
Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
Tag *
|
||||||
|
TagBuilder::Commit()
|
||||||
|
{
|
||||||
|
Tag *tag = new Tag();
|
||||||
|
Commit(*tag);
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,6 +83,12 @@ public:
|
|||||||
|
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move this object to the given #Tag instance. This object
|
||||||
|
* is empty afterwards.
|
||||||
|
*/
|
||||||
|
void Commit(Tag &tag);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new #Tag instance from data in this object. The
|
* Create a new #Tag instance from data in this object. The
|
||||||
* returned object is owned by the caller. This object is
|
* returned object is owned by the caller. This object is
|
||||||
|
Loading…
Reference in New Issue
Block a user