diff options
author | 2025-02-28 00:17:57 +0800 | |
---|---|---|
committer | 2025-03-01 23:42:06 +0100 | |
commit | d40f03e4090edafea75f04a1697ef0384231d333 (patch) | |
tree | e3915131a791b3ce5669ee7938ff4eb4f2c5bbba | |
parent | 02be84957d44ce68dcf81bada0d3250d4d81395a (diff) | |
download | libplist-d40f03e4090edafea75f04a1697ef0384231d333.tar.gz libplist-d40f03e4090edafea75f04a1697ef0384231d333.tar.bz2 |
C++: Add more convenience functions to the interface
-rw-r--r-- | include/plist/Array.h | 10 | ||||
-rw-r--r-- | include/plist/Dictionary.h | 7 | ||||
-rw-r--r-- | include/plist/Structure.h | 1 | ||||
-rw-r--r-- | src/Structure.cpp | 10 |
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 : void Remove(Node* node); void Remove(unsigned int pos); unsigned int GetNodeIndex(Node* node) const; + template <typename T> + T* at(unsigned int index) + { + return (T*)(_array.at(index)); + } + template <typename T> + T* At(unsigned int index) + { + return (T*)(_array.at(index)); + } private : 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 : void Remove(Node* node); void Remove(const std::string& key); std::string GetNodeKey(Node* node); + template <typename T> + T* Get(const std::string& key) + { + return (T*)(_map[key]); + } private : std::map<std::string,Node*> _map; - - }; }; 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 : static Structure* FromXml(const std::string& xml); static Structure* FromBin(const std::vector<char>& bin); + static Structure* FromBin(const char* bin, uint64_t size); protected: 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) if ( NULL != node->_parent ) { plist_type type = plist_get_node_type(node->_parent); - if (PLIST_ARRAY ==type || PLIST_DICT == type ) + if (PLIST_ARRAY == type || PLIST_DICT == type) { Structure* s = static_cast<Structure*>(node->_parent); s->Remove(node); @@ -117,8 +117,14 @@ Structure* Structure::FromBin(const std::vector<char>& bin) plist_from_bin(&bin[0], bin.size(), &root); return ImportStruct(root); +} + +Structure* Structure::FromBin(const char* bin, uint64_t size) +{ + plist_t root = NULL; + plist_from_bin(bin, size, &root); + return ImportStruct(root); } } // namespace PList - |