File indexing completed on 2024-04-14 05:24:21

0001 /*
0002     SPDX-FileCopyrightText: 2020 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef GENERICTABLEDATA_H
0007 #define GENERICTABLEDATA_H
0008 
0009 // local
0010 #include "genericdata.h"
0011 
0012 // Qt
0013 #include <QList>
0014 
0015 namespace Latte {
0016 namespace Data {
0017 
0018 template <class T>
0019 class GenericTable
0020 {
0021 
0022 public:
0023     GenericTable();
0024     GenericTable(GenericTable<T> &&o);
0025     GenericTable(const GenericTable<T> &o);
0026 
0027     //! Operators
0028     GenericTable<T> &operator=(const GenericTable<T> &rhs);
0029     GenericTable<T> &operator=(GenericTable<T> &&rhs);
0030     GenericTable<T> &operator<<(const T &rhs);
0031     GenericTable<T> &operator<<(const GenericTable<T> &rhs);
0032     GenericTable<T> &insert(const int &pos, const T &rhs);
0033     GenericTable<T> &insertBasedOnName(const T &rhs);
0034     GenericTable<T> &insertBasedOnId(const T &rhs);
0035 
0036     bool operator==(const GenericTable<T> &rhs) const;
0037     bool operator!=(const GenericTable<T> &rhs) const;
0038     T &operator[](const QString &id);
0039     const T operator[](const QString &id) const;
0040     T &operator[](const uint &index);
0041     const T operator[](const uint &index) const;
0042     operator QString() const;
0043 
0044     bool containsId(const QString &id) const;
0045     bool containsName(const QString &name) const;
0046     bool isEmpty() const;
0047     bool rowExists(const int &row) const;
0048 
0049     int indexOf(const QString &id) const;
0050     int rowCount() const;
0051     int sortedPosForName(const QString &name) const;
0052     int sortedPosForId(const QString &id) const;
0053 
0054     QString idForName(const QString &name) const;
0055 
0056     QStringList ids() const;
0057     QStringList names() const;
0058 
0059     void clear();
0060     void remove(const int &row);
0061     void remove(const QString &id);
0062 
0063 protected:
0064     //! #id, record
0065     QList<T> m_list;
0066 
0067 };
0068 
0069 }
0070 }
0071 
0072 #endif