-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finished implementation of AutoSelfUpdate, which is used to provide p…
…rior data.
- Loading branch information
1 parent
43879a2
commit eeb315f
Showing
2 changed files
with
36 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,51 @@ | ||
// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. | ||
#pragma once | ||
#include "Autowiring/NewAutoFilter.h" | ||
#include "Autowiring/atomic_object.h" | ||
#include "Autowiring/shared_object.h" | ||
|
||
///<summary> | ||
///Enables an automatic self-update when a packet is decorated with the object type. | ||
///Provides the prior object (the last decorated instance) to all subsequent packets. | ||
///</summary> | ||
///<remarks> | ||
///In order to ensure that this method will be consistent with any other AutoFilter calls, | ||
///the object inherits from atomic_object, which implements basic locking functionality. | ||
///the object inherits from shared_object, which implements basic locking functionality. | ||
///</remarks> | ||
template<class object, class lock = std::mutex> | ||
class AutoSelfUpdate: | ||
public atomic_object<object, lock> { | ||
public shared_object<object, lock> { | ||
protected: | ||
using shared_object<object, lock>::get_lock; | ||
using shared_object<object, lock>::get_object; | ||
|
||
public: | ||
AutoSelfUpdate() {} | ||
AutoSelfUpdate(const shared_object<object, lock>& source) : shared_object<object, lock>(source) {} | ||
AutoSelfUpdate(const object& source) : shared_object<object, lock>(source) {} | ||
using shared_object<object, lock>::operator =; | ||
using shared_object<object, lock>::operator object; | ||
|
||
//The distinct type assigned to the prior value of the object | ||
class prior_object: public object { | ||
public: | ||
prior_object(const object& source): object(source) {} | ||
}; | ||
|
||
//Avoid intermediate copy by defining an explicit cast | ||
operator prior_object() const { | ||
std::lock_guard<lock> lock_this(get_lock()); | ||
return prior_object(get_object()); | ||
} | ||
|
||
//Decorates all packets with instances of prior_object | ||
void AutoFilter(AutoPacket& packet) { | ||
//TODO: Decorate with prior<object> | ||
packet.Decorate(this->operator prior_object()); | ||
} | ||
|
||
void SelfUpdate(object& update) { | ||
atomic_object<object, lock>::operator = (update); | ||
//Updates this object | ||
void AutoGather(const object& update) { | ||
shared_object<object, lock>::operator = (update); | ||
} | ||
|
||
NewAutoFilter<decltype(&AutoSelfUpdate<object>::SelfUpdate), &AutoSelfUpdate<object>::SelfUpdate> AutoFilter_SelfUpdate; | ||
NewAutoFilter<decltype(&AutoSelfUpdate<object>::AutoGather), &AutoSelfUpdate<object>::AutoGather> SelfUpdate; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters