From cfe4b30941a3388a5ee40690fd468f994180fa86 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 5 Aug 2017 09:12:53 -0300 Subject: renamed node path, closes #5691 --- core/node_path.cpp | 418 +++++++++++++++++++++++++++++++++++ core/node_path.h | 99 +++++++++ core/path_db.cpp | 418 ----------------------------------- core/path_db.h | 99 --------- core/variant.h | 2 +- modules/gdnative/godot/node_path.cpp | 2 +- scene/main/node.h | 2 +- scene/scene_string_names.h | 2 +- 8 files changed, 521 insertions(+), 521 deletions(-) create mode 100644 core/node_path.cpp create mode 100644 core/node_path.h delete mode 100644 core/path_db.cpp delete mode 100644 core/path_db.h diff --git a/core/node_path.cpp b/core/node_path.cpp new file mode 100644 index 0000000000..11df9670f2 --- /dev/null +++ b/core/node_path.cpp @@ -0,0 +1,418 @@ +/*************************************************************************/ +/* path_db.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "node_path.h" + +#include "print_string.h" + +uint32_t NodePath::hash() const { + + if (!data) + return 0; + + uint32_t h = data->absolute ? 1 : 0; + int pc = data->path.size(); + const StringName *sn = data->path.ptr(); + for (int i = 0; i < pc; i++) { + h = h ^ sn[i].hash(); + } + int spc = data->subpath.size(); + const StringName *ssn = data->subpath.ptr(); + for (int i = 0; i < spc; i++) { + h = h ^ ssn[i].hash(); + } + + h = h ^ data->property.hash(); + + return h; +} + +void NodePath::prepend_period() { + + if (data->path.size() && data->path[0].operator String() != ".") { + data->path.insert(0, "."); + } +} + +bool NodePath::is_absolute() const { + + if (!data) + return false; + + return data->absolute; +} +int NodePath::get_name_count() const { + + if (!data) + return 0; + + return data->path.size(); +} +StringName NodePath::get_name(int p_idx) const { + + ERR_FAIL_COND_V(!data, StringName()); + ERR_FAIL_INDEX_V(p_idx, data->path.size(), StringName()); + return data->path[p_idx]; +} + +StringName NodePath::get_property() const { + + if (!data) + return StringName(); + return data->property; +} + +int NodePath::get_subname_count() const { + + if (!data) + return 0; + + return data->subpath.size(); +} +StringName NodePath::get_subname(int p_idx) const { + + ERR_FAIL_COND_V(!data, StringName()); + ERR_FAIL_INDEX_V(p_idx, data->subpath.size(), StringName()); + return data->subpath[p_idx]; +} + +void NodePath::unref() { + + if (data && data->refcount.unref()) { + + memdelete(data); + } + data = NULL; +} + +bool NodePath::operator==(const NodePath &p_path) const { + + if (data == p_path.data) + return true; + + if (!data || !p_path.data) + return false; + + if (data->absolute != p_path.data->absolute) + return false; + + if (data->path.size() != p_path.data->path.size()) + return false; + + if (data->subpath.size() != p_path.data->subpath.size()) + return false; + + if (data->property != p_path.data->property) + return false; + + for (int i = 0; i < data->path.size(); i++) { + + if (data->path[i] != p_path.data->path[i]) + return false; + } + + for (int i = 0; i < data->subpath.size(); i++) { + + if (data->subpath[i] != p_path.data->subpath[i]) + return false; + } + + return true; +} +bool NodePath::operator!=(const NodePath &p_path) const { + + return (!(*this == p_path)); +} + +void NodePath::operator=(const NodePath &p_path) { + + if (this == &p_path) + return; + + unref(); + + if (p_path.data && p_path.data->refcount.ref()) { + + data = p_path.data; + } +} + +NodePath::operator String() const { + + if (!data) + return String(); + + String ret; + if (data->absolute) + ret = "/"; + + for (int i = 0; i < data->path.size(); i++) { + + if (i > 0) + ret += "/"; + ret += data->path[i].operator String(); + } + + for (int i = 0; i < data->subpath.size(); i++) { + + ret += ":" + data->subpath[i].operator String(); + } + + if (data->property.operator String() != "") + ret += ":" + String(data->property); + return ret; +} + +NodePath::NodePath(const NodePath &p_path) { + + data = NULL; + + if (p_path.data && p_path.data->refcount.ref()) { + + data = p_path.data; + } +} + +Vector NodePath::get_names() const { + + if (data) + return data->path; + return Vector(); +} +Vector NodePath::get_subnames() const { + + if (data) + return data->subpath; + return Vector(); +} + +NodePath NodePath::rel_path_to(const NodePath &p_np) const { + + ERR_FAIL_COND_V(!is_absolute(), NodePath()); + ERR_FAIL_COND_V(!p_np.is_absolute(), NodePath()); + + Vector src_dirs = get_names(); + Vector dst_dirs = p_np.get_names(); + + //find common parent + int common_parent = 0; + + while (true) { + if (src_dirs.size() == common_parent) + break; + if (dst_dirs.size() == common_parent) + break; + if (src_dirs[common_parent] != dst_dirs[common_parent]) + break; + common_parent++; + } + + common_parent--; + + Vector relpath; + + for (int i = src_dirs.size() - 1; i > common_parent; i--) { + + relpath.push_back(".."); + } + + for (int i = common_parent + 1; i < dst_dirs.size(); i++) { + + relpath.push_back(dst_dirs[i]); + } + + if (relpath.size() == 0) + relpath.push_back("."); + + return NodePath(relpath, p_np.get_subnames(), false, p_np.get_property()); +} + +NodePath::NodePath(const Vector &p_path, bool p_absolute, const String &p_property) { + + data = NULL; + + if (p_path.size() == 0) + return; + + data = memnew(Data); + data->refcount.init(); + data->absolute = p_absolute; + data->path = p_path; + data->property = p_property; +} + +NodePath::NodePath(const Vector &p_path, const Vector &p_subpath, bool p_absolute, const String &p_property) { + + data = NULL; + + if (p_path.size() == 0) + return; + + data = memnew(Data); + data->refcount.init(); + data->absolute = p_absolute; + data->path = p_path; + data->subpath = p_subpath; + data->property = p_property; +} + +void NodePath::simplify() { + + if (!data) + return; + for (int i = 0; i < data->path.size(); i++) { + if (data->path.size() == 1) + break; + if (data->path[i].operator String() == ".") { + data->path.remove(i); + i--; + } else if (data->path[i].operator String() == ".." && i > 0 && data->path[i - 1].operator String() != "." && data->path[i - 1].operator String() != "..") { + //remove both + data->path.remove(i - 1); + data->path.remove(i - 1); + i -= 2; + if (data->path.size() == 0) { + data->path.push_back("."); + break; + } + } + } +} + +NodePath NodePath::simplified() const { + + NodePath np = *this; + np.simplify(); + return np; +} + +NodePath::NodePath(const String &p_path) { + + data = NULL; + + if (p_path.length() == 0) + return; + + String path = p_path; + StringName property; + Vector subpath; + + int absolute = (path[0] == '/') ? 1 : 0; + bool last_is_slash = true; + int slices = 0; + int subpath_pos = path.find(":"); + + if (subpath_pos != -1) { + + int from = subpath_pos + 1; + + for (int i = from; i <= path.length(); i++) { + + if (path[i] == ':' || path[i] == 0) { + + String str = path.substr(from, i - from); + if (path[i] == ':') { + if (str == "") { + ERR_EXPLAIN("Invalid NodePath: " + p_path); + ERR_FAIL(); + } + subpath.push_back(str); + } else { + //property can be empty + property = str; + } + + from = i + 1; + } + } + + path = path.substr(0, subpath_pos); + } + + for (int i = absolute; i < path.length(); i++) { + + if (path[i] == '/') { + + last_is_slash = true; + } else { + + if (last_is_slash) + slices++; + + last_is_slash = false; + } + } + + if (slices == 0 && !absolute && !property) + return; + + data = memnew(Data); + data->refcount.init(); + data->absolute = absolute ? true : false; + data->property = property; + data->subpath = subpath; + + if (slices == 0) + return; + data->path.resize(slices); + last_is_slash = true; + int from = absolute; + int slice = 0; + + for (int i = absolute; i < path.length() + 1; i++) { + + if (path[i] == '/' || path[i] == 0) { + + if (!last_is_slash) { + + String name = path.substr(from, i - from); + ERR_FAIL_INDEX(slice, data->path.size()); + data->path[slice++] = name; + } + from = i + 1; + last_is_slash = true; + } else { + last_is_slash = false; + } + } +} + +bool NodePath::is_empty() const { + + return !data; +} +NodePath::NodePath() { + + data = NULL; +} + +NodePath::~NodePath() { + + unref(); +} diff --git a/core/node_path.h b/core/node_path.h new file mode 100644 index 0000000000..1aed7535ca --- /dev/null +++ b/core/node_path.h @@ -0,0 +1,99 @@ +/*************************************************************************/ +/* path_db.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef PATH_DB_H +#define PATH_DB_H + +#include "string_db.h" +#include "ustring.h" +/** + @author Juan Linietsky +*/ + +class NodePath { + + struct Data { + + SafeRefCount refcount; + StringName property; + Vector path; + Vector subpath; + bool absolute; + }; + + Data *data; + void unref(); + +public: + _FORCE_INLINE_ StringName get_sname() const { + + if (data && data->path.size() == 1 && data->subpath.empty() && !data->property) { + return data->path[0]; + } else { + return operator String(); + } + } + + bool is_absolute() const; + int get_name_count() const; + StringName get_name(int p_idx) const; + int get_subname_count() const; + StringName get_subname(int p_idx) const; + Vector get_names() const; + Vector get_subnames() const; + + NodePath rel_path_to(const NodePath &p_np) const; + + void prepend_period(); + + StringName get_property() const; + + NodePath get_parent() const; + + uint32_t hash() const; + + operator String() const; + bool is_empty() const; + + bool operator==(const NodePath &p_path) const; + bool operator!=(const NodePath &p_path) const; + void operator=(const NodePath &p_path); + + void simplify(); + NodePath simplified() const; + + NodePath(const Vector &p_path, bool p_absolute, const String &p_property = ""); + NodePath(const Vector &p_path, const Vector &p_subpath, bool p_absolute, const String &p_property = ""); + NodePath(const NodePath &p_path); + NodePath(const String &p_path); + NodePath(); + ~NodePath(); +}; + +#endif diff --git a/core/path_db.cpp b/core/path_db.cpp deleted file mode 100644 index d5c84a2457..0000000000 --- a/core/path_db.cpp +++ /dev/null @@ -1,418 +0,0 @@ -/*************************************************************************/ -/* path_db.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "path_db.h" - -#include "print_string.h" - -uint32_t NodePath::hash() const { - - if (!data) - return 0; - - uint32_t h = data->absolute ? 1 : 0; - int pc = data->path.size(); - const StringName *sn = data->path.ptr(); - for (int i = 0; i < pc; i++) { - h = h ^ sn[i].hash(); - } - int spc = data->subpath.size(); - const StringName *ssn = data->subpath.ptr(); - for (int i = 0; i < spc; i++) { - h = h ^ ssn[i].hash(); - } - - h = h ^ data->property.hash(); - - return h; -} - -void NodePath::prepend_period() { - - if (data->path.size() && data->path[0].operator String() != ".") { - data->path.insert(0, "."); - } -} - -bool NodePath::is_absolute() const { - - if (!data) - return false; - - return data->absolute; -} -int NodePath::get_name_count() const { - - if (!data) - return 0; - - return data->path.size(); -} -StringName NodePath::get_name(int p_idx) const { - - ERR_FAIL_COND_V(!data, StringName()); - ERR_FAIL_INDEX_V(p_idx, data->path.size(), StringName()); - return data->path[p_idx]; -} - -StringName NodePath::get_property() const { - - if (!data) - return StringName(); - return data->property; -} - -int NodePath::get_subname_count() const { - - if (!data) - return 0; - - return data->subpath.size(); -} -StringName NodePath::get_subname(int p_idx) const { - - ERR_FAIL_COND_V(!data, StringName()); - ERR_FAIL_INDEX_V(p_idx, data->subpath.size(), StringName()); - return data->subpath[p_idx]; -} - -void NodePath::unref() { - - if (data && data->refcount.unref()) { - - memdelete(data); - } - data = NULL; -} - -bool NodePath::operator==(const NodePath &p_path) const { - - if (data == p_path.data) - return true; - - if (!data || !p_path.data) - return false; - - if (data->absolute != p_path.data->absolute) - return false; - - if (data->path.size() != p_path.data->path.size()) - return false; - - if (data->subpath.size() != p_path.data->subpath.size()) - return false; - - if (data->property != p_path.data->property) - return false; - - for (int i = 0; i < data->path.size(); i++) { - - if (data->path[i] != p_path.data->path[i]) - return false; - } - - for (int i = 0; i < data->subpath.size(); i++) { - - if (data->subpath[i] != p_path.data->subpath[i]) - return false; - } - - return true; -} -bool NodePath::operator!=(const NodePath &p_path) const { - - return (!(*this == p_path)); -} - -void NodePath::operator=(const NodePath &p_path) { - - if (this == &p_path) - return; - - unref(); - - if (p_path.data && p_path.data->refcount.ref()) { - - data = p_path.data; - } -} - -NodePath::operator String() const { - - if (!data) - return String(); - - String ret; - if (data->absolute) - ret = "/"; - - for (int i = 0; i < data->path.size(); i++) { - - if (i > 0) - ret += "/"; - ret += data->path[i].operator String(); - } - - for (int i = 0; i < data->subpath.size(); i++) { - - ret += ":" + data->subpath[i].operator String(); - } - - if (data->property.operator String() != "") - ret += ":" + String(data->property); - return ret; -} - -NodePath::NodePath(const NodePath &p_path) { - - data = NULL; - - if (p_path.data && p_path.data->refcount.ref()) { - - data = p_path.data; - } -} - -Vector NodePath::get_names() const { - - if (data) - return data->path; - return Vector(); -} -Vector NodePath::get_subnames() const { - - if (data) - return data->subpath; - return Vector(); -} - -NodePath NodePath::rel_path_to(const NodePath &p_np) const { - - ERR_FAIL_COND_V(!is_absolute(), NodePath()); - ERR_FAIL_COND_V(!p_np.is_absolute(), NodePath()); - - Vector src_dirs = get_names(); - Vector dst_dirs = p_np.get_names(); - - //find common parent - int common_parent = 0; - - while (true) { - if (src_dirs.size() == common_parent) - break; - if (dst_dirs.size() == common_parent) - break; - if (src_dirs[common_parent] != dst_dirs[common_parent]) - break; - common_parent++; - } - - common_parent--; - - Vector relpath; - - for (int i = src_dirs.size() - 1; i > common_parent; i--) { - - relpath.push_back(".."); - } - - for (int i = common_parent + 1; i < dst_dirs.size(); i++) { - - relpath.push_back(dst_dirs[i]); - } - - if (relpath.size() == 0) - relpath.push_back("."); - - return NodePath(relpath, p_np.get_subnames(), false, p_np.get_property()); -} - -NodePath::NodePath(const Vector &p_path, bool p_absolute, const String &p_property) { - - data = NULL; - - if (p_path.size() == 0) - return; - - data = memnew(Data); - data->refcount.init(); - data->absolute = p_absolute; - data->path = p_path; - data->property = p_property; -} - -NodePath::NodePath(const Vector &p_path, const Vector &p_subpath, bool p_absolute, const String &p_property) { - - data = NULL; - - if (p_path.size() == 0) - return; - - data = memnew(Data); - data->refcount.init(); - data->absolute = p_absolute; - data->path = p_path; - data->subpath = p_subpath; - data->property = p_property; -} - -void NodePath::simplify() { - - if (!data) - return; - for (int i = 0; i < data->path.size(); i++) { - if (data->path.size() == 1) - break; - if (data->path[i].operator String() == ".") { - data->path.remove(i); - i--; - } else if (data->path[i].operator String() == ".." && i > 0 && data->path[i - 1].operator String() != "." && data->path[i - 1].operator String() != "..") { - //remove both - data->path.remove(i - 1); - data->path.remove(i - 1); - i -= 2; - if (data->path.size() == 0) { - data->path.push_back("."); - break; - } - } - } -} - -NodePath NodePath::simplified() const { - - NodePath np = *this; - np.simplify(); - return np; -} - -NodePath::NodePath(const String &p_path) { - - data = NULL; - - if (p_path.length() == 0) - return; - - String path = p_path; - StringName property; - Vector subpath; - - int absolute = (path[0] == '/') ? 1 : 0; - bool last_is_slash = true; - int slices = 0; - int subpath_pos = path.find(":"); - - if (subpath_pos != -1) { - - int from = subpath_pos + 1; - - for (int i = from; i <= path.length(); i++) { - - if (path[i] == ':' || path[i] == 0) { - - String str = path.substr(from, i - from); - if (path[i] == ':') { - if (str == "") { - ERR_EXPLAIN("Invalid NodePath: " + p_path); - ERR_FAIL(); - } - subpath.push_back(str); - } else { - //property can be empty - property = str; - } - - from = i + 1; - } - } - - path = path.substr(0, subpath_pos); - } - - for (int i = absolute; i < path.length(); i++) { - - if (path[i] == '/') { - - last_is_slash = true; - } else { - - if (last_is_slash) - slices++; - - last_is_slash = false; - } - } - - if (slices == 0 && !absolute && !property) - return; - - data = memnew(Data); - data->refcount.init(); - data->absolute = absolute ? true : false; - data->property = property; - data->subpath = subpath; - - if (slices == 0) - return; - data->path.resize(slices); - last_is_slash = true; - int from = absolute; - int slice = 0; - - for (int i = absolute; i < path.length() + 1; i++) { - - if (path[i] == '/' || path[i] == 0) { - - if (!last_is_slash) { - - String name = path.substr(from, i - from); - ERR_FAIL_INDEX(slice, data->path.size()); - data->path[slice++] = name; - } - from = i + 1; - last_is_slash = true; - } else { - last_is_slash = false; - } - } -} - -bool NodePath::is_empty() const { - - return !data; -} -NodePath::NodePath() { - - data = NULL; -} - -NodePath::~NodePath() { - - unref(); -} diff --git a/core/path_db.h b/core/path_db.h deleted file mode 100644 index 1aed7535ca..0000000000 --- a/core/path_db.h +++ /dev/null @@ -1,99 +0,0 @@ -/*************************************************************************/ -/* path_db.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef PATH_DB_H -#define PATH_DB_H - -#include "string_db.h" -#include "ustring.h" -/** - @author Juan Linietsky -*/ - -class NodePath { - - struct Data { - - SafeRefCount refcount; - StringName property; - Vector path; - Vector subpath; - bool absolute; - }; - - Data *data; - void unref(); - -public: - _FORCE_INLINE_ StringName get_sname() const { - - if (data && data->path.size() == 1 && data->subpath.empty() && !data->property) { - return data->path[0]; - } else { - return operator String(); - } - } - - bool is_absolute() const; - int get_name_count() const; - StringName get_name(int p_idx) const; - int get_subname_count() const; - StringName get_subname(int p_idx) const; - Vector get_names() const; - Vector get_subnames() const; - - NodePath rel_path_to(const NodePath &p_np) const; - - void prepend_period(); - - StringName get_property() const; - - NodePath get_parent() const; - - uint32_t hash() const; - - operator String() const; - bool is_empty() const; - - bool operator==(const NodePath &p_path) const; - bool operator!=(const NodePath &p_path) const; - void operator=(const NodePath &p_path); - - void simplify(); - NodePath simplified() const; - - NodePath(const Vector &p_path, bool p_absolute, const String &p_property = ""); - NodePath(const Vector &p_path, const Vector &p_subpath, bool p_absolute, const String &p_property = ""); - NodePath(const NodePath &p_path); - NodePath(const String &p_path); - NodePath(); - ~NodePath(); -}; - -#endif diff --git a/core/variant.h b/core/variant.h index 661d31cf16..583a0d09a0 100644 --- a/core/variant.h +++ b/core/variant.h @@ -43,7 +43,7 @@ #include "math_2d.h" #include "matrix3.h" #include "os/power.h" -#include "path_db.h" +#include "node_path.h" #include "plane.h" #include "quat.h" #include "rect3.h" diff --git a/modules/gdnative/godot/node_path.cpp b/modules/gdnative/godot/node_path.cpp index e718a9e55f..f4179361be 100644 --- a/modules/gdnative/godot/node_path.cpp +++ b/modules/gdnative/godot/node_path.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include -#include "core/path_db.h" +#include "core/node_path.h" #include "core/variant.h" #ifdef __cplusplus diff --git a/scene/main/node.h b/scene/main/node.h index 1794cce9f6..0447deccc1 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -33,7 +33,7 @@ #include "class_db.h" #include "map.h" #include "object.h" -#include "path_db.h" +#include "node_path.h" #include "project_settings.h" #include "scene/main/scene_tree.h" #include "script_language.h" diff --git a/scene/scene_string_names.h b/scene/scene_string_names.h index 0802a73973..0bfe42a7b8 100644 --- a/scene/scene_string_names.h +++ b/scene/scene_string_names.h @@ -30,7 +30,7 @@ #ifndef SCENE_STRING_NAMES_H #define SCENE_STRING_NAMES_H -#include "path_db.h" +#include "node_path.h" #include "string_db.h" class SceneStringNames { -- cgit v1.2.3