Debian Codegraph @

core/io/plist.h

raw symbols SCIP
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
31 #pragma once
32
33 // Property list file format (application/x-plist) parser, property list ASN-1 serialization.
34
35 #include "core/io/file_access.h"
36
37 class PListNode;
38
39 class PList : public RefCounted {
40 GDSOFTCLASS(PList, RefCounted);
41
42 friend class PListNode;
43
44 public:
45 enum PLNodeType {
46 PL_NODE_TYPE_NIL,
47 PL_NODE_TYPE_STRING,
48 PL_NODE_TYPE_ARRAY,
49 PL_NODE_TYPE_DICT,
50 PL_NODE_TYPE_BOOLEAN,
51 PL_NODE_TYPE_INTEGER,
52 PL_NODE_TYPE_REAL,
53 PL_NODE_TYPE_DATA,
54 PL_NODE_TYPE_DATE,
55 };
56
57 private:
58 struct PListTrailer {
59 uint8_t offset_size;
60 uint8_t ref_size;
61 uint64_t object_num;
62 uint64_t root_offset_idx;
63 uint64_t offset_table_start;
64 };
65
66 PListTrailer trailer;
67 Ref<PListNode> root;
68
69 uint64_t read_bplist_var_size_int(Ref<FileAccess> p_file, uint8_t p_size);
70 Ref<PListNode> read_bplist_obj(Ref<FileAccess> p_file, uint64_t p_offset_idx);
71
72 public:
73 PList();
74 PList(const String &p_string);
75
76 bool load_file(const String &p_filename);
77 bool load_string(const String &p_string, String &r_err_out);
78
79 PackedByteArray save_asn1() const;
80 String save_text() const;
81
82 Ref<PListNode> get_root();
83 };
84
85 /*************************************************************************/
86
87 class PListNode : public RefCounted {
88 GDSOFTCLASS(PListNode, RefCounted);
89
90 static int _asn1_size_len(uint8_t p_len_octets);
91
92 public:
93 PList::PLNodeType data_type = PList::PLNodeType::PL_NODE_TYPE_NIL;
94
95 CharString data_string;
96 Vector<Ref<PListNode>> data_array;
97 HashMap<String, Ref<PListNode>> data_dict;
98 union {
99 int64_t data_int;
100 bool data_bool;
101 double data_real;
102 };
103
104 PList::PLNodeType get_type() const;
105 Variant get_value() const;
106
107 static Ref<PListNode> new_node(const Variant &p_value);
108 static Ref<PListNode> new_array();
109 static Ref<PListNode> new_dict();
110 static Ref<PListNode> new_string(const String &p_string);
111 static Ref<PListNode> new_data(const String &p_string);
112 static Ref<PListNode> new_date(const String &p_string);
113 static Ref<PListNode> new_bool(bool p_bool);
114 static Ref<PListNode> new_int(int64_t p_int);
115 static Ref<PListNode> new_real(double p_real);
116
117 bool push_subnode(const Ref<PListNode> &p_node, const String &p_key = "");
118
119 size_t get_asn1_size(uint8_t p_len_octets) const;
120
121 void store_asn1_size(PackedByteArray &p_stream, uint8_t p_len_octets) const;
122 bool store_asn1(PackedByteArray &p_stream, uint8_t p_len_octets) const;
123 void store_text(String &p_stream, uint8_t p_indent) const;
124 };