summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar guyingzhao2025-02-28 00:17:57 +0800
committerGravatar Nikias Bassen2025-03-01 23:42:06 +0100
commitd40f03e4090edafea75f04a1697ef0384231d333 (patch)
treee3915131a791b3ce5669ee7938ff4eb4f2c5bbba
parent02be84957d44ce68dcf81bada0d3250d4d81395a (diff)
downloadlibplist-d40f03e4090edafea75f04a1697ef0384231d333.tar.gz
libplist-d40f03e4090edafea75f04a1697ef0384231d333.tar.bz2
C++: Add more convenience functions to the interface
-rw-r--r--include/plist/Array.h10
-rw-r--r--include/plist/Dictionary.h7
-rw-r--r--include/plist/Structure.h1
-rw-r--r--src/Structure.cpp10
4 files changed, 24 insertions, 4 deletions
diff --git a/include/plist/Array.h b/include/plist/Array.h
index 0239c78..34ddd6f 100644
--- a/include/plist/Array.h
+++ b/include/plist/Array.h
@@ -57,6 +57,16 @@ public :
57 void Remove(Node* node); 57 void Remove(Node* node);
58 void Remove(unsigned int pos); 58 void Remove(unsigned int pos);
59 unsigned int GetNodeIndex(Node* node) const; 59 unsigned int GetNodeIndex(Node* node) const;
60 template <typename T>
61 T* at(unsigned int index)
62 {
63 return (T*)(_array.at(index));
64 }
65 template <typename T>
66 T* At(unsigned int index)
67 {
68 return (T*)(_array.at(index));
69 }
60 70
61private : 71private :
62 std::vector<Node*> _array; 72 std::vector<Node*> _array;
diff --git a/include/plist/Dictionary.h b/include/plist/Dictionary.h
index 583a430..fc7e558 100644
--- a/include/plist/Dictionary.h
+++ b/include/plist/Dictionary.h
@@ -60,11 +60,14 @@ public :
60 void Remove(Node* node); 60 void Remove(Node* node);
61 void Remove(const std::string& key); 61 void Remove(const std::string& key);
62 std::string GetNodeKey(Node* node); 62 std::string GetNodeKey(Node* node);
63 template <typename T>
64 T* Get(const std::string& key)
65 {
66 return (T*)(_map[key]);
67 }
63 68
64private : 69private :
65 std::map<std::string,Node*> _map; 70 std::map<std::string,Node*> _map;
66
67
68}; 71};
69 72
70}; 73};
diff --git a/include/plist/Structure.h b/include/plist/Structure.h
index eded8b2..d85b17a 100644
--- a/include/plist/Structure.h
+++ b/include/plist/Structure.h
@@ -43,6 +43,7 @@ public :
43 43
44 static Structure* FromXml(const std::string& xml); 44 static Structure* FromXml(const std::string& xml);
45 static Structure* FromBin(const std::vector<char>& bin); 45 static Structure* FromBin(const std::vector<char>& bin);
46 static Structure* FromBin(const char* bin, uint64_t size);
46 47
47protected: 48protected:
48 Structure(Node* parent = NULL); 49 Structure(Node* parent = NULL);
diff --git a/src/Structure.cpp b/src/Structure.cpp
index 670cce6..b33de96 100644
--- a/src/Structure.cpp
+++ b/src/Structure.cpp
@@ -77,7 +77,7 @@ void Structure::UpdateNodeParent(Node* node)
77 if ( NULL != node->_parent ) 77 if ( NULL != node->_parent )
78 { 78 {
79 plist_type type = plist_get_node_type(node->_parent); 79 plist_type type = plist_get_node_type(node->_parent);
80 if (PLIST_ARRAY ==type || PLIST_DICT == type ) 80 if (PLIST_ARRAY == type || PLIST_DICT == type)
81 { 81 {
82 Structure* s = static_cast<Structure*>(node->_parent); 82 Structure* s = static_cast<Structure*>(node->_parent);
83 s->Remove(node); 83 s->Remove(node);
@@ -117,8 +117,14 @@ Structure* Structure::FromBin(const std::vector<char>& bin)
117 plist_from_bin(&bin[0], bin.size(), &root); 117 plist_from_bin(&bin[0], bin.size(), &root);
118 118
119 return ImportStruct(root); 119 return ImportStruct(root);
120}
121
122Structure* Structure::FromBin(const char* bin, uint64_t size)
123{
124 plist_t root = NULL;
125 plist_from_bin(bin, size, &root);
120 126
127 return ImportStruct(root);
121} 128}
122 129
123} // namespace PList 130} // namespace PList
124