2 #include <score/document/DocumentInterface.hpp>
3 #include <score/tools/Metadata.hpp>
8 template <
typename T,
typename U>
11 static const constexpr
bool value
12 = std::is_base_of<T, U>::value || std::is_base_of<U, T>::value;
18 template <
typename Object>
50 template <
typename Object>
53 friend bool operator==(
const Path& lhs,
const Path& rhs) noexcept
55 return lhs.m_impl == rhs.m_impl;
58 friend bool operator!=(
const Path& lhs,
const Path& rhs) noexcept
60 return lhs.m_impl != rhs.m_impl;
63 friend uint qHash(
const Path& obj, uint seed) noexcept
65 return qHash(obj.m_impl, seed);
88 : m_impl{std::move(obj.vec())}
92 Path(
const Object& obj) noexcept
93 :
Path(score::IDocument::path(obj))
100 template <
typename U>
104 p.m_impl.vec().push_back({name,
id});
110 template <
typename U>
113 Path<U> p{std::move(this->m_impl.vec())};
114 p.m_impl.vec().push_back({name,
id});
119 template <
typename U>
129 template <
typename U>
132 Path<U> p{std::move(this->m_impl.vec())};
138 template <
typename U>
141 SCORE_ASSERT(m_impl.vec().size() > 0);
142 auto vec = m_impl.vec();
143 auto last = vec.back();
145 return std::make_pair(
Path<U>{std::move(vec)}, std::move(last));
150 template <
typename U>
155 SCORE_ASSERT(!m_impl.vec().empty());
156 auto last = m_impl.vec().back();
157 m_impl.vec().pop_back();
158 return std::make_pair(
Path<U>{std::move(m_impl.vec())}, std::move(last));
163 template <
typename U>
166 : m_impl{other.m_impl.vec()}
170 template <
typename U>
173 : m_impl{std::move(other.m_impl.vec())}
177 template <
typename U>
181 m_impl = other.m_impl;
185 template <
typename U>
189 m_impl = std::move(other.m_impl);
193 Path() noexcept = default;
194 Path(const
Path&) noexcept = default;
196 Path& operator=(const
Path&) noexcept = default;
197 Path& operator=(
Path&&) noexcept = default;
199 Object& find(const
score::DocumentContext& ctx)
const
201 SCORE_ASSERT(valid());
202 return m_impl.
find<Object>(ctx);
208 return m_impl.
try_find<Object>(ctx);
211 const auto& unsafePath() const& noexcept {
return m_impl; }
212 auto& unsafePath() & noexcept {
return m_impl; }
213 auto&& unsafePath() && noexcept {
return std::move(m_impl); }
215 bool valid() const noexcept {
return !m_impl.vec().empty(); }
223 : m_impl{std::move(path.vec())}
226 Path(
const std::vector<ObjectIdentifier>& vec) noexcept
230 Path(std::vector<ObjectIdentifier>&& vec) noexcept
231 : m_impl{std::move(vec)}
238 template <
typename T>
245 template <
typename tag>
248 std::size_t operator()(
const Path<tag>& path)
const
257 template <
typename T>
260 SCORE_ASSERT(path.valid());
261 SCORE_ASSERT(
bool(path.unsafePath().vec().back().id()));
263 return Id<T>(path.unsafePath().vec().back().id());
The IdentifiedObject class.
Definition: IdentifiedObject.hpp:19
The ObjectPath class.
Definition: ObjectPath.hpp:37
T * try_find(const score::DocumentContext &ctx) const noexcept
Tries to find an object.
Definition: ObjectPath.hpp:131
T & find(const score::DocumentContext &ctx) const
find the object described by the ObjectPath
Definition: ObjectPath.hpp:110
The Path class is a typesafe wrapper around ObjectPath.
Definition: Path.hpp:52
auto extend(const QString &name, const Id< U > &id) &&noexcept
Definition: Path.hpp:111
auto splitLast() &&
Definition: Path.hpp:151
auto extend(const Id< U > &id) &&noexcept
Definition: Path.hpp:130
auto splitLast() const &
Return a new path without the last element of this one.
Definition: Path.hpp:139
auto extend(const QString &name, const Id< U > &id) const &noexcept
Add a new ObjectIdentifier at the end of the path and return a new path.
Definition: Path.hpp:101
auto extend(const Id< U > &id) const &noexcept
Add a new ObjectIdentifier at the end of the path and return a new path.
Definition: Path.hpp:120
The id_base_t class.
Definition: Identifier.hpp:57
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Use this if it is not possible to get a path.
Definition: Path.hpp:79
Used to know if two types are in an inheritance relationship.
Definition: Path.hpp:10
Definition: DocumentContext.hpp:18
Definition: ObjectPath.hpp:186