Container::remove(): return removed Stage

This commit is contained in:
Robert Haschke 2020-07-13 16:49:27 +02:00
parent e9c56c9c64
commit 4089d5eefa
3 changed files with 10 additions and 9 deletions

View File

@ -65,8 +65,8 @@ public:
void add(Stage::pointer&& stage);
virtual bool insert(Stage::pointer&& stage, int before = -1);
virtual bool remove(int pos);
virtual bool remove(Stage* child);
virtual Stage::pointer remove(int pos);
virtual Stage::pointer remove(Stage* child);
virtual void clear();
void reset() override;

View File

@ -89,7 +89,7 @@ public:
const_iterator childByIndex(int index, bool for_insert = false) const;
/// remove child at given iterator position, returns fals if pos is invalid
bool remove(ContainerBasePrivate::const_iterator pos);
Stage::pointer remove(ContainerBasePrivate::const_iterator pos);
/// traversing all stages up to max_depth
bool traverseStages(const ContainerBase::StageCallback& processor, unsigned int cur_depth,

View File

@ -204,20 +204,21 @@ bool ContainerBase::insert(Stage::pointer&& stage, int before) {
return true;
}
bool ContainerBasePrivate::remove(ContainerBasePrivate::const_iterator pos) {
Stage::pointer ContainerBasePrivate::remove(ContainerBasePrivate::const_iterator pos) {
if (pos == children_.end())
return false;
return Stage::pointer();
(*pos)->pimpl()->unparent();
children_.erase(pos);
return true;
Stage::pointer result = std::move(*children_.erase(pos, pos)); // stage from non-const iterator to pos
children_.erase(pos); // actually erase stage
return result;
}
bool ContainerBase::remove(int pos) {
Stage::pointer ContainerBase::remove(int pos) {
return pimpl()->remove(pimpl()->childByIndex(pos, false));
}
bool ContainerBase::remove(Stage* child) {
Stage::pointer ContainerBase::remove(Stage* child) {
auto it = pimpl()->children_.begin(), end = pimpl()->children_.end();
for (; it != end && it->get() != child; ++it)
;