diff options
-rw-r--r-- | include/plist/Array.h | 17 | ||||
-rw-r--r-- | src/Array.cpp | 21 |
2 files changed, 26 insertions, 12 deletions
diff --git a/include/plist/Array.h b/include/plist/Array.h index 34ddd6f..949fa4c 100644 --- a/include/plist/Array.h +++ b/include/plist/Array.h @@ -52,19 +52,18 @@ public : const_iterator End() const; const_iterator end() const; size_t size() const; - void Append(Node* node); - void Insert(Node* node, unsigned int pos); + void Append(const Node& node); + void Append(const Node* node); + void Insert(const Node& node, unsigned int pos); + void Insert(const Node* node, unsigned int pos); void Remove(Node* node); void Remove(unsigned int pos); - unsigned int GetNodeIndex(Node* node) const; - template <typename T> - T* at(unsigned int index) - { + unsigned int GetNodeIndex(const Node& node) const; + unsigned int GetNodeIndex(const Node* node) const; + template <typename T> T* at(unsigned int index) { return (T*)(_array.at(index)); } - template <typename T> - T* At(unsigned int index) - { + template <typename T> T* At(unsigned int index) { return (T*)(_array.at(index)); } diff --git a/src/Array.cpp b/src/Array.cpp index 7051ed9..de1259e 100644 --- a/src/Array.cpp +++ b/src/Array.cpp @@ -134,7 +134,7 @@ size_t Array::size() const { return _array.size(); } -void Array::Append(Node* node) +void Array::Append(const Node* node) { if (node) { @@ -145,7 +145,12 @@ void Array::Append(Node* node) } } -void Array::Insert(Node* node, unsigned int pos) +void Array::Append(const Node& node) +{ + Append(&node); +} + +void Array::Insert(const Node* node, unsigned int pos) { if (node) { @@ -158,6 +163,11 @@ void Array::Insert(Node* node, unsigned int pos) } } +void Array::Insert(const Node &node, unsigned int pos) +{ + Insert(&node, pos); +} + void Array::Remove(Node* node) { if (node) @@ -183,10 +193,15 @@ void Array::Remove(unsigned int pos) _array.erase(it); } -unsigned int Array::GetNodeIndex(Node* node) const +unsigned int Array::GetNodeIndex(const Node* node) const { std::vector<Node*>::const_iterator it = std::find(_array.begin(), _array.end(), node); return std::distance (_array.begin(), it); } +unsigned int Array::GetNodeIndex(const Node& node) const +{ + return GetNodeIndex(&node); +} + } // namespace PList |