MeshLib C++ Docs
Loading...
Searching...
No Matches
MRViewportProperty.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRViewportId.h"
4#include <map>
5
6namespace MR
7{
8
12
15template<typename T>
17{
18public:
19 ViewportProperty() = default;
20 ViewportProperty( const T& def ) :def_{ def } {}
21 bool operator==( const ViewportProperty& ) const = default;
23 void set( T def ) { def_ = std::move( def ); }
25 const T & get() const { return def_; }
26 T & get() { return def_; }
27
30 {
31 return id ? map_[id] : def_;
32 }
33
34 void set( T v, ViewportId id )
35 {
36 (*this)[id] = std::move( v );
37 }
38
40 const T & get( ViewportId id, bool * isDef = nullptr ) const
41 {
42 if ( id )
43 {
44 auto it = map_.find( id );
45 if ( it != map_.end() )
46 {
47 if ( isDef )
48 *isDef = false;
49 return it->second;
50 }
51 }
52 if ( isDef )
53 *isDef = true;
54 return def_;
55 }
56
58 bool reset( ViewportId id )
59 {
60 if ( id )
61 return map_.erase( id ) > 0;
62 if ( map_.empty() )
63 return false;
64 map_.clear();
65 return true;
66 }
67
69 bool reset()
70 {
71 if ( map_.empty() )
72 return false;
73 map_.clear();
74 return true;
75 }
76
77private:
78 T def_{};
79 std::map<ViewportId, T> map_;
80};
81
83
84}
Definition MRViewportId.h:16
ViewportProperty()=default
ViewportProperty(const T &def)
Definition MRViewportProperty.h:20
T & get()
Definition MRViewportProperty.h:26
bool operator==(const ViewportProperty &) const =default
void set(T v, ViewportId id)
sets specific property value for given viewport (or default value if !id)
Definition MRViewportProperty.h:34
T & operator[](ViewportId id)
returns direct access to value associated with given viewport (or default value if !...
Definition MRViewportProperty.h:29
const T & get() const
gets default property value
Definition MRViewportProperty.h:25
const T & get(ViewportId id, bool *isDef=nullptr) const
Definition MRViewportProperty.h:40
bool reset()
Definition MRViewportProperty.h:69
void set(T def)
sets default property value
Definition MRViewportProperty.h:23
bool reset(ViewportId id)
Definition MRViewportProperty.h:58
only for bindings generation
Definition MRCameraOrientationPlugin.h:8