-
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.
Merge pull request #82 from leapmotion/feature-autoinit
AutoInit post-construction callback
- Loading branch information
Showing
5 changed files
with
91 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,45 @@ | ||
// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved. | ||
#pragma once | ||
#include "Decompose.h" | ||
|
||
template<class T> | ||
struct has_valid_autoinit { | ||
template<class Fn, Fn> | ||
struct unnamed_constant; | ||
|
||
template<class U> | ||
static std::false_type select(...); | ||
|
||
template<class U> | ||
static std::true_type select(unnamed_constant<decltype(&U::AutoInit), &U::AutoInit>*); | ||
|
||
// Conveninece typedef used externally: | ||
typedef decltype(select<T>(nullptr)) has_valid; | ||
|
||
// Evaluates to true only if T includes a unique AutoFilter method with at least one argument. | ||
static const bool value = has_valid::value; | ||
}; | ||
|
||
/// <summary> | ||
/// Detects whether the specified type T has a method with the name AutoInit | ||
/// </summary> | ||
/// <remarks> | ||
/// An auto-initializer routine is called after a shared pointer assignment has taken place, but before | ||
/// an entity is injected into the context. This affords a context member an opportunity to obtain and, | ||
/// optionally , distribute its own shared pointer before that entity becomes discoverable in that | ||
/// context. | ||
/// | ||
/// Note that this call is actually made before the type is actually injected in the context, so an | ||
/// attempt to perform Autowired<T> from AutoInit will necessarily fail. | ||
/// </remarks> | ||
template<class T> | ||
struct has_autoinit : has_valid_autoinit<T>::has_valid {}; | ||
|
||
template<class T> | ||
static void CallAutoInit(T& obj, std::true_type) { | ||
obj.AutoInit(); | ||
} | ||
|
||
template<class T> | ||
static void CallAutoInit(T&, std::false_type) {} | ||
|
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
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