diff --git a/core/include/DataSource/DataSourceItem.h b/core/include/DataSource/DataSourceItem.h index be60242..950d3b8 100644 --- a/core/include/DataSource/DataSourceItem.h +++ b/core/include/DataSource/DataSourceItem.h @@ -83,6 +83,9 @@ public: DataSourceItemType type() const noexcept; + bool operator==(const DataSourceItem &other); + bool operator!=(const DataSourceItem &other); + private: class DataSourceItemPrivate; spimpl::unique_impl_ptr impl; diff --git a/core/src/DataSource/DataSourceItem.cpp b/core/src/DataSource/DataSourceItem.cpp index 19b1ae2..81dc552 100644 --- a/core/src/DataSource/DataSourceItem.cpp +++ b/core/src/DataSource/DataSourceItem.cpp @@ -117,3 +117,24 @@ DataSourceItemType DataSourceItem::type() const noexcept { return impl->m_Type; } + +bool DataSourceItem::operator==(const DataSourceItem &other) +{ + // Compares items' attributes + if (std::tie(impl->m_Type, impl->m_Data) == std::tie(other.impl->m_Type, other.impl->m_Data)) { + // Compares contents of items' children + return std::equal(std::cbegin(impl->m_Children), std::cend(impl->m_Children), + std::cbegin(other.impl->m_Children), + [](const auto &itemChild, const auto &otherChild) { + return *itemChild == *otherChild; + }); + } + else { + return false; + } +} + +bool DataSourceItem::operator!=(const DataSourceItem &other) +{ + return !(*this == other); +}