diff options
author | Jonathan Beck | 2009-11-04 20:21:54 +0100 |
---|---|---|
committer | Jonathan Beck | 2009-11-04 20:21:54 +0100 |
commit | 84596548e5d0cb14dfd7d2a74156331ab36a8909 (patch) | |
tree | a98e7aeeb8864a946aaf52dc022af4bb8d381dda | |
parent | c8c9cfa77f0c0fdb895dfdbfc177db3c26dcedcc (diff) | |
download | libplist-84596548e5d0cb14dfd7d2a74156331ab36a8909.tar.gz libplist-84596548e5d0cb14dfd7d2a74156331ab36a8909.tar.bz2 |
Add GetNodeIdex and GetNodeKey methods.
-rw-r--r-- | include/plist/Array.h | 1 | ||||
-rw-r--r-- | include/plist/Dictionary.h | 1 | ||||
-rw-r--r-- | src/Array.cpp | 8 | ||||
-rw-r--r-- | src/Dictionary.cpp | 10 |
4 files changed, 20 insertions, 0 deletions
diff --git a/include/plist/Array.h b/include/plist/Array.h index b81e6b1..fd4dea8 100644 --- a/include/plist/Array.h +++ b/include/plist/Array.h @@ -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; diff --git a/include/plist/Dictionary.h b/include/plist/Dictionary.h index e43d29e..a937bde 100644 --- a/include/plist/Dictionary.h +++ b/include/plist/Dictionary.h @@ -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; diff --git a/src/Array.cpp b/src/Array.cpp index bdd26e1..a847ae2 100644 --- a/src/Array.cpp +++ b/src/Array.cpp @@ -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); +} + }; diff --git a/src/Dictionary.cpp b/src/Dictionary.cpp index fedce2e..62ed433 100644 --- a/src/Dictionary.cpp +++ b/src/Dictionary.cpp @@ -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 ""; +} + }; |