diff options
| -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 : | |||
| 44 | void Insert(Node* node, unsigned int pos); | 44 | void Insert(Node* node, unsigned int pos); |
| 45 | void Remove(Node* node); | 45 | void Remove(Node* node); |
| 46 | void Remove(unsigned int pos); | 46 | void Remove(unsigned int pos); |
| 47 | unsigned int GetNodeIndex(Node* node); | ||
| 47 | 48 | ||
| 48 | private : | 49 | private : |
| 49 | std::vector<Node*> _array; | 50 | 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 : | |||
| 49 | iterator Insert(const std::string& key, Node* node); | 49 | iterator Insert(const std::string& key, Node* node); |
| 50 | void Remove(Node* node); | 50 | void Remove(Node* node); |
| 51 | void Remove(const std::string& key); | 51 | void Remove(const std::string& key); |
| 52 | std::string GetNodeKey(Node* key); | ||
| 52 | 53 | ||
| 53 | private : | 54 | private : |
| 54 | std::map<std::string,Node*> _map; | 55 | 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 @@ | |||
| 22 | #include <plist/Array.h> | 22 | #include <plist/Array.h> |
| 23 | #include <plist/Utils.h> | 23 | #include <plist/Utils.h> |
| 24 | 24 | ||
| 25 | #include <algorithm> | ||
| 26 | |||
| 25 | namespace PList | 27 | namespace PList |
| 26 | { | 28 | { |
| 27 | 29 | ||
| @@ -140,4 +142,10 @@ void Array::Remove(unsigned int pos) | |||
| 140 | _array.erase(it); | 142 | _array.erase(it); |
| 141 | } | 143 | } |
| 142 | 144 | ||
| 145 | unsigned int Array::GetNodeIndex(Node* node) | ||
| 146 | { | ||
| 147 | std::vector<Node*>::iterator it = std::find(_array.begin(), _array.end(), node); | ||
| 148 | return std::distance (_array.begin(), it); | ||
| 149 | } | ||
| 150 | |||
| 143 | }; | 151 | }; |
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) | |||
| 177 | _map.erase(key); | 177 | _map.erase(key); |
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | std::string Dictionary::GetNodeKey(Node* node) | ||
| 181 | { | ||
| 182 | for (iterator it = _map.begin(); it != _map.end(); ++it) | ||
| 183 | { | ||
| 184 | if (it->second == node) | ||
| 185 | return it->first; | ||
| 186 | } | ||
| 187 | return ""; | ||
| 188 | } | ||
| 189 | |||
| 180 | }; | 190 | }; |
