NDEVR
API Documentation
Resource.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: Resource
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/ResourceListener.h>
34namespace NDEVR
35{
40 template<class T>
41 class Resource final : public ResourceBase
42 {
43 public:
48 explicit Resource(const T& value)
49 : ResourceBase()
50 , m_value(value)
51 {}
52
53 Resource(const Resource<T>& value) = delete;
54 Resource<T>& operator=(const Resource<T>&) = delete;
55 virtual ~Resource(){};
56
62 void set(const T& info, bool check_equal = true)
63 {
64 if(check_equal && isEqualTo(info))
65 {
66 return;
67 }
68 m_value = info;
70 }
71
76 void set(T&& info, bool check_equal = true)
77 {
78 if(check_equal && isEqualTo(info))
79 {
80 return; // Do nothing on same value
81 }
82 std::swap(m_value, info);
84 }
85
89 const T& get() const
90 {
91 return m_value;
92 }
93
98 void getCopy(T& copy) const
99 {
100 copy = m_value;
101 }
102
108 {
109 return m_value;
110 }
111
112
118 bool isEqualTo(const T& value) const
119 {
120 return value == m_value;
121 }
122
123
124
125 private:
126 T m_value;
127
128 };
129
130
131};
ResourceBase()
Constructs a default ResourceBase with no listeners.
void refreshListeners()
Notifies all registered listeners that the resource value has changed.
void getCopy(T &copy) const
Copies the stored value into the provided output parameter.
Definition Resource.h:98
Resource(const T &value)
Constructs a Resource with an initial value.
Definition Resource.h:48
Resource(const Resource< T > &value)=delete
Copy constructor is deleted to enforce unique ownership.
Resource< T > & operator=(const Resource< T > &)=delete
Copy assignment is deleted to enforce unique ownership.
void set(const T &info, bool check_equal=true)
Destructor.
Definition Resource.h:62
const T & get() const
Returns a const reference to the stored value.
Definition Resource.h:89
void set(T &&info, bool check_equal=true)
Sets the stored value by move and notifies all listeners.
Definition Resource.h:76
bool isEqualTo(const T &value) const
Checks whether the given value is equal to the stored value.
Definition Resource.h:118
T & getModifiable()
Returns a mutable reference to the stored value without notifying listeners.
Definition Resource.h:107
The primary namespace for the NDEVR SDK.