MeshLib
 
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 } {}
22 void set( T def ) { def_ = std::move( def ); }
24 const T & get() const { return def_; }
25 T & get() { return def_; }
26
29 {
30 return id ? map_[id] : def_;
31 }
33 void set( T v, ViewportId id )
34 {
35 (*this)[id] = std::move( v );
36 }
39 const T & get( ViewportId id, bool * isDef = nullptr ) const
40 {
41 if ( id )
42 {
43 auto it = map_.find( id );
44 if ( it != map_.end() )
45 {
46 if ( isDef )
47 *isDef = false;
48 return it->second;
49 }
50 }
51 if ( isDef )
52 *isDef = true;
53 return def_;
54 }
57 bool reset( ViewportId id )
58 {
59 if ( id )
60 return map_.erase( id ) > 0;
61 if ( map_.empty() )
62 return false;
63 map_.clear();
64 return true;
65 }
68 bool reset()
69 {
70 if ( map_.empty() )
71 return false;
72 map_.clear();
73 return true;
74 }
75
76private:
77 T def_{};
78 std::map<ViewportId, T> map_;
79};
80
82
83} // namespace MR
Definition MRViewportId.h:16
Definition MRViewportProperty.h:17
ViewportProperty()=default
ViewportProperty(const T &def)
Definition MRViewportProperty.h:20
T & get()
Definition MRViewportProperty.h:25
void set(T v, ViewportId id)
sets specific property value for given viewport (or default value if !id)
Definition MRViewportProperty.h:33
T & operator[](ViewportId id)
returns direct access to value associated with given viewport (or default value if !...
Definition MRViewportProperty.h:28
const T & get() const
gets default property value
Definition MRViewportProperty.h:24
const T & get(ViewportId id, bool *isDef=nullptr) const
Definition MRViewportProperty.h:39
bool reset()
Definition MRViewportProperty.h:68
void set(T def)
sets default property value
Definition MRViewportProperty.h:22
bool reset(ViewportId id)
Definition MRViewportProperty.h:57
Definition MRCameraOrientationPlugin.h:7