36 using model_type = Model;
37 using order_t = std::list<Element*>;
39 = ossia::hash_map<Id<Model>, std::pair<Element*, typename order_t::iterator>>;
43 using value_type = Element;
58 for(
auto elt : m_order)
64 OSSIA_INLINE
auto& ordered() INLINE_EXPORT {
return m_order; }
68 return score::make_indirect_iterator(this->m_order.begin());
72 return score::make_indirect_iterator(this->m_order.rbegin());
76 return score::make_indirect_iterator(this->m_order.cbegin());
80 return score::make_indirect_iterator(this->m_order.end());
84 return score::make_indirect_iterator(this->m_order.rend());
88 return score::make_indirect_iterator(this->m_order.cend());
91 OSSIA_INLINE std::size_t size()
const INLINE_EXPORT {
return m_map.size(); }
93 bool empty()
const INLINE_EXPORT {
return m_map.empty(); }
95 std::vector<Element*> as_vec()
const INLINE_EXPORT
97 return std::vector<Element*>(m_order.begin(), m_order.end());
105 void insert(value_type* t) INLINE_EXPORT
107 SCORE_ASSERT(m_map.find(t->id()) == m_map.end());
108 m_order.push_front(t);
109 m_map.insert({t->id(), {t, m_order.begin()}});
112 void remove(
typename map_t::iterator it) INLINE_EXPORT
116 if(it != this->m_map.end())
118 m_order.erase(it->second.second);
122 void remove(
typename map_t::const_iterator it) INLINE_EXPORT
126 if(it != this->m_map.end())
128 m_order.erase(it->second.second);
133 void remove(
const Id<Model>&
id) INLINE_EXPORT { remove(m_map.find(
id)); }
135 void clear() INLINE_EXPORT
146 auto it = this->m_map.find(
id);
147 if(it != this->m_map.end())
149 return score::make_indirect_iterator(
150 (
typename order_t::const_iterator)it->second.second);
154 return score::make_indirect_iterator(this->m_order.end());
158 Element& at(
const Id<Model>&
id)
const INLINE_EXPORT
162 SCORE_ASSERT(
id.m_ptr->parent() == this->m_map.find(
id)->second.first->parent());
163 return safe_cast<Element&>(*
id.m_ptr);
165 auto item = this->m_map.find(
id);
166 SCORE_ASSERT(item != this->m_map.end());
168 id.m_ptr = item->second.first;
169 return safe_cast<Element&>(*item->second.first);
181 using model_type = Model;
182 using map_t = ossia::hash_map<Id<Model>, Element*>;
185 using value_type = Element;
199 for(
const auto& elt : m_map)
207 return score::make_indirect_map_iterator(this->m_map.begin());
217 return score::make_indirect_map_iterator(this->m_map.cbegin());
221 return score::make_indirect_map_iterator(this->m_map.end());
231 return score::make_indirect_map_iterator(this->m_map.cend());
234 OSSIA_INLINE std::size_t size()
const INLINE_EXPORT {
return m_map.size(); }
236 OSSIA_INLINE
bool empty()
const INLINE_EXPORT {
return m_map.empty(); }
238 std::vector<Element*> as_vec()
const INLINE_EXPORT
240 std::vector<Element*> e;
241 e.reserve(m_map.size());
242 for(
auto& [key, val] : m_map)
252 e.reserve(m_map.size());
253 for(
auto& [key, val] : m_map)
260 void insert(value_type* t) INLINE_EXPORT
262 SCORE_ASSERT(m_map.find(t->id()) == m_map.end());
263 m_map.insert({t->id(), t});
266 void remove(
typename map_t::iterator it) INLINE_EXPORT
269 if(it != this->m_map.end())
274 void remove(
typename map_t::const_iterator it) INLINE_EXPORT
277 if(it != this->m_map.end())
283 void remove(
const Id<Model>&
id) INLINE_EXPORT { remove(m_map.find(
id)); }
285 void clear() INLINE_EXPORT
295 auto it = this->m_map.find(
id);
296 if(it != this->m_map.end())
298 return score::make_indirect_map_iterator(it);
302 return score::make_indirect_map_iterator(this->m_map.end());
306 Element& at(
const Id<Model>&
id)
const INLINE_EXPORT
310 SCORE_ASSERT(
id.m_ptr->parent() == this->m_map.find(
id)->second->parent());
311 return safe_cast<Element&>(*
id.m_ptr);
313 auto item = this->m_map.find(
id);
314 SCORE_ASSERT(item != this->m_map.end());
316 id.m_ptr = item->second;
317 return safe_cast<Element&>(*item->second);