/*
    This file is part of the Okteta Core library, made within the KDE community.

    SPDX-FileCopyrightText: 2008 Friedrich W. H. Kossebau <kossebau@kde.org>

    SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/

#ifndef KPIECETABLE_PIECELIST_HPP
#define KPIECETABLE_PIECELIST_HPP

// lib
#include "piece.hpp"
// Qt
#include <QVector>

namespace KPieceTable {

class PieceList
{
public:
    PieceList();
    explicit PieceList(const Piece& piece);
    PieceList(const PieceList&);

    ~PieceList();

    PieceList& operator=(const PieceList&) = default;

public:
    int size() const;
    bool isEmpty() const;
    Size totalLength() const;
    const Piece& at(int i) const;

    using ConstIterator = QVector<Piece>::ConstIterator;

    ConstIterator begin() const;
    ConstIterator end() const;

public:
    void append(const Piece& piece);
    void append(const PieceList& other);
    void prepend(const PieceList& other);

private:
    QVector<Piece> mList;
    Size mTotalLength = 0;
};

inline PieceList::PieceList() = default;
inline PieceList::PieceList(const PieceList&) = default;
inline PieceList::PieceList(const Piece& piece)
{
    append(piece);
}

inline PieceList::~PieceList() = default;

inline int PieceList::size()             const { return mList.size(); }
inline bool PieceList::isEmpty()         const { return mList.isEmpty(); }
inline Size PieceList::totalLength()     const { return mTotalLength; }
inline const Piece& PieceList::at(int i) const { return mList.at(i); }

inline PieceList::ConstIterator PieceList::begin() const { return mList.begin(); }
inline PieceList::ConstIterator PieceList::end() const { return mList.end(); }

}

#endif
