MeshLib
 
Loading...
Searching...
No Matches
MRViewportId.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
4#include <cassert>
5
6namespace MR
7{
8
12
16{
17public:
18 ViewportId() noexcept = default;
19 explicit constexpr ViewportId( unsigned i ) noexcept : id_( i ) { }
20
21 constexpr unsigned value() const { return id_; }
22 bool valid() const { return id_ > 0; }
23 explicit operator bool() const { return id_ > 0; }
24
25 bool operator == ( ViewportId b ) const { return id_ == b.id_; }
26 bool operator != ( ViewportId b ) const { return id_ != b.id_; }
27 bool operator < ( ViewportId b ) const { return id_ < b.id_; }
28
29 ViewportId next() const { return ViewportId{ id_ << 1 }; }
30 ViewportId prev() const { return ViewportId{ id_ >> 1 }; }
31
32private:
33 unsigned id_ = 0;
34};
35
38{
39public:
40 ViewportMask() noexcept = default;
41 explicit constexpr ViewportMask( unsigned i ) noexcept : mask_( i ) { }
42 constexpr ViewportMask( ViewportId i ) noexcept : mask_( i.value() ) { }
43
45 static ViewportMask all() { return ViewportMask{ ~0u }; }
46 static ViewportMask any() { return ViewportMask{ ~0u }; }
47
48 constexpr unsigned value() const { return mask_; }
49 constexpr bool empty() const { return mask_ == 0; }
50 bool contains( ViewportId id ) const { assert( id.valid() ); return ( mask_ & id.value() ) != 0; }
51
52 bool operator == ( ViewportMask b ) const { return mask_ == b.mask_; }
53 bool operator != ( ViewportMask b ) const { return mask_ != b.mask_; }
54 bool operator < ( ViewportMask b ) const { return mask_ < b.mask_; }
55
56 ViewportMask operator~() const { ViewportMask res; res.mask_ = ~mask_; return res; }
57
58 ViewportMask & operator &= ( ViewportMask b ) { mask_ &= b.mask_; return * this; }
59 ViewportMask & operator |= ( ViewportMask b ) { mask_ |= b.mask_; return * this; }
60 ViewportMask & operator ^= ( ViewportMask b ) { mask_ ^= b.mask_; return * this; }
61
62 void set( ViewportId id, bool on = true ) { on ? ( mask_ |= id.value() ) : ( mask_ &= ~id.value() ); }
63
64private:
65 unsigned mask_ = 0;
66};
67
68inline ViewportMask operator & ( ViewportMask a, ViewportMask b ) { a &= b; return a; }
69inline ViewportMask operator | ( ViewportMask a, ViewportMask b ) { a |= b; return a; }
70inline ViewportMask operator ^ ( ViewportMask a, ViewportMask b ) { a ^= b; return a; }
71
74{
75public:
76 using iterator_category = std::forward_iterator_tag;
78
80 ViewportIterator() = default;
83 : mask_( mask )
84 {
85 findFirst_();
86 }
88 {
89 findNext_();
90 return * this;
91 }
92 ViewportMask mask() const { return mask_; }
93 ViewportId operator *() const { return id_; }
94
95private:
96 void findFirst_()
97 {
98 id_ = ViewportId{1};
99 for( ; id_.valid() && !mask_.contains( id_ ); id_ = id_.next() );
100 }
101 void findNext_()
102 {
103 assert( id_.valid() );
104 for( id_ = id_.next(); id_.valid() && !mask_.contains( id_ ); id_ = id_.next() );
105 }
106
107 ViewportId id_{0};
108 ViewportMask mask_{0};
109};
110
111inline bool operator ==( const ViewportIterator & a, const ViewportIterator & b )
112 { return *a == *b; }
113
114inline auto begin( ViewportMask mask )
115 { return ViewportIterator( mask ); }
116inline auto end( ViewportMask )
117 { return ViewportIterator(); }
118
120
121} // namespace MR
Definition MRViewportId.h:16
ViewportId next() const
Definition MRViewportId.h:29
ViewportId() noexcept=default
bool operator!=(ViewportId b) const
Definition MRViewportId.h:26
bool valid() const
Definition MRViewportId.h:22
bool operator<(ViewportId b) const
Definition MRViewportId.h:27
constexpr unsigned value() const
Definition MRViewportId.h:21
bool operator==(ViewportId b) const
Definition MRViewportId.h:25
ViewportId prev() const
Definition MRViewportId.h:30
iterates over all ViewportIds in given ViewportMask
Definition MRViewportId.h:74
ViewportIterator()=default
constructs end iterator
ViewportMask mask() const
Definition MRViewportId.h:92
ViewportIterator & operator++()
Definition MRViewportId.h:87
ViewportId operator*() const
Definition MRViewportId.h:93
ViewportIterator(ViewportMask mask)
constructs begin iterator
Definition MRViewportId.h:82
std::forward_iterator_tag iterator_category
Definition MRViewportId.h:76
stores mask of viewport unique identifiers
Definition MRViewportId.h:38
static ViewportMask any()
Definition MRViewportId.h:46
ViewportMask & operator&=(ViewportMask b)
Definition MRViewportId.h:58
bool contains(ViewportId id) const
Definition MRViewportId.h:50
ViewportMask & operator^=(ViewportMask b)
Definition MRViewportId.h:60
ViewportMask & operator|=(ViewportMask b)
Definition MRViewportId.h:59
ViewportMask operator~() const
Definition MRViewportId.h:56
bool operator==(ViewportMask b) const
Definition MRViewportId.h:52
void set(ViewportId id, bool on=true)
Definition MRViewportId.h:62
static ViewportMask all()
mask meaning all or any viewports
Definition MRViewportId.h:45
constexpr ViewportMask(ViewportId i) noexcept
Definition MRViewportId.h:42
bool operator<(ViewportMask b) const
Definition MRViewportId.h:54
ViewportMask() noexcept=default
bool operator!=(ViewportMask b) const
Definition MRViewportId.h:53
constexpr bool empty() const
Definition MRViewportId.h:49
constexpr unsigned value() const
Definition MRViewportId.h:48
auto begin(const BitSet &a)
Definition MRMesh/MRBitSet.h:263
MRMESH_API bool operator==(const BitSet &a, const BitSet &b)
compare that two bit sets have the same set bits (they can be equal even if sizes are distinct but la...
auto end(const BitSet &)
Definition MRMesh/MRBitSet.h:265
BitSet operator&(const BitSet &a, const BitSet &b)
Definition MRMesh/MRBitSet.h:322
BitSet operator|(const BitSet &a, const BitSet &b)
Definition MRMesh/MRBitSet.h:323
BitSet operator^(const BitSet &a, const BitSet &b)
Definition MRMesh/MRBitSet.h:324
Definition MRCameraOrientationPlugin.h:7