Debian Codegraph @

scene/property_list_helper.h

raw symbols SCIP
1 /**************************************************************************/
2 /* property_list_helper.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/object/method_bind.h"
34 #include "core/object/object.h"
35
36 class PropertyListHelper {
37 struct Property {
38 PropertyInfo info;
39 Variant default_value;
40 MethodBind *setter = nullptr;
41 MethodBind *getter = nullptr;
42 };
43
44 static Vector<PropertyListHelper *> base_helpers;
45
46 String prefix;
47 MethodBind *array_length_getter = nullptr;
48 HashMap<String, Property> property_list;
49 Object *object = nullptr;
50
51 bool allow_oob_assign = false;
52
53 const Property *_get_property(const String &p_property, int *r_index, bool p_allow_oob = false) const;
54 void _call_setter(const MethodBind *p_setter, int p_index, const Variant &p_value) const;
55 Variant _call_getter(const Property *p_property, int p_index) const;
56 int _call_array_length_getter() const;
57
58 public:
59 static void clear_base_helpers();
60 static void register_base_helper(PropertyListHelper *p_helper);
61
62 void set_prefix(const String &p_prefix);
63 template <typename G>
64 void set_array_length_getter(G p_array_length_getter) {
65 array_length_getter = create_method_bind(p_array_length_getter);
66 }
67
68 // Register property without setter/getter. Only use when you don't need PropertyListHelper for _set/_get logic.
69 void register_property(const PropertyInfo &p_info, const Variant &p_default);
70
71 template <typename S, typename G>
72 void register_property(const PropertyInfo &p_info, const Variant &p_default, S p_setter, G p_getter) {
73 Property property;
74 property.info = p_info;
75 property.default_value = p_default;
76 property.setter = create_method_bind(p_setter);
77 property.getter = create_method_bind(p_getter);
78
79 property_list[p_info.name] = property;
80 }
81
82 bool is_initialized() const;
83 void setup_for_instance(const PropertyListHelper &p_base, Object *p_object);
84 bool is_property_valid(const String &p_property, int *r_index = nullptr) const;
85
86 void get_property_list(List<PropertyInfo> *p_list) const;
87 bool property_get_value(const String &p_property, Variant &r_ret) const;
88 bool property_set_value(const String &p_property, const Variant &p_value) const;
89 bool property_can_revert(const String &p_property) const;
90 bool property_get_revert(const String &p_property, Variant &r_value) const;
91
92 void enable_out_of_bounds_assign() { allow_oob_assign = true; }
93
94 void clear();
95 };