Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/core/variant/dictionary.h
9903 views
1
/**************************************************************************/
2
/* dictionary.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
#include "core/string/ustring.h"
34
#include "core/templates/hash_map.h"
35
#include "core/templates/local_vector.h"
36
#include "core/templates/pair.h"
37
#include "core/variant/array.h"
38
#include "core/variant/variant_deep_duplicate.h"
39
40
class Variant;
41
42
struct ContainerType;
43
struct ContainerTypeValidate;
44
struct DictionaryPrivate;
45
struct StringLikeVariantComparator;
46
struct VariantHasher;
47
48
class Dictionary {
49
mutable DictionaryPrivate *_p;
50
51
void _ref(const Dictionary &p_from) const;
52
void _unref() const;
53
54
public:
55
using ConstIterator = HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator>::ConstIterator;
56
57
ConstIterator begin() const;
58
ConstIterator end() const;
59
60
LocalVector<Variant> get_key_list() const;
61
Variant get_key_at_index(int p_index) const;
62
Variant get_value_at_index(int p_index) const;
63
64
Variant &operator[](const Variant &p_key);
65
const Variant &operator[](const Variant &p_key) const;
66
67
const Variant *getptr(const Variant &p_key) const;
68
Variant *getptr(const Variant &p_key);
69
70
Variant get_valid(const Variant &p_key) const;
71
Variant get(const Variant &p_key, const Variant &p_default) const;
72
Variant get_or_add(const Variant &p_key, const Variant &p_default);
73
bool set(const Variant &p_key, const Variant &p_value);
74
75
int size() const;
76
bool is_empty() const;
77
void clear();
78
void sort();
79
void merge(const Dictionary &p_dictionary, bool p_overwrite = false);
80
Dictionary merged(const Dictionary &p_dictionary, bool p_overwrite = false) const;
81
82
bool has(const Variant &p_key) const;
83
bool has_all(const Array &p_keys) const;
84
Variant find_key(const Variant &p_value) const;
85
86
bool erase(const Variant &p_key);
87
88
bool operator==(const Dictionary &p_dictionary) const;
89
bool operator!=(const Dictionary &p_dictionary) const;
90
bool recursive_equal(const Dictionary &p_dictionary, int recursion_count) const;
91
92
uint32_t hash() const;
93
uint32_t recursive_hash(int recursion_count) const;
94
void operator=(const Dictionary &p_dictionary);
95
96
void assign(const Dictionary &p_dictionary);
97
const Variant *next(const Variant *p_key = nullptr) const;
98
99
Array keys() const;
100
Array values() const;
101
102
Dictionary duplicate(bool p_deep = false) const;
103
Dictionary duplicate_deep(ResourceDeepDuplicateMode p_deep_subresources_mode = RESOURCE_DEEP_DUPLICATE_INTERNAL) const;
104
Dictionary recursive_duplicate(bool p_deep, ResourceDeepDuplicateMode p_deep_subresources_mode, int recursion_count) const;
105
106
void set_typed(const ContainerType &p_key_type, const ContainerType &p_value_type);
107
void set_typed(uint32_t p_key_type, const StringName &p_key_class_name, const Variant &p_key_script, uint32_t p_value_type, const StringName &p_value_class_name, const Variant &p_value_script);
108
109
bool is_typed() const;
110
bool is_typed_key() const;
111
bool is_typed_value() const;
112
bool is_same_instance(const Dictionary &p_other) const;
113
bool is_same_typed(const Dictionary &p_other) const;
114
bool is_same_typed_key(const Dictionary &p_other) const;
115
bool is_same_typed_value(const Dictionary &p_other) const;
116
117
ContainerType get_key_type() const;
118
ContainerType get_value_type() const;
119
uint32_t get_typed_key_builtin() const;
120
uint32_t get_typed_value_builtin() const;
121
StringName get_typed_key_class_name() const;
122
StringName get_typed_value_class_name() const;
123
Variant get_typed_key_script() const;
124
Variant get_typed_value_script() const;
125
const ContainerTypeValidate &get_key_validator() const;
126
const ContainerTypeValidate &get_value_validator() const;
127
128
void make_read_only();
129
bool is_read_only() const;
130
131
const void *id() const;
132
133
Dictionary(const Dictionary &p_base, uint32_t p_key_type, const StringName &p_key_class_name, const Variant &p_key_script, uint32_t p_value_type, const StringName &p_value_class_name, const Variant &p_value_script);
134
Dictionary(const Dictionary &p_from);
135
Dictionary(std::initializer_list<KeyValue<Variant, Variant>> p_init);
136
Dictionary();
137
~Dictionary();
138
};
139
140