14#include <AUI/Common/AVector.h>
15#include <AUI/Common/ASignal.h>
16#include "AListModelIndex.h"
17#include "IMutableListModel.h"
18#include <AUI/Traits/strings.h>
20namespace aui::detail {
24template <
typename StoredType>
30 using self = AListModel<StoredType>;
33 using iterator =
typename decltype(mVector)::iterator;
34 using const_iterator =
typename decltype(mVector)::const_iterator;
35 using size_type =
typename decltype(mVector)::size_type;
36 using value_type =
typename decltype(mVector)::value_type;
38 AListModel() =
default;
39 AListModel(
const self& s): mVector(s.mVector) {}
40 AListModel(self&& s)
noexcept: mVector(std::move(s.mVector)) {}
45 mVector = std::move(rhs);
51 void setItem(
const AListModelIndex& item,
const StoredType& value)
override {
52 mVector[item.getRow()] = value;
56 bool empty()
const noexcept {
57 return mVector.empty();
59 void reserve(
size_t s)
noexcept {
62 void resize(
size_t s)
noexcept {
66 iterator erase(iterator begin)
noexcept {
67 return this->erase(begin, begin + 1);
69 iterator erase(iterator begin, iterator end)
noexcept {
70 auto range = this->range(
AListModelIndex{size_t(begin - mVector.begin())},
72 auto it = mVector.erase(begin, end);
79 void push_back(
const StoredType& data) {
80 insert(end(), std::move(data));
83 void push_back(StoredType&& data) {
84 insert(end(), std::forward<StoredType>(data));
87 const_iterator insert(const_iterator
at, StoredType data) {
88 at = mVector.insert(
at, std::move(data));
94 void pop_back()
noexcept {
100 AListModel& operator<<(
const StoredType& data) {
104 AListModel& operator<<(StoredType&& data) {
105 push_back(std::forward<StoredType>(data));
109 size_t listSize()
override {
110 return mVector.size();
114 return mVector.at(index.getRow());
116 void invalidate(
size_t index) {
120 void invalidate(iterator index) {
121 invalidate(std::distance(begin(), index));
124 void clear()
noexcept {
125 erase(mVector.begin(), mVector.end());
129 erase(mVector.begin() + items.begin().getIndex().getRow(), mVector.end() + items.begin().getIndex().getRow());
133 erase(mVector.begin() + item.getRow());
137 size_t size()
const noexcept {
138 return mVector.size();
152 const StoredType&
at(
size_t index)
const {
153 if (index >= size())
throw AException(
"index of bounds: {} (size {})"_format(index, size()));
154 return *(mVector.begin() + index);
175 StoredType&
at(
size_t index) {
176 if (index >= size())
throw AException(
"index of bounds: {} (size {})"_format(index, size()));
177 return *(mVector.begin() + index);
188 AUI_ASSERTX(size() > index,
"index out of bounds");
189 return *(mVector.begin() + index);
205 const_iterator begin()
const {
206 return mVector.begin();
208 const_iterator end()
const {
209 return mVector.end();
213 return mVector.begin();
216 return mVector.end();
228 auto list = _new<AListModel<StoredType>>();
229 list->reserve(t.size());
230 for (
auto& item : t) {
231 list->push_back(item);
245 auto list = _new<AListModel<StoredType>>();
246 list->mVector = std::move(t);
259 auto list = _new<AListModel<StoredType>>();
264 template<
typename UnaryOperation>
265 auto map(UnaryOperation&& transformer) {
266 return mVector.map(std::forward<UnaryOperation>(transformer));
270 const AVector<StoredType>& toVector() noexcept {
Abstract AUI exception.
Definition AException.h:28
Definition AListModelIndex.h:20
Definition AListModelRange.h:23
static _< AListModel< StoredType > > fromVector(std::vector< V > t)
Definition AListModel.h:258
static _< AListModel< StoredType > > fromVector(AVector< V > t)
Definition AListModel.h:244
void removeAt(size_t index) noexcept
Definition AListModel.h:200
StoredType & at(size_t index)
Definition AListModel.h:175
const StoredType & operator[](size_t index) const
Definition AListModel.h:187
const StoredType & at(size_t index) const
Definition AListModel.h:152
static _< AListModel< StoredType > > make(const std::initializer_list< V > &t)
Definition AListModel.h:227
A std::vector with AUI extensions.
Definition AVector.h:39
emits< AListModelRange< StoredType > > dataInserted
Definition IListModel.h:88
emits< AListModelRange< StoredType > > dataChanged
Definition IListModel.h:83
emits< AListModelRange< StoredType > > dataRemoved
Definition IListModel.h:93
Definition IMutableListModel.h:20
Definition IMutableListModel.h:36
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:178
void remove_at(Container &c, size_t index) noexcept
Removes element at the specified index.
Definition containers.h:98
#define emit
emits the specified signal in context of this object.
Definition AObject.h:310
#define AUI_ASSERTX(condition, what)
Asserts that the passed condition evaluates to true. Adds extra message string.
Definition Assert.h:74