diff options
| author | 2009-10-13 20:04:06 +0200 | |
|---|---|---|
| committer | 2009-10-13 20:04:06 +0200 | |
| commit | a922b714c9b75fdc67735d674758d4eaedfd32f9 (patch) | |
| tree | 509ec53c18c0be36a9e650eb0f760854cd8d4957 | |
| parent | e492ef675c404cc6c0d1cfa26e47a1c16c850d5f (diff) | |
| download | libplist-a922b714c9b75fdc67735d674758d4eaedfd32f9.tar.gz libplist-a922b714c9b75fdc67735d674758d4eaedfd32f9.tar.bz2 | |
Add C++ binding.
| -rw-r--r-- | include/plist/Array.h | 52 | ||||
| -rw-r--r-- | include/plist/Boolean.h | 43 | ||||
| -rw-r--r-- | include/plist/Data.h | 44 | ||||
| -rw-r--r-- | include/plist/Date.h | 43 | ||||
| -rw-r--r-- | include/plist/Dictionary.h | 58 | ||||
| -rw-r--r-- | include/plist/Integer.h | 43 | ||||
| -rw-r--r-- | include/plist/Node.h | 49 | ||||
| -rw-r--r-- | include/plist/Real.h | 43 | ||||
| -rw-r--r-- | include/plist/String.h | 44 | ||||
| -rw-r--r-- | include/plist/Structure.h | 53 | ||||
| -rw-r--r-- | include/plist/Utils.h | 42 | ||||
| -rw-r--r-- | include/plist/plist++.h | 38 | ||||
| -rw-r--r-- | src/Array.cpp | 194 | ||||
| -rw-r--r-- | src/Boolean.cpp | 52 | ||||
| -rw-r--r-- | src/CMakeLists.txt | 17 | ||||
| -rw-r--r-- | src/Data.cpp | 57 | ||||
| -rw-r--r-- | src/Date.cpp | 52 | ||||
| -rw-r--r-- | src/Dictionary.cpp | 217 | ||||
| -rw-r--r-- | src/Integer.cpp | 52 | ||||
| -rw-r--r-- | src/Node.cpp | 105 | ||||
| -rw-r--r-- | src/Real.cpp | 52 | ||||
| -rw-r--r-- | src/String.cpp | 54 | ||||
| -rw-r--r-- | src/Structure.cpp | 74 | ||||
| -rw-r--r-- | src/Utils.cpp | 74 |
24 files changed, 1552 insertions, 0 deletions
diff --git a/include/plist/Array.h b/include/plist/Array.h new file mode 100644 index 0000000..8f8d992 --- /dev/null +++ b/include/plist/Array.h | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | /* | ||
| 2 | * Array.h | ||
| 3 | * Array node type for C++ binding | ||
| 4 | * | ||
| 5 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #ifndef STRING_H | ||
| 23 | #define STRING_H | ||
| 24 | |||
| 25 | #include <plist/Structure.h> | ||
| 26 | #include <vector> | ||
| 27 | |||
| 28 | namespace PList | ||
| 29 | { | ||
| 30 | |||
| 31 | class Array : public Structure | ||
| 32 | { | ||
| 33 | public : | ||
| 34 | Array(); | ||
| 35 | Array(plist_t node); | ||
| 36 | Array(Array& a); | ||
| 37 | Array& operator=(const Array& a); | ||
| 38 | virtual ~Array(); | ||
| 39 | |||
| 40 | Node* operator[](unsigned int index); | ||
| 41 | void Append(Node* node); | ||
| 42 | void Insert(Node* node, unsigned int pos); | ||
| 43 | void Remove(Node* node); | ||
| 44 | void Remove(unsigned int pos); | ||
| 45 | |||
| 46 | private : | ||
| 47 | std::vector<Node*> _array; | ||
| 48 | }; | ||
| 49 | |||
| 50 | }; | ||
| 51 | |||
| 52 | #endif // STRING_H | ||
diff --git a/include/plist/Boolean.h b/include/plist/Boolean.h new file mode 100644 index 0000000..89761ca --- /dev/null +++ b/include/plist/Boolean.h | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | /* | ||
| 2 | * Boolean.h | ||
| 3 | * Boolean node type for C++ binding | ||
| 4 | * | ||
| 5 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #ifndef BOOLEAN_H | ||
| 23 | #define BOOLEAN_H | ||
| 24 | |||
| 25 | #include <plist/Node.h> | ||
| 26 | |||
| 27 | namespace PList | ||
| 28 | { | ||
| 29 | |||
| 30 | class Boolean : public Node | ||
| 31 | { | ||
| 32 | public : | ||
| 33 | Boolean(); | ||
| 34 | Boolean(bool b); | ||
| 35 | virtual ~Boolean(); | ||
| 36 | |||
| 37 | void SetValue(bool b); | ||
| 38 | bool GetValue(); | ||
| 39 | }; | ||
| 40 | |||
| 41 | }; | ||
| 42 | |||
| 43 | #endif // BOOLEAN_H | ||
diff --git a/include/plist/Data.h b/include/plist/Data.h new file mode 100644 index 0000000..f7e5cd2 --- /dev/null +++ b/include/plist/Data.h | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | /* | ||
| 2 | * Data.h | ||
| 3 | * Data node type for C++ binding | ||
| 4 | * | ||
| 5 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #ifndef DATA_H | ||
| 23 | #define DATA_H | ||
| 24 | |||
| 25 | #include <plist/Node.h> | ||
| 26 | #include <vector> | ||
| 27 | |||
| 28 | namespace PList | ||
| 29 | { | ||
| 30 | |||
| 31 | class Data : public Node | ||
| 32 | { | ||
| 33 | public : | ||
| 34 | Data(); | ||
| 35 | Data(std::vector<char>& buff); | ||
| 36 | virtual ~Data(); | ||
| 37 | |||
| 38 | void SetValue(std::vector<char>& buff); | ||
| 39 | std::vector<char> GetValue(); | ||
| 40 | }; | ||
| 41 | |||
| 42 | }; | ||
| 43 | |||
| 44 | #endif // DATA_H | ||
diff --git a/include/plist/Date.h b/include/plist/Date.h new file mode 100644 index 0000000..df185db --- /dev/null +++ b/include/plist/Date.h | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | /* | ||
| 2 | * Date.h | ||
| 3 | * Date node type for C++ binding | ||
| 4 | * | ||
| 5 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #ifndef DATE_H | ||
| 23 | #define DATE_H | ||
| 24 | |||
| 25 | #include <plist/Node.h> | ||
| 26 | |||
| 27 | namespace PList | ||
| 28 | { | ||
| 29 | |||
| 30 | class Date : public Node | ||
| 31 | { | ||
| 32 | public : | ||
| 33 | Date(); | ||
| 34 | Date(uint64_t i); | ||
| 35 | virtual ~Date(); | ||
| 36 | |||
| 37 | void SetValue(uint64_t i); | ||
| 38 | uint64_t GetValue(); | ||
| 39 | }; | ||
| 40 | |||
| 41 | }; | ||
| 42 | |||
| 43 | #endif // DATE_H | ||
diff --git a/include/plist/Dictionary.h b/include/plist/Dictionary.h new file mode 100644 index 0000000..8468ab5 --- /dev/null +++ b/include/plist/Dictionary.h | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | /* | ||
| 2 | * Dictionary.h | ||
| 3 | * Dictionary node type for C++ binding | ||
| 4 | * | ||
| 5 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #ifndef DICTIONARY_H | ||
| 23 | #define DICTIONARY_H | ||
| 24 | |||
| 25 | #include <plist/Structure.h> | ||
| 26 | #include <map> | ||
| 27 | #include <string> | ||
| 28 | |||
| 29 | namespace PList | ||
| 30 | { | ||
| 31 | |||
| 32 | class Dictionary : public Structure | ||
| 33 | { | ||
| 34 | public : | ||
| 35 | Dictionary(); | ||
| 36 | Dictionary(plist_t node); | ||
| 37 | Dictionary(Dictionary& d); | ||
| 38 | Dictionary& operator=(const Dictionary& d); | ||
| 39 | virtual ~Dictionary(); | ||
| 40 | |||
| 41 | typedef std::map<std::string,Node*>::iterator iterator; | ||
| 42 | |||
| 43 | Node* operator[](std::string& key); | ||
| 44 | iterator Begin(); | ||
| 45 | iterator End(); | ||
| 46 | void Insert(std::string& key, Node* node); | ||
| 47 | void Remove(Node* node); | ||
| 48 | void Remove(std::string& key); | ||
| 49 | |||
| 50 | private : | ||
| 51 | std::map<std::string,Node*> _map; | ||
| 52 | |||
| 53 | |||
| 54 | }; | ||
| 55 | |||
| 56 | }; | ||
| 57 | |||
| 58 | #endif // DICTIONARY_H | ||
diff --git a/include/plist/Integer.h b/include/plist/Integer.h new file mode 100644 index 0000000..8f1ecdb --- /dev/null +++ b/include/plist/Integer.h | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | /* | ||
| 2 | * Integer.h | ||
| 3 | * Integer node type for C++ binding | ||
| 4 | * | ||
| 5 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #ifndef INTEGER_H | ||
| 23 | #define INTEGER_H | ||
| 24 | |||
| 25 | #include <plist/Node.h> | ||
| 26 | |||
| 27 | namespace PList | ||
| 28 | { | ||
| 29 | |||
| 30 | class Integer : public Node | ||
| 31 | { | ||
| 32 | public : | ||
| 33 | Integer(); | ||
| 34 | Integer(uint64_t i); | ||
| 35 | virtual ~Integer(); | ||
| 36 | |||
| 37 | void SetValue(uint64_t i); | ||
| 38 | uint64_t GetValue(); | ||
| 39 | }; | ||
| 40 | |||
| 41 | }; | ||
| 42 | |||
| 43 | #endif // INTEGER_H | ||
diff --git a/include/plist/Node.h b/include/plist/Node.h new file mode 100644 index 0000000..0f6100e --- /dev/null +++ b/include/plist/Node.h | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | /* | ||
| 2 | * Node.h | ||
| 3 | * Abstract node type for C++ binding | ||
| 4 | * | ||
| 5 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #ifndef NODE_H | ||
| 23 | #define NODE_H | ||
| 24 | |||
| 25 | #include <plist/plist.h> | ||
| 26 | |||
| 27 | namespace PList | ||
| 28 | { | ||
| 29 | |||
| 30 | class Node | ||
| 31 | { | ||
| 32 | public : | ||
| 33 | virtual ~Node(); | ||
| 34 | Node(plist_t node); | ||
| 35 | Node(Node& node); | ||
| 36 | Node& operator=(const Node& node); | ||
| 37 | |||
| 38 | plist_type GetType(); | ||
| 39 | plist_t GetPlist() const; | ||
| 40 | |||
| 41 | protected: | ||
| 42 | Node(); | ||
| 43 | Node(plist_type type); | ||
| 44 | plist_t _node; | ||
| 45 | }; | ||
| 46 | |||
| 47 | }; | ||
| 48 | |||
| 49 | #endif // NODE_H | ||
diff --git a/include/plist/Real.h b/include/plist/Real.h new file mode 100644 index 0000000..272f431 --- /dev/null +++ b/include/plist/Real.h | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | /* | ||
| 2 | * Real.h | ||
| 3 | * Real node type for C++ binding | ||
| 4 | * | ||
| 5 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #ifndef REAL_H | ||
| 23 | #define REAL_H | ||
| 24 | |||
| 25 | #include <plist/Node.h> | ||
| 26 | |||
| 27 | namespace PList | ||
| 28 | { | ||
| 29 | |||
| 30 | class Real : public Node | ||
| 31 | { | ||
| 32 | public : | ||
| 33 | Real(); | ||
| 34 | Real(double d); | ||
| 35 | virtual ~Real(); | ||
| 36 | |||
| 37 | void SetValue(double d); | ||
| 38 | double GetValue(); | ||
| 39 | }; | ||
| 40 | |||
| 41 | }; | ||
| 42 | |||
| 43 | #endif // REAL_H | ||
diff --git a/include/plist/String.h b/include/plist/String.h new file mode 100644 index 0000000..14becac --- /dev/null +++ b/include/plist/String.h | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | /* | ||
| 2 | * String.h | ||
| 3 | * String node type for C++ binding | ||
| 4 | * | ||
| 5 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #ifndef STRING_H | ||
| 23 | #define STRING_H | ||
| 24 | |||
| 25 | #include <plist/Node.h> | ||
| 26 | #include <string> | ||
| 27 | |||
| 28 | namespace PList | ||
| 29 | { | ||
| 30 | |||
| 31 | class String : public Node | ||
| 32 | { | ||
| 33 | public : | ||
| 34 | String(); | ||
| 35 | String(std::string& s); | ||
| 36 | virtual ~String(); | ||
| 37 | |||
| 38 | void SetValue(std::string& s); | ||
| 39 | std::string GetValue(); | ||
| 40 | }; | ||
| 41 | |||
| 42 | }; | ||
| 43 | |||
| 44 | #endif // STRING_H | ||
diff --git a/include/plist/Structure.h b/include/plist/Structure.h new file mode 100644 index 0000000..a0bdcbc --- /dev/null +++ b/include/plist/Structure.h | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | /* | ||
| 2 | * Structure.h | ||
| 3 | * Structure node type for C++ binding | ||
| 4 | * | ||
| 5 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #ifndef STRUCTURE_H | ||
| 23 | #define STRUCTURE_H | ||
| 24 | |||
| 25 | #include <plist/Node.h> | ||
| 26 | #include <string> | ||
| 27 | #include <vector> | ||
| 28 | |||
| 29 | namespace PList | ||
| 30 | { | ||
| 31 | |||
| 32 | class Structure : public Node | ||
| 33 | { | ||
| 34 | public : | ||
| 35 | virtual ~Structure(); | ||
| 36 | |||
| 37 | uint32_t GetSize(); | ||
| 38 | |||
| 39 | std::string ToXml(); | ||
| 40 | std::vector<char> ToBin(); | ||
| 41 | |||
| 42 | protected: | ||
| 43 | Structure(); | ||
| 44 | Structure(plist_type type); | ||
| 45 | |||
| 46 | private: | ||
| 47 | Structure(Structure& s); | ||
| 48 | Structure& operator=(const Structure& s); | ||
| 49 | }; | ||
| 50 | |||
| 51 | }; | ||
| 52 | |||
| 53 | #endif // STRUCTURE_H | ||
diff --git a/include/plist/Utils.h b/include/plist/Utils.h new file mode 100644 index 0000000..b499635 --- /dev/null +++ b/include/plist/Utils.h | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | /* | ||
| 2 | * Utils.h | ||
| 3 | * Import functions for C++ binding | ||
| 4 | * | ||
| 5 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #ifndef UTILS_H | ||
| 23 | #define UTILS_H | ||
| 24 | |||
| 25 | #include <plist/Structure.h> | ||
| 26 | #include <string> | ||
| 27 | |||
| 28 | namespace PList | ||
| 29 | { | ||
| 30 | class Utils | ||
| 31 | { | ||
| 32 | public: | ||
| 33 | static Structure* FromXml(std::string& in); | ||
| 34 | static Structure* FromBin(std::vector<char>& in); | ||
| 35 | |||
| 36 | private: | ||
| 37 | Utils(); | ||
| 38 | ~Utils(); | ||
| 39 | }; | ||
| 40 | }; | ||
| 41 | |||
| 42 | #endif // UTILS_H | ||
diff --git a/include/plist/plist++.h b/include/plist/plist++.h new file mode 100644 index 0000000..209d874 --- /dev/null +++ b/include/plist/plist++.h | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | /* | ||
| 2 | * plist++.h | ||
| 3 | * Main include of libplist C++ binding | ||
| 4 | * | ||
| 5 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #ifndef LIBPLIST++_H | ||
| 23 | #define LIBPLIST++_H | ||
| 24 | |||
| 25 | #include "plist.h" | ||
| 26 | #include "Array.h" | ||
| 27 | #include "Boolean.h" | ||
| 28 | #include "Data.h" | ||
| 29 | #include "Date.h" | ||
| 30 | #include "Dictionary.h" | ||
| 31 | #include "Integer.h" | ||
| 32 | #include "Node.h" | ||
| 33 | #include "Real.h" | ||
| 34 | #include "String.h" | ||
| 35 | #include "Structure.h" | ||
| 36 | #include "Utils.h" | ||
| 37 | |||
| 38 | #endif | ||
diff --git a/src/Array.cpp b/src/Array.cpp new file mode 100644 index 0000000..6f1d3f9 --- /dev/null +++ b/src/Array.cpp | |||
| @@ -0,0 +1,194 @@ | |||
| 1 | /* | ||
| 2 | * Array.cpp | ||
| 3 | * | ||
| 4 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 5 | * | ||
| 6 | * This library is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU Lesser General Public | ||
| 8 | * License as published by the Free Software Foundation; either | ||
| 9 | * version 2.1 of the License, or (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This library is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * Lesser General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU Lesser General Public | ||
| 17 | * License along with this library; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <stdlib.h> | ||
| 22 | #include <plist/Array.h> | ||
| 23 | #include <plist/Dictionary.h> | ||
| 24 | |||
| 25 | namespace PList | ||
| 26 | { | ||
| 27 | |||
| 28 | Array::Array() : Structure(PLIST_ARRAY) | ||
| 29 | { | ||
| 30 | _array.clear(); | ||
| 31 | } | ||
| 32 | |||
| 33 | Array::Array(plist_t node) : Structure() | ||
| 34 | { | ||
| 35 | _node = node; | ||
| 36 | uint32_t size = plist_array_get_size(_node); | ||
| 37 | |||
| 38 | for (uint32_t i = 0; i < size; i++) | ||
| 39 | { | ||
| 40 | plist_t subnode = plist_array_get_item(_node, i); | ||
| 41 | plist_type subtype = plist_get_node_type(subnode); | ||
| 42 | switch(subtype) | ||
| 43 | { | ||
| 44 | case PLIST_DICT: | ||
| 45 | _array.push_back( new Dictionary(subnode) ); | ||
| 46 | break; | ||
| 47 | case PLIST_ARRAY: | ||
| 48 | _array.push_back( new Array(subnode) ); | ||
| 49 | break; | ||
| 50 | case PLIST_BOOLEAN: | ||
| 51 | case PLIST_UINT: | ||
| 52 | case PLIST_REAL: | ||
| 53 | case PLIST_STRING: | ||
| 54 | case PLIST_DATE: | ||
| 55 | case PLIST_DATA: | ||
| 56 | default: | ||
| 57 | _array.push_back( new Node(subnode) ); | ||
| 58 | break; | ||
| 59 | } | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | Array::Array(Array& a) | ||
| 64 | { | ||
| 65 | plist_free(_node); | ||
| 66 | for (int it = 0; it < _array.size(); it++) | ||
| 67 | { | ||
| 68 | delete _array.at(it); | ||
| 69 | } | ||
| 70 | _array.clear(); | ||
| 71 | |||
| 72 | _node = plist_copy(a.GetPlist()); | ||
| 73 | uint32_t size = plist_array_get_size(_node); | ||
| 74 | |||
| 75 | for (uint32_t i = 0; i < size; i++) | ||
| 76 | { | ||
| 77 | plist_t subnode = plist_array_get_item(_node, i); | ||
| 78 | plist_type subtype = plist_get_node_type(subnode); | ||
| 79 | switch(subtype) | ||
| 80 | { | ||
| 81 | case PLIST_DICT: | ||
| 82 | _array.push_back( new Dictionary(subnode) ); | ||
| 83 | break; | ||
| 84 | case PLIST_ARRAY: | ||
| 85 | _array.push_back( new Array(subnode) ); | ||
| 86 | break; | ||
| 87 | case PLIST_BOOLEAN: | ||
| 88 | case PLIST_UINT: | ||
| 89 | case PLIST_REAL: | ||
| 90 | case PLIST_STRING: | ||
| 91 | case PLIST_DATE: | ||
| 92 | case PLIST_DATA: | ||
| 93 | default: | ||
| 94 | _array.push_back( new Node(subnode) ); | ||
| 95 | break; | ||
| 96 | } | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | Array& Array::operator=(const Array& a) | ||
| 101 | { | ||
| 102 | plist_free(_node); | ||
| 103 | for (int it = 0; it < _array.size(); it++) | ||
| 104 | { | ||
| 105 | delete _array.at(it); | ||
| 106 | } | ||
| 107 | _array.clear(); | ||
| 108 | |||
| 109 | _node = plist_copy(a.GetPlist()); | ||
| 110 | uint32_t size = plist_array_get_size(_node); | ||
| 111 | |||
| 112 | for (uint32_t i = 0; i < size; i++) | ||
| 113 | { | ||
| 114 | plist_t subnode = plist_array_get_item(_node, i); | ||
| 115 | plist_type subtype = plist_get_node_type(subnode); | ||
| 116 | switch(subtype) | ||
| 117 | { | ||
| 118 | case PLIST_DICT: | ||
| 119 | _array.push_back( new Dictionary(subnode) ); | ||
| 120 | break; | ||
| 121 | case PLIST_ARRAY: | ||
| 122 | _array.push_back( new Array(subnode) ); | ||
| 123 | break; | ||
| 124 | case PLIST_BOOLEAN: | ||
| 125 | case PLIST_UINT: | ||
| 126 | case PLIST_REAL: | ||
| 127 | case PLIST_STRING: | ||
| 128 | case PLIST_DATE: | ||
| 129 | case PLIST_DATA: | ||
| 130 | default: | ||
| 131 | _array.push_back( new Node(subnode) ); | ||
| 132 | break; | ||
| 133 | } | ||
| 134 | } | ||
| 135 | } | ||
| 136 | |||
| 137 | Array::~Array() | ||
| 138 | { | ||
| 139 | plist_free(_node); | ||
| 140 | for (int it = 0; it < _array.size(); it++) | ||
| 141 | { | ||
| 142 | delete _array.at(it); | ||
| 143 | } | ||
| 144 | _array.clear(); | ||
| 145 | } | ||
| 146 | |||
| 147 | Node* Array::operator[](unsigned int index) | ||
| 148 | { | ||
| 149 | return _array.at(index); | ||
| 150 | } | ||
| 151 | |||
| 152 | void Array::Append(Node* node) | ||
| 153 | { | ||
| 154 | if (node) | ||
| 155 | { | ||
| 156 | plist_array_append_item(_node, node->GetPlist()); | ||
| 157 | _array.push_back(node); | ||
| 158 | } | ||
| 159 | } | ||
| 160 | |||
| 161 | void Array::Insert(Node* node, unsigned int pos) | ||
| 162 | { | ||
| 163 | if (node) | ||
| 164 | { | ||
| 165 | plist_array_insert_item(_node, node->GetPlist(), pos); | ||
| 166 | std::vector<Node*>::iterator it = _array.begin(); | ||
| 167 | it += pos; | ||
| 168 | _array.insert(it, node); | ||
| 169 | } | ||
| 170 | } | ||
| 171 | |||
| 172 | void Array::Remove(Node* node) | ||
| 173 | { | ||
| 174 | if (node) | ||
| 175 | { | ||
| 176 | uint32_t pos = plist_array_get_item_index(node->GetPlist()); | ||
| 177 | plist_array_remove_item(_node, pos); | ||
| 178 | std::vector<Node*>::iterator it = _array.begin(); | ||
| 179 | it += pos; | ||
| 180 | _array.erase(it); | ||
| 181 | delete node; | ||
| 182 | } | ||
| 183 | } | ||
| 184 | |||
| 185 | void Array::Remove(unsigned int pos) | ||
| 186 | { | ||
| 187 | plist_array_remove_item(_node, pos); | ||
| 188 | std::vector<Node*>::iterator it = _array.begin(); | ||
| 189 | it += pos; | ||
| 190 | delete _array.at(pos); | ||
| 191 | _array.erase(it); | ||
| 192 | } | ||
| 193 | |||
| 194 | }; | ||
diff --git a/src/Boolean.cpp b/src/Boolean.cpp new file mode 100644 index 0000000..5797d88 --- /dev/null +++ b/src/Boolean.cpp | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | /* | ||
| 2 | * Boolean.cpp | ||
| 3 | * | ||
| 4 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 5 | * | ||
| 6 | * This library is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU Lesser General Public | ||
| 8 | * License as published by the Free Software Foundation; either | ||
| 9 | * version 2.1 of the License, or (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This library is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * Lesser General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU Lesser General Public | ||
| 17 | * License along with this library; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <stdlib.h> | ||
| 22 | #include <plist/Boolean.h> | ||
| 23 | |||
| 24 | namespace PList | ||
| 25 | { | ||
| 26 | |||
| 27 | Boolean::Boolean() : Node(PLIST_BOOLEAN) | ||
| 28 | { | ||
| 29 | } | ||
| 30 | |||
| 31 | Boolean::Boolean(bool b) : Node(PLIST_BOOLEAN) | ||
| 32 | { | ||
| 33 | plist_set_bool_val(_node, b); | ||
| 34 | } | ||
| 35 | |||
| 36 | Boolean::~Boolean() | ||
| 37 | { | ||
| 38 | } | ||
| 39 | |||
| 40 | void Boolean::SetValue(bool b) | ||
| 41 | { | ||
| 42 | plist_set_bool_val(_node, b); | ||
| 43 | } | ||
| 44 | |||
| 45 | bool Boolean::GetValue() | ||
| 46 | { | ||
| 47 | uint8_t b = 0; | ||
| 48 | plist_get_bool_val(_node, &b); | ||
| 49 | return b; | ||
| 50 | } | ||
| 51 | |||
| 52 | }; | ||
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ab3f694..5e03748 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt | |||
| @@ -7,11 +7,28 @@ SET(libplist_SRC | |||
| 7 | bplist.c | 7 | bplist.c |
| 8 | xplist.c ) | 8 | xplist.c ) |
| 9 | 9 | ||
| 10 | SET(libplist++_SRC | ||
| 11 | Node.cpp | ||
| 12 | Boolean.cpp | ||
| 13 | Integer.cpp | ||
| 14 | Real.cpp | ||
| 15 | String.cpp | ||
| 16 | Date.cpp | ||
| 17 | Data.cpp | ||
| 18 | Structure.cpp | ||
| 19 | Array.cpp | ||
| 20 | Dictionary.cpp | ||
| 21 | Utils.cpp | ||
| 22 | ) | ||
| 23 | |||
| 10 | ADD_LIBRARY( plist SHARED ${libplist_SRC} ) | 24 | ADD_LIBRARY( plist SHARED ${libplist_SRC} ) |
| 11 | TARGET_LINK_LIBRARIES( plist ${LIBXML2_LIBRARIES} ${GLIB2_LIBRARIES} ) | 25 | TARGET_LINK_LIBRARIES( plist ${LIBXML2_LIBRARIES} ${GLIB2_LIBRARIES} ) |
| 12 | SET_TARGET_PROPERTIES( plist PROPERTIES VERSION ${LIBPLIST_LIBVERSION} ) | 26 | SET_TARGET_PROPERTIES( plist PROPERTIES VERSION ${LIBPLIST_LIBVERSION} ) |
| 13 | SET_TARGET_PROPERTIES( plist PROPERTIES SOVERSION ${LIBPLIST_SOVERSION} ) | 27 | SET_TARGET_PROPERTIES( plist PROPERTIES SOVERSION ${LIBPLIST_SOVERSION} ) |
| 14 | 28 | ||
| 29 | ADD_LIBRARY( plist++ SHARED ${libplist++_SRC} ) | ||
| 30 | TARGET_LINK_LIBRARIES( plist++ plist ) | ||
| 31 | |||
| 15 | INSTALL(TARGETS plist | 32 | INSTALL(TARGETS plist |
| 16 | RUNTIME DESTINATION bin COMPONENT lib | 33 | RUNTIME DESTINATION bin COMPONENT lib |
| 17 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dev | 34 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dev |
diff --git a/src/Data.cpp b/src/Data.cpp new file mode 100644 index 0000000..2ce610d --- /dev/null +++ b/src/Data.cpp | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | /* | ||
| 2 | * Data.cpp | ||
| 3 | * | ||
| 4 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 5 | * | ||
| 6 | * This library is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU Lesser General Public | ||
| 8 | * License as published by the Free Software Foundation; either | ||
| 9 | * version 2.1 of the License, or (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This library is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * Lesser General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU Lesser General Public | ||
| 17 | * License along with this library; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <stdlib.h> | ||
| 22 | #include <plist/Data.h> | ||
| 23 | |||
| 24 | namespace PList | ||
| 25 | { | ||
| 26 | |||
| 27 | Data::Data() : Node(PLIST_DATA) | ||
| 28 | { | ||
| 29 | } | ||
| 30 | |||
| 31 | Data::Data(std::vector<char>& buff) : Node(PLIST_DATA) | ||
| 32 | { | ||
| 33 | plist_set_data_val(_node, &buff[0], buff.size()); | ||
| 34 | } | ||
| 35 | |||
| 36 | Data::~Data() | ||
| 37 | { | ||
| 38 | } | ||
| 39 | |||
| 40 | void Data::SetValue(std::vector<char>& buff) | ||
| 41 | { | ||
| 42 | plist_set_data_val(_node, &buff[0], buff.size()); | ||
| 43 | } | ||
| 44 | |||
| 45 | std::vector<char> Data::GetValue() | ||
| 46 | { | ||
| 47 | char* buff = NULL; | ||
| 48 | uint64_t length = 0; | ||
| 49 | plist_get_data_val(_node, &buff, &length); | ||
| 50 | std::vector<char> ret(buff, buff + length); | ||
| 51 | free(buff); | ||
| 52 | return ret; | ||
| 53 | } | ||
| 54 | |||
| 55 | |||
| 56 | |||
| 57 | }; | ||
diff --git a/src/Date.cpp b/src/Date.cpp new file mode 100644 index 0000000..56e1e8e --- /dev/null +++ b/src/Date.cpp | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | /* | ||
| 2 | * Date.cpp | ||
| 3 | * | ||
| 4 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 5 | * | ||
| 6 | * This library is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU Lesser General Public | ||
| 8 | * License as published by the Free Software Foundation; either | ||
| 9 | * version 2.1 of the License, or (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This library is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * Lesser General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU Lesser General Public | ||
| 17 | * License along with this library; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <stdlib.h> | ||
| 22 | #include <plist/Date.h> | ||
| 23 | |||
| 24 | namespace PList | ||
| 25 | { | ||
| 26 | |||
| 27 | Date::Date() : Node(PLIST_DATE) | ||
| 28 | { | ||
| 29 | } | ||
| 30 | |||
| 31 | Date::Date(uint64_t i) : Node(PLIST_DATE) | ||
| 32 | { | ||
| 33 | plist_set_date_val(_node, i, 0); | ||
| 34 | } | ||
| 35 | |||
| 36 | Date::~Date() | ||
| 37 | { | ||
| 38 | } | ||
| 39 | |||
| 40 | void Date::SetValue(uint64_t i) | ||
| 41 | { | ||
| 42 | plist_set_date_val(_node, i, 0); | ||
| 43 | } | ||
| 44 | |||
| 45 | uint64_t Date::GetValue() | ||
| 46 | { | ||
| 47 | int32_t i = 0; | ||
| 48 | plist_get_date_val(_node, &i, &i); | ||
| 49 | return i; | ||
| 50 | } | ||
| 51 | |||
| 52 | }; | ||
diff --git a/src/Dictionary.cpp b/src/Dictionary.cpp new file mode 100644 index 0000000..5bace76 --- /dev/null +++ b/src/Dictionary.cpp | |||
| @@ -0,0 +1,217 @@ | |||
| 1 | /* | ||
| 2 | * Dictionary.cpp | ||
| 3 | * | ||
| 4 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 5 | * | ||
| 6 | * This library is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU Lesser General Public | ||
| 8 | * License as published by the Free Software Foundation; either | ||
| 9 | * version 2.1 of the License, or (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This library is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * Lesser General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU Lesser General Public | ||
| 17 | * License along with this library; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <stdlib.h> | ||
| 22 | #include <plist/Dictionary.h> | ||
| 23 | #include <plist/Array.h> | ||
| 24 | |||
| 25 | namespace PList | ||
| 26 | { | ||
| 27 | |||
| 28 | Dictionary::Dictionary() : Structure(PLIST_DICT) | ||
| 29 | { | ||
| 30 | } | ||
| 31 | |||
| 32 | Dictionary::Dictionary(plist_t node) : Structure() | ||
| 33 | { | ||
| 34 | _node = node; | ||
| 35 | plist_dict_iter it = NULL; | ||
| 36 | |||
| 37 | char* key = NULL; | ||
| 38 | plist_t subnode = NULL; | ||
| 39 | plist_dict_new_iter(_node, &it); | ||
| 40 | plist_dict_next_item(_node, it, &key, &subnode); | ||
| 41 | while (subnode) | ||
| 42 | { | ||
| 43 | plist_type subtype = plist_get_node_type(subnode); | ||
| 44 | switch(subtype) | ||
| 45 | { | ||
| 46 | case PLIST_DICT: | ||
| 47 | _map[std::string(key)] = new Dictionary(subnode); | ||
| 48 | break; | ||
| 49 | case PLIST_ARRAY: | ||
| 50 | _map[std::string(key)] = new Array(subnode); | ||
| 51 | break; | ||
| 52 | case PLIST_BOOLEAN: | ||
| 53 | case PLIST_UINT: | ||
| 54 | case PLIST_REAL: | ||
| 55 | case PLIST_STRING: | ||
| 56 | case PLIST_DATE: | ||
| 57 | case PLIST_DATA: | ||
| 58 | default: | ||
| 59 | _map[std::string(key)] = new Node(subnode); | ||
| 60 | break; | ||
| 61 | } | ||
| 62 | |||
| 63 | subnode = NULL; | ||
| 64 | free(key); | ||
| 65 | key = NULL; | ||
| 66 | plist_dict_next_item(_node, it, NULL, &subnode); | ||
| 67 | } | ||
| 68 | free(it); | ||
| 69 | } | ||
| 70 | |||
| 71 | Dictionary::Dictionary(Dictionary& d) | ||
| 72 | { | ||
| 73 | for (Dictionary::iterator it = _map.begin(); it != _map.end(); it++) | ||
| 74 | { | ||
| 75 | plist_free(it->second->GetPlist()); | ||
| 76 | delete it->second; | ||
| 77 | } | ||
| 78 | _map.clear(); | ||
| 79 | |||
| 80 | _node = plist_copy(d.GetPlist()); | ||
| 81 | plist_dict_iter it = NULL; | ||
| 82 | |||
| 83 | char* key = NULL; | ||
| 84 | plist_t subnode = NULL; | ||
| 85 | plist_dict_new_iter(_node, &it); | ||
| 86 | plist_dict_next_item(_node, it, &key, &subnode); | ||
| 87 | while (subnode) | ||
| 88 | { | ||
| 89 | plist_type subtype = plist_get_node_type(subnode); | ||
| 90 | switch(subtype) | ||
| 91 | { | ||
| 92 | case PLIST_DICT: | ||
| 93 | _map[std::string(key)] = new Dictionary(subnode); | ||
| 94 | break; | ||
| 95 | case PLIST_ARRAY: | ||
| 96 | _map[std::string(key)] = new Array(subnode); | ||
| 97 | break; | ||
| 98 | case PLIST_BOOLEAN: | ||
| 99 | case PLIST_UINT: | ||
| 100 | case PLIST_REAL: | ||
| 101 | case PLIST_STRING: | ||
| 102 | case PLIST_DATE: | ||
| 103 | case PLIST_DATA: | ||
| 104 | default: | ||
| 105 | _map[std::string(key)] = new Node(subnode); | ||
| 106 | break; | ||
| 107 | } | ||
| 108 | |||
| 109 | subnode = NULL; | ||
| 110 | free(key); | ||
| 111 | key = NULL; | ||
| 112 | plist_dict_next_item(_node, it, NULL, &subnode); | ||
| 113 | } | ||
| 114 | free(it); | ||
| 115 | } | ||
| 116 | |||
| 117 | Dictionary& Dictionary::operator=(const Dictionary& d) | ||
| 118 | { | ||
| 119 | for (Dictionary::iterator it = _map.begin(); it != _map.end(); it++) | ||
| 120 | { | ||
| 121 | plist_free(it->second->GetPlist()); | ||
| 122 | delete it->second; | ||
| 123 | } | ||
| 124 | _map.clear(); | ||
| 125 | |||
| 126 | _node = plist_copy(d.GetPlist()); | ||
| 127 | plist_dict_iter it = NULL; | ||
| 128 | |||
| 129 | char* key = NULL; | ||
| 130 | plist_t subnode = NULL; | ||
| 131 | plist_dict_new_iter(_node, &it); | ||
| 132 | plist_dict_next_item(_node, it, &key, &subnode); | ||
| 133 | while (subnode) | ||
| 134 | { | ||
| 135 | plist_type subtype = plist_get_node_type(subnode); | ||
| 136 | switch(subtype) | ||
| 137 | { | ||
| 138 | case PLIST_DICT: | ||
| 139 | _map[std::string(key)] = new Dictionary(subnode); | ||
| 140 | break; | ||
| 141 | case PLIST_ARRAY: | ||
| 142 | _map[std::string(key)] = new Array(subnode); | ||
| 143 | break; | ||
| 144 | case PLIST_BOOLEAN: | ||
| 145 | case PLIST_UINT: | ||
| 146 | case PLIST_REAL: | ||
| 147 | case PLIST_STRING: | ||
| 148 | case PLIST_DATE: | ||
| 149 | case PLIST_DATA: | ||
| 150 | default: | ||
| 151 | _map[std::string(key)] = new Node(subnode); | ||
| 152 | break; | ||
| 153 | } | ||
| 154 | |||
| 155 | subnode = NULL; | ||
| 156 | free(key); | ||
| 157 | key = NULL; | ||
| 158 | plist_dict_next_item(_node, it, NULL, &subnode); | ||
| 159 | } | ||
| 160 | free(it); | ||
| 161 | } | ||
| 162 | |||
| 163 | Dictionary::~Dictionary() | ||
| 164 | { | ||
| 165 | for (Dictionary::iterator it = _map.begin(); it != _map.end(); it++) | ||
| 166 | { | ||
| 167 | plist_free(it->second->GetPlist()); | ||
| 168 | delete it->second; | ||
| 169 | } | ||
| 170 | _map.clear(); | ||
| 171 | } | ||
| 172 | |||
| 173 | Node* Dictionary::operator[](std::string& key) | ||
| 174 | { | ||
| 175 | return _map[key]; | ||
| 176 | } | ||
| 177 | |||
| 178 | Dictionary::iterator Dictionary::Begin() | ||
| 179 | { | ||
| 180 | return _map.begin(); | ||
| 181 | } | ||
| 182 | |||
| 183 | Dictionary::iterator Dictionary::End() | ||
| 184 | { | ||
| 185 | return _map.end(); | ||
| 186 | } | ||
| 187 | |||
| 188 | void Dictionary::Insert(std::string& key, Node* node) | ||
| 189 | { | ||
| 190 | if (node) | ||
| 191 | { | ||
| 192 | plist_dict_insert_item(_node, key.c_str(), node->GetPlist()); | ||
| 193 | delete _map[key]; | ||
| 194 | _map[key] = node; | ||
| 195 | } | ||
| 196 | } | ||
| 197 | |||
| 198 | void Dictionary::Remove(Node* node) | ||
| 199 | { | ||
| 200 | if (node) | ||
| 201 | { | ||
| 202 | char* key = NULL; | ||
| 203 | plist_dict_get_item_key(node->GetPlist(), &key); | ||
| 204 | plist_dict_remove_item(_node, key); | ||
| 205 | std::string skey = key; | ||
| 206 | free(key); | ||
| 207 | delete node; | ||
| 208 | } | ||
| 209 | } | ||
| 210 | |||
| 211 | void Dictionary::Remove(std::string& key) | ||
| 212 | { | ||
| 213 | plist_dict_remove_item(_node, key.c_str()); | ||
| 214 | delete _map[key]; | ||
| 215 | } | ||
| 216 | |||
| 217 | }; | ||
diff --git a/src/Integer.cpp b/src/Integer.cpp new file mode 100644 index 0000000..d4a7645 --- /dev/null +++ b/src/Integer.cpp | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | /* | ||
| 2 | * Integer.cpp | ||
| 3 | * | ||
| 4 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 5 | * | ||
| 6 | * This library is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU Lesser General Public | ||
| 8 | * License as published by the Free Software Foundation; either | ||
| 9 | * version 2.1 of the License, or (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This library is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * Lesser General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU Lesser General Public | ||
| 17 | * License along with this library; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <stdlib.h> | ||
| 22 | #include <plist/Integer.h> | ||
| 23 | |||
| 24 | namespace PList | ||
| 25 | { | ||
| 26 | |||
| 27 | Integer::Integer() : Node(PLIST_UINT) | ||
| 28 | { | ||
| 29 | } | ||
| 30 | |||
| 31 | Integer::Integer(uint64_t i) : Node(PLIST_UINT) | ||
| 32 | { | ||
| 33 | plist_set_uint_val(_node, i); | ||
| 34 | } | ||
| 35 | |||
| 36 | Integer::~Integer() | ||
| 37 | { | ||
| 38 | } | ||
| 39 | |||
| 40 | void Integer::SetValue(uint64_t i) | ||
| 41 | { | ||
| 42 | plist_set_uint_val(_node, i); | ||
| 43 | } | ||
| 44 | |||
| 45 | uint64_t Integer::GetValue() | ||
| 46 | { | ||
| 47 | uint64_t i = 0; | ||
| 48 | plist_get_uint_val(_node, &i); | ||
| 49 | return i; | ||
| 50 | } | ||
| 51 | |||
| 52 | }; | ||
diff --git a/src/Node.cpp b/src/Node.cpp new file mode 100644 index 0000000..dbcd6d6 --- /dev/null +++ b/src/Node.cpp | |||
| @@ -0,0 +1,105 @@ | |||
| 1 | /* | ||
| 2 | * Node.cpp | ||
| 3 | * | ||
| 4 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 5 | * | ||
| 6 | * This library is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU Lesser General Public | ||
| 8 | * License as published by the Free Software Foundation; either | ||
| 9 | * version 2.1 of the License, or (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This library is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * Lesser General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU Lesser General Public | ||
| 17 | * License along with this library; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <stdlib.h> | ||
| 22 | #include <plist/Node.h> | ||
| 23 | |||
| 24 | namespace PList | ||
| 25 | { | ||
| 26 | |||
| 27 | Node::Node() | ||
| 28 | { | ||
| 29 | } | ||
| 30 | |||
| 31 | Node::Node(plist_t node) : _node(node) | ||
| 32 | { | ||
| 33 | } | ||
| 34 | |||
| 35 | Node::Node(plist_type type) | ||
| 36 | { | ||
| 37 | _node = NULL; | ||
| 38 | |||
| 39 | switch(type) { | ||
| 40 | case PLIST_BOOLEAN: | ||
| 41 | _node = plist_new_bool(0); | ||
| 42 | break; | ||
| 43 | case PLIST_UINT: | ||
| 44 | _node = plist_new_uint(0); | ||
| 45 | break; | ||
| 46 | case PLIST_REAL: | ||
| 47 | _node = plist_new_real(0.); | ||
| 48 | break; | ||
| 49 | case PLIST_STRING: | ||
| 50 | _node = plist_new_string(""); | ||
| 51 | break; | ||
| 52 | case PLIST_DATA: | ||
| 53 | _node = plist_new_data(NULL,0); | ||
| 54 | break; | ||
| 55 | case PLIST_DATE: | ||
| 56 | _node = plist_new_date(0,0); | ||
| 57 | break; | ||
| 58 | case PLIST_ARRAY: | ||
| 59 | _node = plist_new_array(); | ||
| 60 | break; | ||
| 61 | case PLIST_DICT: | ||
| 62 | _node = plist_new_dict(); | ||
| 63 | break; | ||
| 64 | case PLIST_KEY: | ||
| 65 | case PLIST_NONE: | ||
| 66 | default: | ||
| 67 | break; | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | Node::~Node() | ||
| 72 | { | ||
| 73 | plist_free(_node); | ||
| 74 | _node = NULL; | ||
| 75 | } | ||
| 76 | |||
| 77 | Node::Node(Node& node) | ||
| 78 | { | ||
| 79 | plist_free(_node); | ||
| 80 | _node = NULL; | ||
| 81 | |||
| 82 | _node = plist_copy(_node); | ||
| 83 | } | ||
| 84 | |||
| 85 | Node& Node::operator=(const Node& node) | ||
| 86 | { | ||
| 87 | plist_free(_node); | ||
| 88 | _node = NULL; | ||
| 89 | |||
| 90 | _node = plist_copy(_node); | ||
| 91 | } | ||
| 92 | |||
| 93 | plist_type Node::GetType() | ||
| 94 | { | ||
| 95 | if (_node) | ||
| 96 | { | ||
| 97 | return plist_get_node_type(_node); | ||
| 98 | } | ||
| 99 | } | ||
| 100 | |||
| 101 | plist_t Node::GetPlist() const | ||
| 102 | { | ||
| 103 | return _node; | ||
| 104 | } | ||
| 105 | }; | ||
diff --git a/src/Real.cpp b/src/Real.cpp new file mode 100644 index 0000000..41c5d87 --- /dev/null +++ b/src/Real.cpp | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | /* | ||
| 2 | * Real.cpp | ||
| 3 | * | ||
| 4 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 5 | * | ||
| 6 | * This library is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU Lesser General Public | ||
| 8 | * License as published by the Free Software Foundation; either | ||
| 9 | * version 2.1 of the License, or (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This library is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * Lesser General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU Lesser General Public | ||
| 17 | * License along with this library; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <stdlib.h> | ||
| 22 | #include <plist/Real.h> | ||
| 23 | |||
| 24 | namespace PList | ||
| 25 | { | ||
| 26 | |||
| 27 | Real::Real() : Node(PLIST_REAL) | ||
| 28 | { | ||
| 29 | } | ||
| 30 | |||
| 31 | Real::Real(double d) : Node(PLIST_REAL) | ||
| 32 | { | ||
| 33 | plist_set_real_val(_node, d); | ||
| 34 | } | ||
| 35 | |||
| 36 | Real::~Real() | ||
| 37 | { | ||
| 38 | } | ||
| 39 | |||
| 40 | void Real::SetValue(double d) | ||
| 41 | { | ||
| 42 | plist_set_real_val(_node, d); | ||
| 43 | } | ||
| 44 | |||
| 45 | double Real::GetValue() | ||
| 46 | { | ||
| 47 | double d = 0.; | ||
| 48 | plist_get_real_val(_node, &d); | ||
| 49 | return d; | ||
| 50 | } | ||
| 51 | |||
| 52 | }; | ||
diff --git a/src/String.cpp b/src/String.cpp new file mode 100644 index 0000000..24b4ce8 --- /dev/null +++ b/src/String.cpp | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | /* | ||
| 2 | * String.cpp | ||
| 3 | * | ||
| 4 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 5 | * | ||
| 6 | * This library is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU Lesser General Public | ||
| 8 | * License as published by the Free Software Foundation; either | ||
| 9 | * version 2.1 of the License, or (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This library is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * Lesser General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU Lesser General Public | ||
| 17 | * License along with this library; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <stdlib.h> | ||
| 22 | #include <plist/String.h> | ||
| 23 | |||
| 24 | namespace PList | ||
| 25 | { | ||
| 26 | |||
| 27 | String::String() : Node(PLIST_STRING) | ||
| 28 | { | ||
| 29 | } | ||
| 30 | |||
| 31 | String::String(std::string& s) : Node(PLIST_STRING) | ||
| 32 | { | ||
| 33 | plist_set_string_val(_node, s.c_str()); | ||
| 34 | } | ||
| 35 | |||
| 36 | String::~String() | ||
| 37 | { | ||
| 38 | } | ||
| 39 | |||
| 40 | void String::SetValue(std::string& s) | ||
| 41 | { | ||
| 42 | plist_set_string_val(_node, s.c_str()); | ||
| 43 | } | ||
| 44 | |||
| 45 | std::string String::GetValue() | ||
| 46 | { | ||
| 47 | char* s = NULL; | ||
| 48 | plist_get_string_val(_node, &s); | ||
| 49 | std::string ret = s; | ||
| 50 | free(s); | ||
| 51 | return ret; | ||
| 52 | } | ||
| 53 | |||
| 54 | }; | ||
diff --git a/src/Structure.cpp b/src/Structure.cpp new file mode 100644 index 0000000..6fd9b3d --- /dev/null +++ b/src/Structure.cpp | |||
| @@ -0,0 +1,74 @@ | |||
| 1 | /* | ||
| 2 | * Structure.cpp | ||
| 3 | * | ||
| 4 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 5 | * | ||
| 6 | * This library is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU Lesser General Public | ||
| 8 | * License as published by the Free Software Foundation; either | ||
| 9 | * version 2.1 of the License, or (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This library is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * Lesser General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU Lesser General Public | ||
| 17 | * License along with this library; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <stdlib.h> | ||
| 22 | #include <plist/Structure.h> | ||
| 23 | |||
| 24 | namespace PList | ||
| 25 | { | ||
| 26 | |||
| 27 | Structure::Structure() : Node() | ||
| 28 | { | ||
| 29 | } | ||
| 30 | Structure::Structure(plist_type type) : Node(type) | ||
| 31 | { | ||
| 32 | } | ||
| 33 | |||
| 34 | Structure::~Structure() | ||
| 35 | { | ||
| 36 | } | ||
| 37 | |||
| 38 | uint32_t Structure::GetSize() | ||
| 39 | { | ||
| 40 | uint32_t size = 0; | ||
| 41 | plist_type type = plist_get_node_type(_node); | ||
| 42 | if (type == PLIST_ARRAY) | ||
| 43 | { | ||
| 44 | size = plist_array_get_size(_node); | ||
| 45 | } | ||
| 46 | else if (type == PLIST_DICT) | ||
| 47 | { | ||
| 48 | size = plist_dict_get_size(_node); | ||
| 49 | } | ||
| 50 | return size; | ||
| 51 | } | ||
| 52 | |||
| 53 | std::string Structure::ToXml() | ||
| 54 | { | ||
| 55 | char* xml = NULL; | ||
| 56 | uint32_t length = 0; | ||
| 57 | plist_to_xml(_node, &xml, &length); | ||
| 58 | std::string ret(xml, xml+length); | ||
| 59 | free(xml); | ||
| 60 | return ret; | ||
| 61 | } | ||
| 62 | |||
| 63 | std::vector<char> Structure::ToBin() | ||
| 64 | { | ||
| 65 | char* bin = NULL; | ||
| 66 | uint32_t length = 0; | ||
| 67 | plist_to_bin(_node, &bin, &length); | ||
| 68 | std::vector<char> ret(bin, bin+length); | ||
| 69 | free(bin); | ||
| 70 | return ret; | ||
| 71 | } | ||
| 72 | |||
| 73 | }; | ||
| 74 | |||
diff --git a/src/Utils.cpp b/src/Utils.cpp new file mode 100644 index 0000000..a9d2459 --- /dev/null +++ b/src/Utils.cpp | |||
| @@ -0,0 +1,74 @@ | |||
| 1 | /* | ||
| 2 | * Utils.cpp | ||
| 3 | * | ||
| 4 | * Copyright (c) 2009 Jonathan Beck All Rights Reserved. | ||
| 5 | * | ||
| 6 | * This library is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU Lesser General Public | ||
| 8 | * License as published by the Free Software Foundation; either | ||
| 9 | * version 2.1 of the License, or (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This library is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * Lesser General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU Lesser General Public | ||
| 17 | * License along with this library; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <stdlib.h> | ||
| 22 | #include <plist/Utils.h> | ||
| 23 | #include <plist/Dictionary.h> | ||
| 24 | #include <plist/Array.h> | ||
| 25 | |||
| 26 | namespace PList | ||
| 27 | { | ||
| 28 | |||
| 29 | static Structure* FromPlist(plist_t root) | ||
| 30 | { | ||
| 31 | Structure* ret = NULL; | ||
| 32 | if (root) | ||
| 33 | { | ||
| 34 | plist_type type = plist_get_node_type(root); | ||
| 35 | switch(type) | ||
| 36 | { | ||
| 37 | case PLIST_DICT: | ||
| 38 | ret = new Dictionary(root); | ||
| 39 | break; | ||
| 40 | case PLIST_ARRAY: | ||
| 41 | ret = new Array(root); | ||
| 42 | break; | ||
| 43 | case PLIST_BOOLEAN: | ||
| 44 | case PLIST_UINT: | ||
| 45 | case PLIST_REAL: | ||
| 46 | case PLIST_STRING: | ||
| 47 | case PLIST_DATE: | ||
| 48 | case PLIST_DATA: | ||
| 49 | default: | ||
| 50 | plist_free(root); | ||
| 51 | break; | ||
| 52 | } | ||
| 53 | } | ||
| 54 | return ret; | ||
| 55 | } | ||
| 56 | |||
| 57 | Structure* Utils::FromXml(std::string& in) | ||
| 58 | { | ||
| 59 | plist_t root = NULL; | ||
| 60 | plist_from_xml(in.c_str(), in.size(), &root); | ||
| 61 | |||
| 62 | return FromPlist(root); | ||
| 63 | } | ||
| 64 | |||
| 65 | Structure* Utils::FromBin(std::vector<char>& in) | ||
| 66 | { | ||
| 67 | plist_t root = NULL; | ||
| 68 | plist_from_bin(&in[0], in.size(), &root); | ||
| 69 | |||
| 70 | return FromPlist(root); | ||
| 71 | |||
| 72 | } | ||
| 73 | |||
| 74 | }; | ||
