Commit 84596548 authored by Jonathan Beck's avatar Jonathan Beck

Add GetNodeIdex and GetNodeKey methods.

parent c8c9cfa7
......@@ -44,6 +44,7 @@ public :
void Insert(Node* node, unsigned int pos);
void Remove(Node* node);
void Remove(unsigned int pos);
unsigned int GetNodeIndex(Node* node);
private :
std::vector<Node*> _array;
......
......@@ -49,6 +49,7 @@ public :
iterator Insert(const std::string& key, Node* node);
void Remove(Node* node);
void Remove(const std::string& key);
std::string GetNodeKey(Node* key);
private :
std::map<std::string,Node*> _map;
......
......@@ -22,6 +22,8 @@
#include <plist/Array.h>
#include <plist/Utils.h>
#include <algorithm>
namespace PList
{
......@@ -140,4 +142,10 @@ void Array::Remove(unsigned int pos)
_array.erase(it);
}
unsigned int Array::GetNodeIndex(Node* node)
{
std::vector<Node*>::iterator it = std::find(_array.begin(), _array.end(), node);
return std::distance (_array.begin(), it);
}
};
......@@ -177,4 +177,14 @@ void Dictionary::Remove(const std::string& key)
_map.erase(key);
}
std::string Dictionary::GetNodeKey(Node* node)
{
for (iterator it = _map.begin(); it != _map.end(); ++it)
{
if (it->second == node)
return it->first;
}
return "";
}
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment