NDEVR
API Documentation
ResourceMirror.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: ResourceMirror
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/Resource.h>
34namespace NDEVR
35{
40 template<class t_type>
42 {
43 public:
51 , a(a)
52 , b(b)
53 {
54 a.addListener(this);
55 b.addListener(this, true);
56 }
57
61 virtual ~ResourceMirror() {}
62
67 virtual void addInfoParent(const ResourceBase* info) override
68 {
70 }
71
75 virtual void removeInfoParent(const ResourceBase* info) override
76 {
79 }
80
84 virtual void onValueChanged() override
85 {
86 if (a.get() != value)
87 {
88 value = a.get();
89 b.set(value);
90 }
91 else if (b.get() != value)
92 {
93 value = b.get();
94 a.set(value);
95 }
96 }
99 t_type value;
100 };
101}
A base class for templated resources.
virtual void removeInfoParent(const ResourceBase *info)
Removes a ResourceBase from the list of parents this listener is observing.
ResourceListener()
Constructs a default ResourceListener.
virtual void addInfoParent(const ResourceBase *info)
Registers a ResourceBase as a parent that this listener is observing.
void disconnectListener()
Disconnects this listener from all parent resources it is subscribed to.
t_type value
The last known synchronized value, used to detect which resource changed.
Resource< t_type > & a
The first mirrored resource.
virtual void addInfoParent(const ResourceBase *info) override
Registers a parent resource that this listener depends on.
virtual void removeInfoParent(const ResourceBase *info) override
Removes a parent resource and disconnects this listener.
virtual void onValueChanged() override
Called when either mirrored resource changes.
ResourceMirror(Resource< t_type > &a, Resource< t_type > &b)
Constructs a ResourceMirror that synchronizes two resources bidirectionally.
virtual ~ResourceMirror()
Destructor.
Resource< t_type > & b
The second mirrored resource.
A core part of the engine, stores variables that can be listened to with ResourceListener which will ...
Definition Resource.h:42
The primary namespace for the NDEVR SDK.