diff options
Diffstat (limited to 'include/plist')
| -rw-r--r-- | include/plist/Array.h | 19 | ||||
| -rw-r--r-- | include/plist/Data.h | 7 | ||||
| -rw-r--r-- | include/plist/Date.h | 6 | ||||
| -rw-r--r-- | include/plist/Dictionary.h | 5 | ||||
| -rw-r--r-- | include/plist/String.h | 3 | ||||
| -rw-r--r-- | include/plist/Structure.h | 3 | ||||
| -rw-r--r-- | include/plist/plist.h | 94 |
7 files changed, 108 insertions, 29 deletions
diff --git a/include/plist/Array.h b/include/plist/Array.h index 0239c78..f4360c5 100644 --- a/include/plist/Array.h +++ b/include/plist/Array.h @@ -43,6 +43,10 @@ public : typedef std::vector<Node*>::const_iterator const_iterator; Node* operator[](unsigned int index); + Node* Back(); + Node* back(); + Node* Front(); + Node* front(); iterator Begin(); iterator begin(); iterator End(); @@ -52,11 +56,20 @@ 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; + 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) { + return (T*)(_array.at(index)); + } private : std::vector<Node*> _array; diff --git a/include/plist/Data.h b/include/plist/Data.h index 3f1c329..1de88aa 100644 --- a/include/plist/Data.h +++ b/include/plist/Data.h @@ -35,13 +35,14 @@ public : Data(plist_t node, Node* parent = NULL); Data(const Data& d); Data& operator=(const Data& b); - Data(const std::vector<uint8_t>& buff); + Data(const std::vector<char>& buff); + Data(const char* buff, uint64_t size); virtual ~Data(); Node* Clone() const; - void SetValue(const std::vector<uint8_t>& buff); - std::vector<uint8_t> GetValue() const; + void SetValue(const std::vector<char>& buff); + std::vector<char> GetValue() const; }; }; diff --git a/include/plist/Date.h b/include/plist/Date.h index 5113cf3..7026699 100644 --- a/include/plist/Date.h +++ b/include/plist/Date.h @@ -40,13 +40,13 @@ public : Date(plist_t node, Node* parent = NULL); Date(const Date& d); Date& operator=(const Date& d); - Date(timeval t); + Date(int64_t t); virtual ~Date(); Node* Clone() const; - void SetValue(timeval t); - timeval GetValue() const; + void SetValue(int64_t t); + int64_t GetValue() const; }; }; diff --git a/include/plist/Dictionary.h b/include/plist/Dictionary.h index 583a430..37ff1c9 100644 --- a/include/plist/Dictionary.h +++ b/include/plist/Dictionary.h @@ -60,11 +60,12 @@ 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/String.h b/include/plist/String.h index 9aba16b..95f8dd1 100644 --- a/include/plist/String.h +++ b/include/plist/String.h @@ -35,7 +35,10 @@ public : String(plist_t node, Node* parent = NULL); String(const String& s); String& operator=(const String& s); + String& operator=(const std::string& s); + String& operator=(const char* s); String(const std::string& s); + String(const char *s); virtual ~String(); Node* Clone() const; diff --git a/include/plist/Structure.h b/include/plist/Structure.h index eded8b2..b7fbdb5 100644 --- a/include/plist/Structure.h +++ b/include/plist/Structure.h @@ -43,6 +43,9 @@ 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); + static Structure* FromMemory(const std::vector<char>& buf, plist_format_t* format = NULL); + static Structure* FromMemory(const char* buf, uint64_t size, plist_format_t* format = NULL); protected: Structure(Node* parent = NULL); diff --git a/include/plist/plist.h b/include/plist/plist.h index 7d5b4cb..41af8ce 100644 --- a/include/plist/plist.h +++ b/include/plist/plist.h @@ -258,17 +258,16 @@ extern "C" * @return the created item * @sa #plist_type */ - PLIST_API plist_t plist_new_data(const uint8_t *val, uint64_t length); + PLIST_API plist_t plist_new_data(const char *val, uint64_t length); /** * Create a new plist_t type #PLIST_DATE * - * @param sec the number of seconds since 01/01/2001 - * @param usec the number of microseconds + * @param sec The number of seconds since 01/01/1970 (UNIX timestamp) * @return the created item * @sa #plist_type */ - PLIST_API plist_t plist_new_date(int32_t sec, int32_t usec); + PLIST_API plist_t plist_new_unix_date(int64_t sec); /** * Create a new plist_t type #PLIST_UID @@ -445,7 +444,7 @@ extern "C" PLIST_API void plist_dict_get_item_key(plist_t node, char **key); /** - * Get the item for given key in a #PLIST_DICT node. + * Get the nth item in a #PLIST_DICT node. * * @param node the node of type #PLIST_DICT * @param key the identifier of the item to get. @@ -755,7 +754,7 @@ extern "C" * @param length the length of the buffer * @note Use plist_mem_free() to free the allocated memory. */ - PLIST_API void plist_get_data_val(plist_t node, uint8_t **val, uint64_t * length); + PLIST_API void plist_get_data_val(plist_t node, char **val, uint64_t * length); /** * Get a pointer to the data buffer of a #PLIST_DATA node. @@ -768,17 +767,16 @@ extern "C" * * @return Pointer to the buffer */ - PLIST_API const uint8_t* plist_get_data_ptr(plist_t node, uint64_t* length); + PLIST_API const char* plist_get_data_ptr(plist_t node, uint64_t* length); /** * Get the value of a #PLIST_DATE node. * This function does nothing if node is not of type #PLIST_DATE * * @param node the node - * @param sec a pointer to an int32_t variable. Represents the number of seconds since 01/01/2001. - * @param usec a pointer to an int32_t variable. Represents the number of microseconds + * @param sec a pointer to an int64_t variable. Represents the number of seconds since 01/01/1970 (UNIX timestamp). */ - PLIST_API void plist_get_date_val(plist_t node, int32_t * sec, int32_t * usec); + PLIST_API void plist_get_unix_date_val(plist_t node, int64_t *sec); /** * Get the value of a #PLIST_UID node. @@ -860,17 +858,16 @@ extern "C" * be freed by the node. * @param length the length of the buffer */ - PLIST_API void plist_set_data_val(plist_t node, const uint8_t *val, uint64_t length); + PLIST_API void plist_set_data_val(plist_t node, const char *val, uint64_t length); /** * Set the value of a node. * Forces type of node to #PLIST_DATE * * @param node the node - * @param sec the number of seconds since 01/01/2001 - * @param usec the number of microseconds + * @param sec the number of seconds since 01/01/1970 (UNIX timestamp) */ - PLIST_API void plist_set_date_val(plist_t node, int32_t sec, int32_t usec); + PLIST_API void plist_set_unix_date_val(plist_t node, int64_t sec); /** * Set the value of a node. @@ -1213,16 +1210,15 @@ extern "C" /** * Helper function to compare the value of a PLIST_DATE node against - * a given set of seconds and fraction of a second since epoch. + * a given number of seconds since epoch (UNIX timestamp). * * @param datenode node of type PLIST_DATE - * @param cmpsec number of seconds since epoch to compare against - * @param cmpusec fraction of a second in microseconds to compare against + * @param cmpval Number of seconds to compare against (UNIX timestamp) * @return 0 if the node's date is equal to the supplied values, * 1 if the node's date is greater than the supplied values, * or -1 if the node's date is less than the supplied values. */ - PLIST_API int plist_date_val_compare(plist_t datenode, int32_t cmpsec, int32_t cmpusec); + PLIST_API int plist_unix_date_val_compare(plist_t datenode, int64_t cmpval); /** * Helper function to compare the value of a PLIST_STRING node against @@ -1382,6 +1378,68 @@ extern "C" */ PLIST_API const char* libplist_version(); + + /******************************************** + * * + * Deprecated API * + * * + ********************************************/ + + /** + * Create a new plist_t type #PLIST_DATE + * + * @deprecated Deprecated. Use plist_new_unix_date instead. + * + * @param sec the number of seconds since 01/01/2001 + * @param usec the number of microseconds + * @return the created item + * @sa #plist_type + */ + PLIST_WARN_DEPRECATED("use plist_new_unix_date instead") + PLIST_API plist_t plist_new_date(int32_t sec, int32_t usec); + + /** + * Get the value of a #PLIST_DATE node. + * This function does nothing if node is not of type #PLIST_DATE + * + * @deprecated Deprecated. Use plist_get_unix_date_val instead. + * + * @param node the node + * @param sec a pointer to an int32_t variable. Represents the number of seconds since 01/01/2001. + * @param usec a pointer to an int32_t variable. Represents the number of microseconds + */ + PLIST_WARN_DEPRECATED("use plist_get_unix_date_val instead") + PLIST_API void plist_get_date_val(plist_t node, int32_t * sec, int32_t * usec); + + /** + * Set the value of a node. + * Forces type of node to #PLIST_DATE + * + * @deprecated Deprecated. Use plist_set_unix_date_val instead. + * + * @param node the node + * @param sec the number of seconds since 01/01/2001 + * @param usec the number of microseconds + */ + PLIST_WARN_DEPRECATED("use plist_set_unix_date_val instead") + PLIST_API void plist_set_date_val(plist_t node, int32_t sec, int32_t usec); + + /** + * Helper function to compare the value of a PLIST_DATE node against + * a given set of seconds and fraction of a second since epoch. + * + * @deprecated Deprecated. Use plist_unix_date_val_compare instead. + * + * @param datenode node of type PLIST_DATE + * @param cmpsec number of seconds since epoch to compare against + * @param cmpusec fraction of a second in microseconds to compare against + * @return 0 if the node's date is equal to the supplied values, + * 1 if the node's date is greater than the supplied values, + * or -1 if the node's date is less than the supplied values. + */ + PLIST_WARN_DEPRECATED("use plist_unix_date_val_compare instead") + PLIST_API int plist_date_val_compare(plist_t datenode, int32_t cmpsec, int32_t cmpusec); + /*@}*/ #ifdef __cplusplus |
