17 #ifndef HPP_CORE_CONTAINER_HH 18 # define HPP_CORE_CONTAINER_HH 22 # include <type_traits> 24 # include <hpp/util/pointer.hh> 31 template <
typename T>
struct is_pointer : std::is_pointer<T> {};
32 template <
typename T>
struct is_pointer<shared_ptr<T> > : std::true_type {};
33 template <
typename T>
struct remove_pointer : std::remove_pointer<T> {};
34 template <
typename T>
struct remove_pointer<shared_ptr<T> > {
typedef T type; };
35 template <
typename T>
struct remove_pointer<const shared_ptr<T> > {
typedef T type; };
37 template <
bool deref_ptr>
struct deref {
38 template <
typename T>
static inline T
get (T t) {
return t; }
40 template <>
struct deref <true> {
41 template <
typename T>
static inline typename remove_pointer<T>::type
get (T t) {
return *t; }
46 template <
typename Types,
typename Key = std::
string >
struct Container 48 typedef std::map <Key, Types>
Map_t;
58 void erase (
const Key& name) { map.erase (name); }
62 void add (
const key_type& name,
const mapped_type& element)
64 std::pair<iterator, bool> ret = map.insert(
value_type(name, element));
66 ret.first->second = element;
69 bool has (
const key_type& name)
const {
return (map.find (name) != map.end ()); }
72 const mapped_type&
get (
const key_type& name)
const 74 const_iterator _e = map.find (name);
75 if (_e == map.end ()) {
76 std::stringstream ss; ss <<
"Invalid key: " << name;
77 throw std::invalid_argument (ss.str());
83 const mapped_type&
get (
const key_type& name,
const mapped_type& defaultValue)
const 85 const_iterator _e = map.find (name);
86 if (_e == map.end ())
return defaultValue;
92 template <
typename ReturnType>
96 for (const_iterator _e = map.begin (); _e != map.end (); ++_e)
97 l.push_back (_e->second);
101 template <
typename ReturnType>
105 for (const_iterator _e = map.begin (); _e != map.end (); ++_e)
106 l.push_back (_e->first);
111 std::ostream&
print (std::ostream& os)
const 113 typedef internal::is_pointer<mapped_type> should_deref;
114 typedef internal::deref<should_deref::value> deref;
115 for (const_iterator _e = map.begin (); _e != map.end (); ++_e)
116 os << _e->first <<
": " 117 << deref::template get<const mapped_type> (_e->second)
124 #endif // HPP_CORE_CONTAINER_HH ReturnType getAllAs() const
Definition: container.hh:93
ReturnType getKeys() const
Definition: container.hh:102
Definition: bi-rrt-planner.hh:24
std::ostream & print(std::ostream &os) const
Print object in a stream.
Definition: container.hh:111
Map_t::key_type key_type
Definition: container.hh:50
bool has(const key_type &name) const
Return the element named name.
Definition: container.hh:69
Definition: container.hh:46
Map_t::iterator iterator
Definition: container.hh:53
std::map< Key, Types > Map_t
Definition: container.hh:48
Map_t::mapped_type mapped_type
Definition: container.hh:51
void clear()
Clear content of container.
Definition: container.hh:60
pinocchio::value_type value_type
Definition: fwd.hh:157
void add(const key_type &name, const mapped_type &element)
Add an element.
Definition: container.hh:62
Map_t::const_iterator const_iterator
Definition: container.hh:52
Map_t map
Definition: container.hh:55
void erase(const Key &name)
Erase the element named name.
Definition: container.hh:58
Map_t::value_type value_type
Definition: container.hh:49