/**************************************************************************/1/* property_list_helper.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/object/method_bind.h"33#include "core/object/object.h"3435class PropertyListHelper {36struct Property {37PropertyInfo info;38Variant default_value;39MethodBind *setter = nullptr;40MethodBind *getter = nullptr;41};4243static Vector<PropertyListHelper *> base_helpers;4445String prefix;46MethodBind *array_length_getter = nullptr;47HashMap<String, Property> property_list;48Object *object = nullptr;4950const Property *_get_property(const String &p_property, int *r_index) const;51void _call_setter(const MethodBind *p_setter, int p_index, const Variant &p_value) const;52Variant _call_getter(const Property *p_property, int p_index) const;53int _call_array_length_getter() const;5455public:56static void clear_base_helpers();57static void register_base_helper(PropertyListHelper *p_helper);5859void set_prefix(const String &p_prefix);60template <typename G>61void set_array_length_getter(G p_array_length_getter) {62array_length_getter = create_method_bind(p_array_length_getter);63}6465// Register property without setter/getter. Only use when you don't need PropertyListHelper for _set/_get logic.66void register_property(const PropertyInfo &p_info, const Variant &p_default);6768template <typename S, typename G>69void register_property(const PropertyInfo &p_info, const Variant &p_default, S p_setter, G p_getter) {70Property property;71property.info = p_info;72property.default_value = p_default;73property.setter = create_method_bind(p_setter);74property.getter = create_method_bind(p_getter);7576property_list[p_info.name] = property;77}7879bool is_initialized() const;80void setup_for_instance(const PropertyListHelper &p_base, Object *p_object);81bool is_property_valid(const String &p_property, int *r_index = nullptr) const;8283void get_property_list(List<PropertyInfo> *p_list) const;84bool property_get_value(const String &p_property, Variant &r_ret) const;85bool property_set_value(const String &p_property, const Variant &p_value) const;86bool property_can_revert(const String &p_property) const;87bool property_get_revert(const String &p_property, Variant &r_value) const;8889void clear();90};919293