29 #ifndef HPP_CORE_CONTAINER_HH
30 #define HPP_CORE_CONTAINER_HH
33 #include <hpp/util/pointer.hh>
37 #include <type_traits>
44 struct is_pointer : std::is_pointer<T> {};
46 struct is_pointer<shared_ptr<T> > : std::true_type {};
48 struct remove_pointer : std::remove_pointer<T> {};
50 struct remove_pointer<shared_ptr<T> > {
54 struct remove_pointer<const shared_ptr<T> > {
58 template <
bool deref_ptr>
61 static inline T get(T t) {
68 static inline typename remove_pointer<T>::type get(T t) {
75 template <
typename Types,
typename Key = std::
string>
77 typedef std::map<Key, Types>
Map_t;
87 void erase(
const Key& name) {
map.erase(name); }
92 std::pair<iterator, bool> ret =
map.insert(
value_type(name, element));
93 if (!ret.second) ret.first->second = element;
101 if (_e ==
map.end()) {
102 std::stringstream ss;
103 ss <<
"Invalid key: " << name;
104 throw std::invalid_argument(ss.str());
113 if (_e ==
map.end())
return defaultValue;
119 template <
typename ReturnType>
123 l.push_back(_e->second);
127 template <
typename ReturnType>
131 l.push_back(_e->first);
136 std::ostream&
print(std::ostream& os)
const {
137 typedef internal::is_pointer<mapped_type> should_deref;
138 typedef internal::deref<should_deref::value> deref;
140 os << _e->first <<
": "
141 << deref::template get<const mapped_type>(_e->second) << std::endl;
pinocchio::value_type value_type
Definition: fwd.hh:174
Definition: bi-rrt-planner.hh:35
Definition: container.hh:76
bool has(const key_type &name) const
Return the element named name.
Definition: container.hh:96
std::map< Key, Types > Map_t
Definition: container.hh:77
Map_t::const_iterator const_iterator
Definition: container.hh:81
void add(const key_type &name, const mapped_type &element)
Add an element.
Definition: container.hh:91
Map_t::key_type key_type
Definition: container.hh:79
Map_t::value_type value_type
Definition: container.hh:78
std::ostream & print(std::ostream &os) const
Print object in a stream.
Definition: container.hh:136
void erase(const Key &name)
Erase the element named name.
Definition: container.hh:87
Map_t::mapped_type mapped_type
Definition: container.hh:80
ReturnType getAllAs() const
Definition: container.hh:120
void clear()
Clear content of container.
Definition: container.hh:89
const mapped_type & get(const key_type &name, const mapped_type &defaultValue) const
Return the element named name.
Definition: container.hh:110
ReturnType getKeys() const
Definition: container.hh:128
Map_t map
Definition: container.hh:84
Map_t::iterator iterator
Definition: container.hh:82
const mapped_type & get(const key_type &name) const
Return the element named name.
Definition: container.hh:99