summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar guyingzhao2025-04-06 12:18:23 +0200
committerGravatar Nikias Bassen2025-04-06 12:18:23 +0200
commite6f3c6c62111b37cc97db2d61a1c765695ee401a (patch)
treeea39e49b6587443d070a0edeccef6c8dffe35c8e
parented8a73301b844bf5f7efd9cd437c9c0765a49a88 (diff)
downloadlibplist-e6f3c6c62111b37cc97db2d61a1c765695ee401a.tar.gz
libplist-e6f3c6c62111b37cc97db2d61a1c765695ee401a.tar.bz2
C++: Array: Add const Node& variants to Append, Insert
-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 :
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