/* Copyright (C) 2013 * swift project Community / Contributors * * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, * including this file, may be copied, modified, propagated, or distributed except according to the terms * contained in the LICENSE file. */ //! \file #ifndef BLACKMISC_CONTAINERBASE_H #define BLACKMISC_CONTAINERBASE_H #include "range.h" #include "predicates.h" #include "json.h" #include "variant.h" #include "dbus.h" #include #include namespace BlackMisc { //! Class providing static helper methods for different containers class CContainerHelper { public: //! Stringify value object template static QString stringify(const U &obj, bool i18n) { return obj.toQString(i18n); } //! Stringify int static QString stringify(int n, bool i18n) { return i18n ? QLocale().toString(n) : QString::number(n); } //! Stringify uint static QString stringify(uint n, bool i18n) { return i18n ? QLocale().toString(n) : QString::number(n); } //! Stringify qlonglong static QString stringify(qlonglong n, bool i18n) { return i18n ? QLocale().toString(n) : QString::number(n); } //! Stringify qulonglong static QString stringify(qulonglong n, bool i18n) { return i18n ? QLocale().toString(n) : QString::number(n); } //! Stringify double static QString stringify(double n, bool i18n) { return i18n ? QLocale().toString(n) : QString::number(n); } //! Stringify QString static QString stringify(QString str, bool /*i18n*/) { return str; } //! Stringify pair template static QString stringify(const std::pair &pair, bool i18n) { return stringify(pair.first, i18n) + ":" + stringify(pair.second, i18n); } }; /*! * Base class for CCollection and CSequence adding mutating operations and CValueObject facility on top of CRangeBase. */ template class CContainerBase : public CRangeBase, public Mixin::MetaType, public Mixin::DBusOperators, public Mixin::JsonOperators, public Mixin::String { public: //! \copydoc BlackMisc::CValueObject::compare friend int compare(const Derived &a, const Derived &b) { for (auto i = a.cbegin(), j = b.cbegin(); i != a.cend() && j != b.cend(); ++i, ++j) { if (*i < *j) { return -1; } if (*j < *i) { return 1; } } if (a.size() < b.size()) { return -1; } if (b.size() < a.size()) { return 1; } return 0; } //! Return a new container of a different type, containing the same elements as this one. //! \tparam Other the type of the new container. //! @{ template