Skip to content

Commit

Permalink
Consolidated TypeRegistry utterances from Autowiring.h to a single ut…
Browse files Browse the repository at this point in the history
…terance in CoreContext.h
  • Loading branch information
gtremper committed Aug 7, 2014
1 parent a0dfafa commit 50025ad
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
13 changes: 2 additions & 11 deletions autowiring/Autowired.h
Expand Up @@ -4,7 +4,6 @@
#include "Decompose.h"
#include "Deferred.h"
#include "GlobalCoreContext.h"
#include "TypeRegistry.h"
#include MEMORY_HEADER
#include ATOMIC_HEADER

Expand Down Expand Up @@ -121,8 +120,6 @@ class Autowired:
AutowirableSlot<T>(ctxt ? ctxt->template ResolveAnchor<T>() : ctxt),
m_pFirstChild(nullptr)
{
// Add this type to the TypeRegistry
(void) RegType<T>::r;
if(ctxt)
ctxt->Autowire(*this);
}
Expand Down Expand Up @@ -254,21 +251,15 @@ class AutoRequired:
// !!!!! Read comment in Autowired if you get a compiler error here !!!!!
AutoRequired(const std::shared_ptr<CoreContext>& ctxt = CoreContext::CurrentContext()):
std::shared_ptr<T>(ctxt->template Inject<T>())
{
// Add this type to the TypeRegistry
(void) RegType<T>::r;
}
{}

/// <summary>
/// Construct overload, for types which take constructor arguments
/// </summary>
template<class... Args>
AutoRequired(const std::shared_ptr<CoreContext>& ctxt, Args&&... args) :
std::shared_ptr<T>(ctxt->template Construct<T>(std::forward<Args>(args)...))
{
// Add this type to the TypeRegistry
(void) RegType<T>::r;
}
{}

operator bool(void) const {
return IsAutowired();
Expand Down
12 changes: 12 additions & 0 deletions autowiring/CoreContext.h
Expand Up @@ -20,6 +20,7 @@
#include "ExceptionFilter.h"
#include "TeardownNotifier.h"
#include "EventRegistry.h"
#include "TypeRegistry.h"
#include "TypeUnifier.h"

#include <list>
Expand Down Expand Up @@ -521,6 +522,9 @@ class CoreContext:
/// </summary>
template<typename T, typename... Args>
std::shared_ptr<T> Construct(Args&&... args) {
// Add this type to the TypeRegistry
(void) RegType<T>::r;

// If T doesn't inherit Object, then we need to compose a unifying type which does
typedef typename SelectTypeUnifier<T>::type TActual;
static_assert(std::is_base_of<Object, TActual>::value, "Constructive type does not implement Object as expected");
Expand Down Expand Up @@ -934,6 +938,13 @@ class CoreContext:
}
};

namespace autowiring {
template<typename T>
void InjectCurrent(void){
CoreContext::InjectCurrent<T>();
}
}

/// <summary>
/// Constant type optimization for named sigil types
/// </summary>
Expand All @@ -960,3 +971,4 @@ template<typename T, typename... Sigil>
void CoreContext::AutoRequireMicroBolt(void) {
Inject<MicroBolt<T, Sigil...>>();
}

8 changes: 6 additions & 2 deletions autowiring/TypeRegistry.h
@@ -1,11 +1,15 @@
// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved.
#pragma once
#include "CreationRules.h"
#include "CoreContext.h"
#include "TypeIdentifier.h"
#include STL_TUPLE_HEADER
#include MEMORY_HEADER

namespace autowiring {
template<typename T>
void InjectCurrent(void);
}

struct TypeRegistryEntry {
TypeRegistryEntry(const std::type_info& ti);

Expand Down Expand Up @@ -65,7 +69,7 @@ struct TypeRegistryEntryT:

template<typename U>
typename std::enable_if<is_injectable<U>::value>::type AnyInject(void) const {
CoreContext::CurrentContext()->Inject<U>();
autowiring::InjectCurrent<U>();
}

template<typename U>
Expand Down
2 changes: 0 additions & 2 deletions src/autowiring/test/MarshalingTest.cpp
Expand Up @@ -29,8 +29,6 @@ If the types aren't POD. At the very least, tests need to be written which viola
"I can do everything with stringstreams" implementation currently passing
*/



struct StandardType : public Auto::Serialize{
std::string m_str1;
std::string m_str2;
Expand Down

0 comments on commit 50025ad

Please sign in to comment.