path_db.h
1 /*************************************************************************/
2 /* path_db.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 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 /*************************************************************************/
29 #ifndef PATH_DB_H
30 #define PATH_DB_H
31 
32 
33 #include "ustring.h"
34 #include "string_db.h"
41 class NodePath {
42 
43  struct Data {
44 
45  SafeRefCount refcount;
46  StringName property;
47  Vector<StringName> path;
48  Vector<StringName> subpath;
49  bool absolute;
50  };
51 
52  Data *data;
53  void unref();
54 public:
55 
56  _FORCE_INLINE_ StringName get_sname() const {
57 
58  if (data && data->path.size()==1 && data->subpath.empty() && !data->property) {
59  return data->path[0];
60  } else {
61  return operator String();
62  }
63  }
64 
65  bool is_absolute() const;
66  int get_name_count() const;
67  StringName get_name(int p_idx) const;
68  int get_subname_count() const;
69  StringName get_subname(int p_idx) const;
70  Vector<StringName> get_names() const;
71  Vector<StringName> get_subnames() const;
72 
73  NodePath rel_path_to(const NodePath& p_np) const;
74 
75  StringName get_property() const;
76 
77  NodePath get_parent() const;
78 
79  uint32_t hash() const;
80 
81  operator String() const;
82  bool is_empty() const;
83 
84  bool operator==(const NodePath& p_path) const;
85  bool operator!=(const NodePath& p_path) const;
86  void operator=(const NodePath& p_path);
87 
88  void simplify();
89  NodePath simplified() const;
90 
91  NodePath(const Vector<StringName>& p_path,bool p_absolute,const String& p_property="");
92  NodePath(const Vector<StringName>& p_path,const Vector<StringName>& p_subpath,bool p_absolute,const String& p_property="");
93  NodePath(const NodePath& p_path);
94  NodePath(const String& p_path);
95  NodePath();
96  ~NodePath();
97 };
98 
99 #endif
Definition: path_db.h:41
Definition: safe_refcount.h:336
Definition: string_db.h:48
Definition: ustring.h:64