Visual Computing Library  devel
Loading...
Searching...
No Matches
selection.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_MESH_VIEWS_COMPONENTS_SELECTION_H
24#define VCL_MESH_VIEWS_COMPONENTS_SELECTION_H
25
26#include <vclib/base.h>
27
28#include <ranges>
29
30namespace vcl::views {
31
32namespace detail {
33
34inline constexpr auto isSelected = [](auto&& e) -> decltype(auto) {
35 if constexpr (vcl::IsPointer<decltype(e)>) {
36 return e->selected();
37 }
38 else {
39 return e.selected();
40 }
41};
42
43inline constexpr auto isNotSelected = [](auto&& e) -> decltype(auto) {
44 if constexpr (vcl::IsPointer<decltype(e)>) {
45 return !e->selected();
46 }
47 else {
48 return !e.selected();
49 }
50};
51
52struct SelectionView
53{
54 constexpr SelectionView() = default;
55
56 template<std::ranges::range R>
57 friend constexpr auto operator|(R&& r, SelectionView)
58 {
59 return std::forward<R>(r) | std::views::transform(isSelected);
60 }
61};
62
63struct SelectedView
64{
65 constexpr SelectedView() = default;
66
67 template<std::ranges::range R>
68 friend constexpr auto operator|(R&& r, SelectedView)
69 {
70 return std::forward<R>(r) | std::views::filter(isSelected);
71 }
72};
73
74struct NotSelectedView
75{
76 constexpr NotSelectedView() = default;
77
78 template<std::ranges::range R>
79 friend constexpr auto operator|(R&& r, NotSelectedView)
80 {
81 return std::forward<R>(r) | std::views::filter(isNotSelected);
82 }
83};
84
85} // namespace detail
86
87inline constexpr detail::SelectionView selection;
88inline constexpr detail::SelectedView selected;
89inline constexpr detail::NotSelectedView notSelected;
90
91} // namespace vcl::views
92
93#endif // VCL_MESH_VIEWS_COMPONENTS_SELECTION_H
The IsPointer concept is satisfied if T is a Pointer, even if the type T is a reference to a pointer.
Definition pointers.h:54