17 #include <pia/common/common_definitions.h> 18 #include <pia/common/common_TreeMap.h> 32 template <
typename Key_,
typename Value_>
33 class OffsetTreeMap :
public TreeMap<Key_>
38 typedef TreeMapNode<Key> Node;
45 : TreeMap<Key>(), m_Offset(-1)
55 void InitOffset(s32 offset)
66 TreeMap<Key>::ClearNode();
75 Value* Find(
const Key& key)
const 77 return NodeToValueWithNullCheck(TreeMap<Key>::FindNode(key));
88 Value* Insert(
const Key& key, Value* pValue)
90 return NodeToValueWithNullCheck(TreeMap<Key>::InsertNode(key, ValueToNode(pValue)));
100 Value* Erase(
const Key& key)
102 return NodeToValueWithNullCheck(TreeMap<Key>::EraseNode(key));
111 void Erase(Value* pValue)
113 EraseNode(ValueToNode(pValue));
123 return NodeToValueWithNullCheck(TreeMap<Key>::FrontNode());
133 return NodeToValueWithNullCheck(TreeMap<Key>::BackNode());
143 Value* Prev(
const Value* pValue)
const 145 return NodeToValueWithNullCheck(ValueToNode(pValue)->Prev());
155 Value* Next(
const Value* pValue)
const 157 return NodeToValueWithNullCheck(ValueToNode(pValue)->Next());
166 bool IsInclude(
const Value* pValue)
const 168 return IsIncludeNode(ValueToNode(pValue));
177 friend class OffsetTreeMap;
180 Iterator(
const OffsetTreeMap* pTreeMap, Node* pNode)
181 : m_pTreeMap(pTreeMap), m_pNode(pNode)
183 m_pValue = m_pTreeMap->NodeToValueWithNullCheck(pNode);
187 Iterator& operator++()
189 m_pNode = m_pNode->Next();
190 m_pValue = m_pTreeMap->NodeToValueWithNullCheck(m_pNode);
194 bool operator==(
const Iterator& x)
const 196 return m_pValue == x.m_pValue;
198 bool operator!=(
const Iterator& x)
const 200 return m_pValue != x.m_pValue;
213 const OffsetTreeMap* m_pTreeMap;
224 friend class OffsetTreeMap;
227 ConstIterator(
const OffsetTreeMap* pTreeMap,
const Node* pNode)
228 : m_pTreeMap(pTreeMap), m_pNode(pNode)
230 m_pValue = m_pTreeMap->NodeToValueWithNullCheck(pNode);
234 ConstIterator& operator++()
236 m_pNode = m_pNode->Next();
237 m_pValue = m_pTreeMap->NodeToValueWithNullCheck(m_pNode);
241 bool operator==(
const ConstIterator& x)
const 243 return m_pValue == x.m_pValue;
245 bool operator!=(
const ConstIterator& x)
const 247 return m_pValue != x.m_pValue;
250 const Value& operator*()
254 const Value* operator->()
260 const OffsetTreeMap* m_pTreeMap;
261 const Value* m_pValue;
273 friend class OffsetTreeMap;
276 RobustIterator(
const OffsetTreeMap* pTreeMap, Node* pNode)
277 : m_pTreeMap(pTreeMap)
279 m_pValue = m_pTreeMap->NodeToValueWithNullCheck(pNode);
280 m_pNextNode = (pNode != NULL) ? pNode->Next() : NULL;
284 RobustIterator& operator++()
286 if (m_pNextNode != NULL)
288 m_pValue = m_pTreeMap->NodeToValue(m_pNextNode);
289 m_pNextNode = m_pNextNode->Next();
298 bool operator==(
const RobustIterator& x)
const 300 return m_pValue == x.m_pValue;
302 bool operator!=(
const RobustIterator& x)
const 304 return m_pValue != x.m_pValue;
317 const OffsetTreeMap* m_pTreeMap;
328 Iterator Begin()
const 330 return Iterator(
this, TreeMap<Key>::FrontNode());
341 return Iterator(
this, NULL);
350 Iterator LowerBound(
const Key& key)
const 352 return Iterator(
this, TreeMap<Key>::LowerBoundNode(key));
361 ConstIterator ConstBegin()
const 363 return ConstIterator(
this, TreeMap<Key>::FrontNode());
372 ConstIterator ConstEnd()
const 374 return ConstIterator(
this, NULL);
383 ConstIterator ConstLowerBound(
const Key& key)
const 385 return ConstIterator(
this, TreeMap<Key>::LowerBoundNode(key));
394 RobustIterator RobustBegin()
const 396 return RobustIterator(
this, TreeMap<Key>::FrontNode());
405 RobustIterator RobustEnd()
const 407 return RobustIterator(
this, NULL);
416 RobustIterator RobustLowerBound(
const Key& key)
const 418 return RobustIterator(
this, TreeMap<Key>::LowerBoundNode(key));
424 Node* ValueToNode(
const Value* pObj)
const 426 return reinterpret_cast<Node*
>((
reinterpret_cast<u32
>(pObj)) + m_Offset);
429 Value* NodeToValue(
const Node* pNode)
const 431 return reinterpret_cast<Value*
>((
reinterpret_cast<u32
>(pNode)) - m_Offset);
434 Value* NodeToValueWithNullCheck(
const Node* pNode)
const 437 return reinterpret_cast<Value*
>((
reinterpret_cast<u32
>(pNode)) - m_Offset);