提交 fb4c048c 编写于 作者: J JasonZhou404 提交者: Jiangtao Hu

Planning: overload = for IndexedList

上级 ae431412
......@@ -85,6 +85,24 @@ class IndexedList {
*/
const std::vector<const T*>& Items() const { return object_list_; }
/**
* @brief List all the items in the container.
* @return the unordered_map of ids and objects in the container.
*/
const std::unordered_map<I, T>& Dict() const { return object_dict_; }
/**
* @brief Copy the container with objects.
*/
IndexedList& operator=(const IndexedList& other) {
this->object_list_.clear();
this->object_dict_.clear();
for (const auto& item : other.Dict()) {
Add(item.first, item.second);
}
return *this;
}
private:
std::vector<const T*> object_list_;
std::unordered_map<I, T> object_dict_;
......
......@@ -67,5 +67,19 @@ TEST(IndexedList, Find) {
ASSERT_EQ(nullptr, object.Find(2));
}
TEST(IndexedList, Copy) {
StringIndexedList b_object;
b_object.Add(1, "one");
b_object.Add(2, "two");
StringIndexedList a_object;
a_object.Add(3, "three");
a_object.Add(4, "four");
a_object = b_object;
ASSERT_NE(nullptr, a_object.Find(1));
ASSERT_NE(nullptr, a_object.Find(2));
ASSERT_EQ(nullptr, a_object.Find(3));
ASSERT_EQ(nullptr, a_object.Find(4));
}
} // namespace planning
} // namespace apollo
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册