mirror of
https://github.com/moveit/moveit_task_constructor.git
synced 2025-11-04 14:49:57 +08:00
ContainerBasePrivate::position() -> childByIndex()
This commit is contained in:
parent
84f5c481be
commit
f0dc02e2c3
@ -76,7 +76,7 @@ public:
|
|||||||
* Negative index counts from end, i.e. -1 is last, -2 is second last, etc. (if !for_insert)
|
* Negative index counts from end, i.e. -1 is last, -2 is second last, etc. (if !for_insert)
|
||||||
* If for_insert == true, negative indexes are shifted by one: -1 is end(), -2 is --end(), etc.
|
* If for_insert == true, negative indexes are shifted by one: -1 is end(), -2 is --end(), etc.
|
||||||
* Contrary to std::advance(), iterator limits are considered. */
|
* Contrary to std::advance(), iterator limits are considered. */
|
||||||
const_iterator position(int index, bool for_insert = false) const;
|
const_iterator childByIndex(int index, bool for_insert = false) const;
|
||||||
|
|
||||||
/// traversing all stages up to max_depth
|
/// traversing all stages up to max_depth
|
||||||
bool traverseStages(const ContainerBase::StageCallback &processor,
|
bool traverseStages(const ContainerBase::StageCallback &processor,
|
||||||
|
|||||||
@ -56,7 +56,7 @@ ContainerBasePrivate::ContainerBasePrivate(ContainerBase *me, const std::string
|
|||||||
pending_forward_.reset(new Interface);
|
pending_forward_.reset(new Interface);
|
||||||
}
|
}
|
||||||
|
|
||||||
ContainerBasePrivate::const_iterator ContainerBasePrivate::position(int index, bool for_insert) const {
|
ContainerBasePrivate::const_iterator ContainerBasePrivate::childByIndex(int index, bool for_insert) const {
|
||||||
if (!for_insert && index < 0)
|
if (!for_insert && index < 0)
|
||||||
--index;
|
--index;
|
||||||
const_iterator position = children_.begin();
|
const_iterator position = children_.begin();
|
||||||
@ -166,7 +166,7 @@ bool ContainerBase::insert(Stage::pointer &&stage, int before)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ContainerBasePrivate::const_iterator where = pimpl()->position(before, true);
|
ContainerBasePrivate::const_iterator where = pimpl()->childByIndex(before, true);
|
||||||
ContainerBasePrivate::iterator it = pimpl()->children_.insert(where, std::move(stage));
|
ContainerBasePrivate::iterator it = pimpl()->children_.insert(where, std::move(stage));
|
||||||
impl->setHierarchy(this, it);
|
impl->setHierarchy(this, it);
|
||||||
return true;
|
return true;
|
||||||
@ -174,7 +174,7 @@ bool ContainerBase::insert(Stage::pointer &&stage, int before)
|
|||||||
|
|
||||||
bool ContainerBase::remove(int pos)
|
bool ContainerBase::remove(int pos)
|
||||||
{
|
{
|
||||||
ContainerBasePrivate::const_iterator it = pimpl()->position(pos, false);
|
ContainerBasePrivate::const_iterator it = pimpl()->childByIndex(pos, false);
|
||||||
(*it)->pimpl()->setHierarchy(nullptr, ContainerBasePrivate::iterator());
|
(*it)->pimpl()->setHierarchy(nullptr, ContainerBasePrivate::iterator());
|
||||||
pimpl()->children_.erase(it);
|
pimpl()->children_.erase(it);
|
||||||
return true;
|
return true;
|
||||||
@ -188,7 +188,7 @@ void ContainerBase::clear()
|
|||||||
void ContainerBase::exposePropertiesOfChild(int child, const std::initializer_list<std::string>& names)
|
void ContainerBase::exposePropertiesOfChild(int child, const std::initializer_list<std::string>& names)
|
||||||
{
|
{
|
||||||
auto impl = pimpl();
|
auto impl = pimpl();
|
||||||
ContainerBasePrivate::const_iterator child_it = impl->position(child, false);
|
ContainerBasePrivate::const_iterator child_it = impl->childByIndex(child, false);
|
||||||
if (child_it == impl->children().end())
|
if (child_it == impl->children().end())
|
||||||
throw std::runtime_error("invalid child index");
|
throw std::runtime_error("invalid child index");
|
||||||
|
|
||||||
@ -203,7 +203,7 @@ void ContainerBase::exposePropertyOfChildAs(int child, const std::string& child_
|
|||||||
const std::string& parent_property_name)
|
const std::string& parent_property_name)
|
||||||
{
|
{
|
||||||
auto impl = pimpl();
|
auto impl = pimpl();
|
||||||
ContainerBasePrivate::const_iterator child_it = impl->position(child, false);
|
ContainerBasePrivate::const_iterator child_it = impl->childByIndex(child, false);
|
||||||
if (child_it == impl->children().end())
|
if (child_it == impl->children().end())
|
||||||
throw std::runtime_error("invalid child index");
|
throw std::runtime_error("invalid child index");
|
||||||
|
|
||||||
|
|||||||
@ -77,26 +77,26 @@ TEST(ContainerBase, positionForInsert) {
|
|||||||
SerialContainer s;
|
SerialContainer s;
|
||||||
SerialContainerPrivate *impl = s.pimpl();
|
SerialContainerPrivate *impl = s.pimpl();
|
||||||
|
|
||||||
EXPECT_EQ(impl->position(0, true), impl->children().end());
|
EXPECT_EQ(impl->childByIndex(0, true), impl->children().end());
|
||||||
EXPECT_EQ(impl->position(1, true), impl->children().end());
|
EXPECT_EQ(impl->childByIndex(1, true), impl->children().end());
|
||||||
EXPECT_EQ(impl->position(-1, true), impl->children().end());
|
EXPECT_EQ(impl->childByIndex(-1, true), impl->children().end());
|
||||||
EXPECT_EQ(impl->position(-2, true), impl->children().end());
|
EXPECT_EQ(impl->childByIndex(-2, true), impl->children().end());
|
||||||
|
|
||||||
s.insert(std::make_unique<NamedStage>("0"));
|
s.insert(std::make_unique<NamedStage>("0"));
|
||||||
EXPECT_STREQ((*impl->position(0, true))->name().c_str(), "0");
|
EXPECT_STREQ((*impl->childByIndex(0, true))->name().c_str(), "0");
|
||||||
EXPECT_EQ(impl->position(-1, true), impl->children().end());
|
EXPECT_EQ(impl->childByIndex(-1, true), impl->children().end());
|
||||||
EXPECT_STREQ((*impl->position(-2, true))->name().c_str(), "0");
|
EXPECT_STREQ((*impl->childByIndex(-2, true))->name().c_str(), "0");
|
||||||
EXPECT_EQ(impl->position(-3, true), impl->children().end());
|
EXPECT_EQ(impl->childByIndex(-3, true), impl->children().end());
|
||||||
|
|
||||||
s.insert(std::make_unique<NamedStage>("1"));
|
s.insert(std::make_unique<NamedStage>("1"));
|
||||||
EXPECT_STREQ((*impl->position(0, true))->name().c_str(), "0");
|
EXPECT_STREQ((*impl->childByIndex(0, true))->name().c_str(), "0");
|
||||||
EXPECT_STREQ((*impl->position(1, true))->name().c_str(), "1");
|
EXPECT_STREQ((*impl->childByIndex(1, true))->name().c_str(), "1");
|
||||||
EXPECT_EQ(impl->position(2, true), impl->children().end());
|
EXPECT_EQ(impl->childByIndex(2, true), impl->children().end());
|
||||||
|
|
||||||
EXPECT_EQ(impl->position(-1, true), impl->children().end());
|
EXPECT_EQ(impl->childByIndex(-1, true), impl->children().end());
|
||||||
EXPECT_STREQ((*impl->position(-2, true))->name().c_str(), "1");
|
EXPECT_STREQ((*impl->childByIndex(-2, true))->name().c_str(), "1");
|
||||||
EXPECT_STREQ((*impl->position(-3, true))->name().c_str(), "0");
|
EXPECT_STREQ((*impl->childByIndex(-3, true))->name().c_str(), "0");
|
||||||
EXPECT_EQ(impl->position(-4, true), impl->children().end());
|
EXPECT_EQ(impl->childByIndex(-4, true), impl->children().end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -154,8 +154,8 @@ protected:
|
|||||||
ASSERT_TRUE(num == expected.size()) << "different list lengths";
|
ASSERT_TRUE(num == expected.size()) << "different list lengths";
|
||||||
|
|
||||||
// validate position()
|
// validate position()
|
||||||
EXPECT_EQ(container->children().begin(), container->position(-num));
|
EXPECT_EQ(container->children().begin(), container->childByIndex(-num));
|
||||||
EXPECT_EQ(container->children().end(), container->position(num));
|
EXPECT_EQ(container->children().end(), container->childByIndex(num));
|
||||||
|
|
||||||
// validate order
|
// validate order
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
@ -164,8 +164,8 @@ protected:
|
|||||||
StagePrivate *child = (*it)->pimpl();
|
StagePrivate *child = (*it)->pimpl();
|
||||||
EXPECT_EQ(child, *exp_it) << "wrong order";
|
EXPECT_EQ(child, *exp_it) << "wrong order";
|
||||||
EXPECT_EQ(child->parent()->pimpl(), container) << "wrong parent";
|
EXPECT_EQ(child->parent()->pimpl(), container) << "wrong parent";
|
||||||
EXPECT_EQ(it, container->position(pos)) << "bad forward position resolution";
|
EXPECT_EQ(it, container->childByIndex(pos)) << "bad forward position resolution";
|
||||||
EXPECT_EQ(it, container->position(pos-num)) << "bad backward position resolution";
|
EXPECT_EQ(it, container->childByIndex(pos-num)) << "bad backward position resolution";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user