-
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.
Added MicroAutoFilter to wrap std::function.
- Loading branch information
Gabriel Hare
committed
Aug 7, 2014
1 parent
8ce38bb
commit 652cda6
Showing
4 changed files
with
63 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. | ||
#pragma once | ||
|
||
#include "is_auto_filter.h" | ||
#include "Deferred.h" | ||
|
||
/// <summary> | ||
/// Transmutes a function returning void to an instance that can be called by AutoPacket. | ||
/// The specializations distinguish between void and Deferred return types. | ||
/// </summary> | ||
/// <remarks> | ||
/// The default constructor yields an AutoFilter that does nothing. | ||
/// </remarks> | ||
template<class Ret, class... Args> | ||
struct MicroAutoFilter { | ||
// This case pertains only when the return value is not recognized | ||
static_assert(is_auto_filter_return<Ret>{}, | ||
"The return is not an allowed type for AutoFilter methods"); | ||
}; | ||
template<class... Args> | ||
struct MicroAutoFilter<void, Args...> { | ||
MicroAutoFilter(const std::function<void(Args...)>& filter) : m_filter(filter) { | ||
static_assert(all_auto_filter_args<Args...>::value, | ||
"At least one argument is not an allowed type for AutoFilter methods"); | ||
} | ||
|
||
void AutoFilter(Args... args) { | ||
if (m_filter) | ||
return m_filter(args...); | ||
} | ||
|
||
protected: | ||
std::function<void(Args...)> m_filter; | ||
}; | ||
template<class... Args> | ||
struct MicroAutoFilter<Deferred, Args...> { | ||
MicroAutoFilter(const std::function<void(Args...)>& filter) : m_filter(filter) { | ||
static_assert(all_auto_filter_args<Args...>::value, | ||
"At least one argument is not an allowed type for AutoFilter methods"); | ||
} | ||
|
||
Deferred AutoFilter(Args... args) { | ||
if (m_filter) | ||
return m_filter(args...); | ||
return Deferred(this); | ||
} | ||
|
||
protected: | ||
std::function<void(Args...)> m_filter; | ||
}; |
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
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