plist.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**************************************************************************/
  2. /* plist.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. // Property list file format (application/x-plist) parser, property list ASN-1 serialization.
  31. #ifndef OSX_PLIST_H
  32. #define OSX_PLIST_H
  33. #include "core/crypto/crypto_core.h"
  34. #include "core/os/file_access.h"
  35. #include "modules/modules_enabled.gen.h" // For regex.
  36. #ifdef MODULE_REGEX_ENABLED
  37. class PListNode;
  38. class PList : public Reference {
  39. friend class PListNode;
  40. public:
  41. enum PLNodeType {
  42. PL_NODE_TYPE_NIL,
  43. PL_NODE_TYPE_STRING,
  44. PL_NODE_TYPE_ARRAY,
  45. PL_NODE_TYPE_DICT,
  46. PL_NODE_TYPE_BOOLEAN,
  47. PL_NODE_TYPE_INTEGER,
  48. PL_NODE_TYPE_REAL,
  49. PL_NODE_TYPE_DATA,
  50. PL_NODE_TYPE_DATE,
  51. };
  52. private:
  53. Ref<PListNode> root;
  54. public:
  55. PList();
  56. PList(const String &p_string);
  57. bool load_file(const String &p_filename);
  58. bool load_string(const String &p_string);
  59. PoolByteArray save_asn1() const;
  60. String save_text() const;
  61. Ref<PListNode> get_root();
  62. };
  63. /*************************************************************************/
  64. class PListNode : public Reference {
  65. static int _asn1_size_len(uint8_t p_len_octets);
  66. public:
  67. PList::PLNodeType data_type = PList::PLNodeType::PL_NODE_TYPE_NIL;
  68. CharString data_string;
  69. Vector<Ref<PListNode>> data_array;
  70. Map<String, Ref<PListNode>> data_dict;
  71. union {
  72. int32_t data_int;
  73. bool data_bool;
  74. float data_real;
  75. };
  76. static Ref<PListNode> new_array();
  77. static Ref<PListNode> new_dict();
  78. static Ref<PListNode> new_string(const String &p_string);
  79. static Ref<PListNode> new_data(const String &p_string);
  80. static Ref<PListNode> new_date(const String &p_string);
  81. static Ref<PListNode> new_bool(bool p_bool);
  82. static Ref<PListNode> new_int(int32_t p_int);
  83. static Ref<PListNode> new_real(float p_real);
  84. bool push_subnode(const Ref<PListNode> &p_node, const String &p_key = "");
  85. size_t get_asn1_size(uint8_t p_len_octets) const;
  86. void store_asn1_size(PoolByteArray &p_stream, uint8_t p_len_octets) const;
  87. bool store_asn1(PoolByteArray &p_stream, uint8_t p_len_octets) const;
  88. void store_text(String &p_stream, uint8_t p_indent) const;
  89. PListNode() {}
  90. ~PListNode() {}
  91. };
  92. #endif // MODULE_REGEX_ENABLED
  93. #endif // OSX_PLIST_H