API Documentation
Loading...
Searching...
No Matches
Resource.h
Go to the documentation of this file.
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{
36 /**--------------------------------------------------------------------------------------------------
37 \brief A core part of the engine, stores variables that can be listened to with ResourceListener
38 which will recieve updates when changed.
39 **/
40 template<class T>
41 class Resource final : public ResourceBase
42 {
43 public:
44 explicit Resource(const T& value)
45 : ResourceBase()
46 , m_value(value)
47 {}
48
49 Resource(const Resource<T>& value) = delete;
51 virtual ~Resource(){};
52
53 void set(const T& info, bool check_equal = true)
54 {
55 if(check_equal && isEqualTo(info))
56 {
57 return;
58 }
59 m_value = info;
61 }
62 void set(T&& info, bool check_equal = true)
63 {
64 if(check_equal && isEqualTo(info))
65 {
66 return; // Do nothing on same value
67 }
68 std::swap(m_value, info);
70 }
71 const T& get() const
72 {
73 return m_value;
74 }
75
76 void getCopy(T& copy) const
77 {
78 copy = m_value;
79 }
80
82 {
83 return m_value;
84 }
85
86
87 bool isEqualTo(const T& value) const
88 {
89 return value == m_value;
90 }
91
92
93
94 private:
95 T m_value;
96
97 };
98
99
100};
A base class for templated resources.
Definition ResourceListener.h:43
A core part of the engine, stores variables that can be listened to with ResourceListener which will ...
Definition Toggle.h:41
Resource(const Resource< T > &value)=delete
Resource(const T &value)
Definition Resource.h:44
T & getModifiable()
Definition Resource.h:81
const T & get() const
Definition Resource.h:71
virtual ~Resource()
Definition Resource.h:51
bool isEqualTo(const T &value) const
Definition Resource.h:87
void set(T &&info, bool check_equal=true)
Definition Resource.h:62
Resource< T > & operator=(const Resource< T > &)=delete
void getCopy(T &copy) const
Definition Resource.h:76
void set(const T &info, bool check_equal=true)
Definition Resource.h:53
Definition ACIColor.h:37