/* * Copyright 2020 Michail Vourlakos * * This file is part of Latte-Dock * * Latte-Dock is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * Latte-Dock is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include "generictable.h" #include "activitydata.h" #include "appletdata.h" #include "layoutdata.h" #include namespace Latte { namespace Data { template GenericTable::GenericTable() { } template GenericTable::GenericTable(GenericTable &&o) : m_list(o.m_list) { } template GenericTable::GenericTable(const GenericTable &o) : m_list(o.m_list) { } //! Operators template GenericTable &GenericTable::operator=(const GenericTable &rhs) { m_list = rhs.m_list; return (*this); } template GenericTable &GenericTable::operator=(GenericTable &&rhs) { m_list = rhs.m_list; return (*this); } template GenericTable &GenericTable::operator<<(const T &rhs) { if (!rhs.id.isEmpty()) { m_list << rhs; } return (*this); } template GenericTable &GenericTable::operator<<(const GenericTable &rhs) { m_list << rhs.m_list; return (*this); } template GenericTable &GenericTable::insert(const int &pos, const T &rhs) { m_list.insert(pos, rhs); return (*this); } template GenericTable &GenericTable::insertBasedOnName(const T &rhs) { return insert(sortedPosForName(rhs.name), rhs); } template GenericTable &GenericTable::insertBasedOnId(const T &rhs) { return insert(sortedPosForId(rhs.id), rhs); } template bool GenericTable::operator==(const GenericTable &rhs) const { if (m_list.count() == 0 && rhs.m_list.count() == 0) { return true; } if (m_list.count() != rhs.m_list.count()) { return false; } for(int i=0; i bool GenericTable::operator!=(const GenericTable &rhs) const { return !(*this == rhs); } template T &GenericTable::operator[](const QString &id) { int pos{-1}; for(int i=0; i const T GenericTable::operator[](const QString &id) const { int pos{-1}; for(int i=0; i T &GenericTable::operator[](const uint &index) { return m_list[index]; } template const T GenericTable::operator[](const uint &index) const { return m_list[index]; } template bool GenericTable::containsId(const QString &id) const { for(int i=0; i bool GenericTable::containsName(const QString &name) const { for(int i=0; i bool GenericTable::rowExists(const int &row) const { return (m_list.count()>=0 && row>=0 && row int GenericTable::indexOf(const QString &id) const { for(int i=0; i int GenericTable::rowCount() const { return m_list.count(); } template int GenericTable::sortedPosForId(const QString &id) const { int pos{0}; for(int i=0; i int GenericTable::sortedPosForName(const QString &name) const { int pos{0}; for(int i=0; i QString GenericTable::idForName(const QString &name) const { for(int i=0; i void GenericTable::clear() { m_list.clear(); } template void GenericTable::remove(const QString &id) { const int pos = indexOf(id); if (pos >= 0) { m_list.removeAt(pos); } } template void GenericTable::remove(const int &row) { if (rowExists(row)) { m_list.removeAt(row); } } //! Make linker happy and provide which table instances will be used. //! The alternative would be to move functions definitions in the header file //! but that would drop readability template class GenericTable; template class GenericTable; template class GenericTable; } }