neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
i_basic_item_model.hpp
Go to the documentation of this file.
1// i_item_model.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
23#include "i_item_model.hpp"
24
25namespace neogfx
26{
27 template <typename T>
28 class i_basic_item_model : public i_item_model
29 {
30 public:
31 typedef T value_type;
32 public:
33 virtual iterator insert_item(const_iterator aPosition, value_type const& aValue) = 0;
34 virtual iterator insert_item(const_iterator aPosition, value_type const& aValue, item_cell_data const& aCellData) = 0;
35 virtual iterator insert_item(item_model_index const& aIndex, value_type const& aValue) = 0;
36 virtual iterator insert_item(item_model_index const& aIndex, value_type const& aValue, item_cell_data const& aCellData) = 0;
37 virtual iterator append_item(value_type const& aValue) = 0;
38 virtual iterator append_item(value_type const& aValue, item_cell_data const& aCellData) = 0;
39 virtual iterator append_item(const_iterator aParent, value_type const& aValue) = 0;
40 virtual iterator append_item(const_iterator aParent, value_type const& aValue, item_cell_data const& aCellData) = 0;
41 virtual iterator append_item(item_model_index const& aIndex, value_type const& aValue) = 0;
42 virtual iterator append_item(item_model_index const& aIndex, value_type const& aValue, item_cell_data const& aCellData) = 0;
43 public:
44 virtual value_type& item(item_model_index const& aIndex) = 0;
45 virtual value_type const& item(item_model_index const& aIndex) const = 0;
46 public:
47 value_type& item(const_iterator aItem)
48 {
49 return item(iterator_to_index(aItem));
50 }
51 value_type const& item(const_iterator aItem) const
52 {
53 return item(iterator_to_index(aItem));
54 }
55 std::optional<item_model_index> find_item_maybe(value_type const& aItem) const
56 {
57 auto const end = rows();
58 for (item_model_index::row_type row = 0; row < end; ++row)
59 {
60 auto const& existing = item(item_model_index{ row, 0 });
61 if (existing == aItem)
62 return item_model_index{ row, 0 };
63 }
64 return std::nullopt;
65 }
67 {
68 auto result = find_item_maybe(aItem);
69 if (result != std::nullopt)
70 return *result;
71 throw item_not_found();
72 }
73 };
74}
virtual iterator append_item(const_iterator aParent, value_type const &aValue)=0
value_type const & item(const_iterator aItem) const
virtual iterator append_item(item_model_index const &aIndex, value_type const &aValue, item_cell_data const &aCellData)=0
virtual iterator append_item(item_model_index const &aIndex, value_type const &aValue)=0
virtual iterator insert_item(const_iterator aPosition, value_type const &aValue)=0
virtual iterator insert_item(item_model_index const &aIndex, value_type const &aValue, item_cell_data const &aCellData)=0
virtual value_type const & item(item_model_index const &aIndex) const =0
virtual iterator append_item(const_iterator aParent, value_type const &aValue, item_cell_data const &aCellData)=0
virtual iterator append_item(value_type const &aValue, item_cell_data const &aCellData)=0
virtual value_type & item(item_model_index const &aIndex)=0
std::optional< item_model_index > find_item_maybe(value_type const &aItem) const
virtual iterator insert_item(const_iterator aPosition, value_type const &aValue, item_cell_data const &aCellData)=0
value_type & item(const_iterator aItem)
virtual iterator append_item(value_type const &aValue)=0
item_model_index find_item(value_type const &aItem) const
virtual iterator insert_item(item_model_index const &aIndex, value_type const &aValue)=0