From d40f03e4090edafea75f04a1697ef0384231d333 Mon Sep 17 00:00:00 2001 From: guyingzhao Date: Fri, 28 Feb 2025 00:17:57 +0800 Subject: C++: Add more convenience functions to the interface --- include/plist/Array.h | 10 ++++++++++ include/plist/Dictionary.h | 7 +++++-- include/plist/Structure.h | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) (limited to 'include/plist') 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 + T* at(unsigned int index) + { + return (T*)(_array.at(index)); + } + template + T* At(unsigned int index) + { + return (T*)(_array.at(index)); + } private : std::vector _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 + T* Get(const std::string& key) + { + return (T*)(_map[key]); + } private : std::map _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& bin); + static Structure* FromBin(const char* bin, uint64_t size); protected: Structure(Node* parent = NULL); -- cgit v1.1-32-gdbae