From 6605e17a1a7aba1b16c37af42d8f26f826fa29fa Mon Sep 17 00:00:00 2001 From: Joseph Mirabel <jmirabel@laas.fr> Date: Mon, 11 Jan 2016 19:00:46 +0100 Subject: [PATCH] Update to changes in hpp-core regarding Container class --- include/hpp/manipulation/device.hh | 7 +++++++ include/hpp/manipulation/problem-solver.hh | 7 +++++++ src/problem-solver.cc | 16 ++++++++-------- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/include/hpp/manipulation/device.hh b/include/hpp/manipulation/device.hh index fefbe58a..fec0b6ac 100644 --- a/include/hpp/manipulation/device.hh +++ b/include/hpp/manipulation/device.hh @@ -67,6 +67,13 @@ namespace hpp { return core::Container <Element>::get (name); } + /// Check if a Container has a key. + template <typename Element> + bool has (const std::string& name) const + { + return core::Container <Element>::has (name); + } + /// Get the keys of a container template <typename Element, typename ReturnType> ReturnType getKeys () const diff --git a/include/hpp/manipulation/problem-solver.hh b/include/hpp/manipulation/problem-solver.hh index a30be804..91c0fcd1 100644 --- a/include/hpp/manipulation/problem-solver.hh +++ b/include/hpp/manipulation/problem-solver.hh @@ -136,6 +136,13 @@ namespace hpp { return Container <Element>::get (name); } + /// Check if a Container has a key. + template <typename Element> + bool has (const std::string& name) const + { + return core::Container <Element>::has (name); + } + /// Add an element to a container template <typename Element> void add (const std::string& name, const Element& element) diff --git a/src/problem-solver.cc b/src/problem-solver.cc index 8772e009..6700497b 100644 --- a/src/problem-solver.cc +++ b/src/problem-solver.cc @@ -161,21 +161,21 @@ namespace hpp { ConvexShapeContactComplementPtr_t > constraints (ConvexShapeContactComplement::createPair (name, complementName, robot_)); - JointAndShapes_t l = robot_->get <JointAndShapes_t> (surface1); - if (l.empty ()) throw std::runtime_error - ("First list of triangles not found."); + if (!robot_->has <JointAndShapes_t> (surface1)) + throw std::runtime_error ("First list of triangles not found."); + JointAndShapes_t l = robot_->get <JointAndShapes_t> (surface1); for (JointAndShapes_t::const_iterator it = l.begin (); it != l.end(); ++it) { constraints.first->addObject (ConvexShape (it->second, it->first)); } + // Search first robot triangles - l = robot_->get <JointAndShapes_t> (surface2); - if (l.empty ()) { + if (robot_->has <JointAndShapes_t> (surface2)) + l = robot_->get <JointAndShapes_t> (surface2); // and then environment triangles. + else if (has <JointAndShapes_t> (surface2)) l = get <JointAndShapes_t> (surface2); - if (l.empty ()) throw std::runtime_error - ("Second list of triangles not found."); - } + else throw std::runtime_error ("Second list of triangles not found."); for (JointAndShapes_t::const_iterator it = l.begin (); it != l.end(); ++it) { constraints.first->addFloor (ConvexShape (it->second, it->first)); -- GitLab