sortedvector.h 2.52 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/********************************************************************************************
 *                                                                                          *
 * Copyright (C) 2017 Armin Felder, Dennis Beier                                            *
 * This file is part of RocketChatMobileEngine <https://git.fairkom.net/chat/fairchat>.     *
 *                                                                                          *
 * RocketChatMobileEngine 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 3 of the License, or                        *
 * (at your option) any later version.                                                      *
 *                                                                                          *
 * RocketChatMobileEngine 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 RocketChatMobileEngine. If not, see <http://www.gnu.org/licenses/>.           *
 *                                                                                          *
 ********************************************************************************************/


armin's avatar
fixes  
armin committed
22
23
24
25
26
#ifndef SORTEDVECTOR_H
#define SORTEDVECTOR_H

#include <QVector>
#include <QSharedPointer>
Armin Felder's avatar
Armin Felder committed
27
#include <QMutex>
Armin Felder's avatar
Armin Felder committed
28

armin's avatar
armin committed
29
30
struct SortedVectorProperties {
    enum class sortOrder {
Armin Felder's avatar
Armin Felder committed
31
32
33
34
        asc,
        dsc
    };
};
35
template<typename T> class SortedVector : public QVector<QSharedPointer<T>>
armin's avatar
fixes  
armin committed
36
{
37
    public:
Armin Felder's avatar
Armin Felder committed
38

armin's avatar
cleanup    
armin committed
39
        int insertSort( const QSharedPointer<T> & );
40
        int findInsertPosition( const QSharedPointer<T> & ) const;
41
        int findPosition( const QSharedPointer<T> & ) const;
armin's avatar
armin committed
42
        std::tuple<int, int> reOrder();
armin's avatar
cleanup    
armin committed
43
        bool operator =( const QVector<QSharedPointer<T>> &o )
44
45
46
47
48
        {
            this->clear();
            this->append( o );
            return true;
        }
armin's avatar
armin committed
49
    private:
Armin Felder's avatar
Armin Felder committed
50
        mutable QMutex mSortMutex;
armin's avatar
fixes  
armin committed
51
52
53
};
#include "sortedvector.cpp"
#endif // SORTEDVECTOR_H