summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/plist/Array.h17
-rw-r--r--src/Array.cpp21
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 :
52 const_iterator End() const; 52 const_iterator End() const;
53 const_iterator end() const; 53 const_iterator end() const;
54 size_t size() const; 54 size_t size() const;
55 void Append(Node* node); 55 void Append(const Node& node);
56 void Insert(Node* node, unsigned int pos); 56 void Append(const Node* node);
57 void Insert(const Node& node, unsigned int pos);
58 void Insert(const Node* node, unsigned int pos);
57 void Remove(Node* node); 59 void Remove(Node* node);
58 void Remove(unsigned int pos); 60 void Remove(unsigned int pos);
59 unsigned int GetNodeIndex(Node* node) const; 61 unsigned int GetNodeIndex(const Node& node) const;
60 template <typename T> 62 unsigned int GetNodeIndex(const Node* node) const;
61 T* at(unsigned int index) 63 template <typename T> T* at(unsigned int index) {
62 {
63 return (T*)(_array.at(index)); 64 return (T*)(_array.at(index));
64 } 65 }
65 template <typename T> 66 template <typename T> T* At(unsigned int index) {
66 T* At(unsigned int index)
67 {
68 return (T*)(_array.at(index)); 67 return (T*)(_array.at(index));
69 } 68 }
70 69
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 {
134 return _array.size(); 134 return _array.size();
135} 135}
136 136
137void Array::Append(Node* node) 137void Array::Append(const Node* node)
138{ 138{
139 if (node) 139 if (node)
140 { 140 {
@@ -145,7 +145,12 @@ void Array::Append(Node* node)
145 } 145 }
146} 146}
147 147
148void Array::Insert(Node* node, unsigned int pos) 148void Array::Append(const Node& node)
149{
150 Append(&node);
151}
152
153void Array::Insert(const Node* node, unsigned int pos)
149{ 154{
150 if (node) 155 if (node)
151 { 156 {
@@ -158,6 +163,11 @@ void Array::Insert(Node* node, unsigned int pos)
158 } 163 }
159} 164}
160 165
166void Array::Insert(const Node &node, unsigned int pos)
167{
168 Insert(&node, pos);
169}
170
161void Array::Remove(Node* node) 171void Array::Remove(Node* node)
162{ 172{
163 if (node) 173 if (node)
@@ -183,10 +193,15 @@ void Array::Remove(unsigned int pos)
183 _array.erase(it); 193 _array.erase(it);
184} 194}
185 195
186unsigned int Array::GetNodeIndex(Node* node) const 196unsigned int Array::GetNodeIndex(const Node* node) const
187{ 197{
188 std::vector<Node*>::const_iterator it = std::find(_array.begin(), _array.end(), node); 198 std::vector<Node*>::const_iterator it = std::find(_array.begin(), _array.end(), node);
189 return std::distance (_array.begin(), it); 199 return std::distance (_array.begin(), it);
190} 200}
191 201
202unsigned int Array::GetNodeIndex(const Node& node) const
203{
204 return GetNodeIndex(&node);
205}
206
192} // namespace PList 207} // namespace PList