Skip to content

Commit

Permalink
Merge pull request #179 from leapmotion/bug-visibility
Browse files Browse the repository at this point in the history
Type visibility
  • Loading branch information
codemercenary committed Oct 28, 2014
2 parents dd914c8 + 653d7c3 commit 8050d6f
Show file tree
Hide file tree
Showing 34 changed files with 199 additions and 90 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -27,7 +27,7 @@ else()
endif()

if(NOT WIN32)
set(CMAKE_CXX_FLAGS "-std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libstdc++")
endif()
if(USE_LIBCXX)
Expand Down
34 changes: 9 additions & 25 deletions autowiring/AutoInjectable.h
Expand Up @@ -3,13 +3,15 @@
#include "AutoFuture.h"
#include "CoreContext.h"

class AutoInjectableExpressionBase
{
class AutoInjectableExpressionBase {
public:
virtual ~AutoInjectableExpressionBase(void) {}
AutoInjectableExpressionBase(void);
virtual ~AutoInjectableExpressionBase(void);
virtual void operator()(AutoFuture* pFuture) const = 0;
};

extern template class std::shared_ptr<AutoInjectableExpressionBase>;

/// <summary>
/// An expression type, which generally encapsulates a single injection operation
/// </summary>
Expand Down Expand Up @@ -99,29 +101,11 @@ class AutoInjectableExpressionFn:
class AutoInjectable
{
public:
AutoInjectable(AutoInjectableExpressionBase* pValue = nullptr) :
pValue(pValue),
pFLink(nullptr)
{}

AutoInjectable(AutoInjectable&& rhs):
pValue(rhs.pValue),
pFLink(rhs.pFLink)
{
rhs.pFLink = nullptr;
}

AutoInjectable(const AutoInjectable &rhs) :
pValue(rhs.pValue),
pFLink(rhs.pFLink ? new AutoInjectable(*rhs.pFLink) : nullptr)
{
}
AutoInjectable(AutoInjectableExpressionBase* pValue = nullptr);
AutoInjectable(AutoInjectable&& rhs);
AutoInjectable(const AutoInjectable &rhs);

~AutoInjectable()
{
delete pFLink;
pFLink = nullptr;
}
~AutoInjectable();

/// <summary>
/// Primary injection operation, injects this injectable's payload into the current context
Expand Down
2 changes: 2 additions & 0 deletions autowiring/AutoPacket.h
Expand Up @@ -19,6 +19,7 @@
#include STL_UNORDERED_MAP
#include EXCEPTION_PTR_HEADER

class AutoPacket;
class AutoPacketFactory;
class AutoPacketProfiler;
struct AutoFilterDescriptor;
Expand All @@ -40,6 +41,7 @@ class AutoPacket:
{
private:
AutoPacket(const AutoPacket& rhs) = delete;
AutoPacket(AutoPacket&&) = delete;
AutoPacket(AutoPacketFactory& factory, const std::shared_ptr<Object>& outstanding);

public:
Expand Down
8 changes: 7 additions & 1 deletion autowiring/AutoPacketFactory.h
Expand Up @@ -12,9 +12,9 @@
#include TYPE_TRAITS_HEADER
#include STL_UNORDERED_SET

struct AdjacencyEntry;
class Deferred;
class DispatchQueue;
struct AdjacencyEntry;

/// <summary>
/// A configurable factory class for pipeline packets with a built-in object pool
Expand Down Expand Up @@ -227,3 +227,9 @@ class AutoPacketFactory:
/// <returns>the number of outstanding AutoPackets</returns>
size_t GetOutstanding(void) const { return m_packets.GetOutstanding(); }
};

// Extern explicit template instantiation declarations added to prevent
// exterior instantation of internally used template instances
extern template class RegType<AutoPacketFactory>;
extern template struct SlotInformationStump<AutoPacketFactory, false>;
extern template const std::shared_ptr<AutoPacketFactory>& SharedPointerSlot::as<AutoPacketFactory>(void) const;
9 changes: 8 additions & 1 deletion autowiring/AutowiringEvents.h
@@ -1,5 +1,6 @@
// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved.
#pragma once
#include "EventRegistry.h"
#include TYPE_INDEX_HEADER

struct ObjectTraits;
Expand All @@ -11,10 +12,16 @@ class CoreContext;
/// </summary
class AutowiringEvents {
public:
AutowiringEvents(void);
virtual ~AutowiringEvents(void);

virtual void NewContext(CoreContext&)=0;
virtual void ExpiredContext(CoreContext&)=0;
virtual void NewObject(CoreContext&, const ObjectTraits&)=0;
virtual void EventFired(CoreContext&, const std::type_info&)=0;
};


// Extern explicit template instantiation declarations added to prevent
// exterior instantation of internally used template instances
extern template class RegEvent<AutowiringEvents>;
extern template class TypeUnifierComplex<AutowiringEvents>;
3 changes: 1 addition & 2 deletions autowiring/BasicThread.h
Expand Up @@ -43,8 +43,7 @@ class BasicThread:
public:
/// <param name="pName">An optional name for this thread</param>
BasicThread(const char* pName = nullptr);

virtual ~BasicThread(void) {}
virtual ~BasicThread(void);

protected:
// Internally held thread status block. This has to be a shared pointer because we need to signal
Expand Down
4 changes: 3 additions & 1 deletion autowiring/BoltBase.h
@@ -1,5 +1,6 @@
// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved.
#pragma once
#include TYPE_INDEX_HEADER

class CoreContext;

Expand All @@ -13,7 +14,8 @@ typedef const std::type_info*const* t_TypeInfoVector;
class BoltBase
{
public:
virtual ~BoltBase(void) {}
BoltBase(void);
virtual ~BoltBase(void);

/// <summary>
/// Returns a null-termianted list of one (or more) sigil types that this bolt cares about
Expand Down
8 changes: 4 additions & 4 deletions autowiring/CallExtractor.h
Expand Up @@ -33,7 +33,7 @@ struct CallExtractor<RetType (*)(Args...)>:

// Handoff
((t_pfn)pfn)(
auto_arg<Args>(autoPacket.shared_from_this(), *satisfaction.source<typename auto_arg<Args>::base_type>())...
auto_arg<Args>(autoPacket.shared_from_this(), *satisfaction.source(typeid(typename auto_arg<Args>::base_type)))...
);
}
};
Expand All @@ -60,7 +60,7 @@ struct CallExtractor<void (T::*)(Args...)>:

// Handoff
(((T*) pObj)->*memFn)(
auto_arg<Args>(autoPacket.shared_from_this(), *satisfaction.source<typename auto_arg<Args>::base_type>())...
auto_arg<Args>(autoPacket.shared_from_this(), *satisfaction.source(typeid(typename auto_arg<Args>::base_type)))...
);
}
};
Expand All @@ -82,7 +82,7 @@ struct CallExtractor<void (T::*)(Args...) const> :

// Handoff
(((const T*) pObj)->*memFn)(
auto_arg<Args>(autoPacket.shared_from_this(), *satisfaction.source<typename auto_arg<Args>::base_type>())...
auto_arg<Args>(autoPacket.shared_from_this(), *satisfaction.source(typeid(typename auto_arg<Args>::base_type)))...
);
}
};
Expand Down Expand Up @@ -113,7 +113,7 @@ struct CallExtractor<Deferred (T::*)(Args...)>:
// and will therefore have the same lifecycle as the AutoPacket.
*(T*) pObj += [pObj, pAutoPacket, &satisfaction] {
(((T*) pObj)->*memFn)(
auto_arg<Args>(pAutoPacket, *satisfaction.source<typename auto_arg<Args>::base_type>())...
auto_arg<Args>(pAutoPacket, *satisfaction.source(typeid(typename auto_arg<Args>::base_type)))...
);
};
}
Expand Down
3 changes: 3 additions & 0 deletions autowiring/CoreRunnable.h
Expand Up @@ -6,6 +6,9 @@ class Object;

class CoreRunnable {
public:
CoreRunnable(void);
virtual ~CoreRunnable(void);

/// <summary>
/// Causes this runnable to begin processing
/// </summary>
Expand Down
3 changes: 1 addition & 2 deletions autowiring/CoreThread.h
Expand Up @@ -19,8 +19,7 @@ class CoreThread:
public:
/// <param name="pName">An optional name for this thread</param>
CoreThread(const char* pName = nullptr);

virtual ~CoreThread(void) {}
virtual ~CoreThread(void);

protected:
void DEPRECATED(Ready(void) const, "Do not call this method, the concept of thread readiness is now deprecated") {}
Expand Down
60 changes: 30 additions & 30 deletions autowiring/CreationRules.h
Expand Up @@ -18,9 +18,35 @@ struct is_injectable
/// <summary>
/// Simple structure to centralize knowledge about how to create types with various declarations
/// </summary>
struct CreationRules {
namespace CreationRules {
template<void* (*)(size_t)>
struct alloc_fn {};

template<typename U>
U* Allocate(alloc_fn<&U::operator new>*) {
return (U*) U::operator new(sizeof(U));
}

template<typename U>
U* Allocate(...) {
return (U*) ::operator new(sizeof(U));
}

template<void(*)(void*)>
struct free_fn {};

template<typename U>
void Free(void* ptr, free_fn<&U::operator delete>*) {
U::operator delete(ptr);
}

template<typename U>
void Free(void* ptr, ...) {
::operator delete(ptr);
}

template<typename U, typename... Args>
static typename std::enable_if<has_static_new<U, Args...>::value, U*>::type New(Args&&... args) {
typename std::enable_if<has_static_new<U, Args...>::value, U*>::type New(Args&&... args) {
auto retVal = U::New(std::forward<Args>(args)...);
static_assert(
std::is_convertible<decltype(retVal), U*>::value,
Expand All @@ -30,7 +56,7 @@ struct CreationRules {
}

template<typename U, typename... Args>
static typename std::enable_if<!has_static_new<U, Args...>::value, U*>::type New(Args&&... args) {
typename std::enable_if<!has_static_new<U, Args...>::value, U*>::type New(Args&&... args) {
static_assert(!std::is_abstract<U>::value, "Cannot create a type which is abstract");
static_assert(!has_static_new<U, Args...>::value, "Can't inject member with arguments if it has a static New");

Expand All @@ -54,30 +80,4 @@ struct CreationRules {
throw;
}
}

template<void* (*)(size_t)>
struct alloc_fn {};

template<typename U>
static U* Allocate(alloc_fn<&U::operator new>*) {
return (U*) U::operator new(sizeof(U));
}

template<typename U>
static U* Allocate(...) {
return (U*) ::operator new(sizeof(U));
}

template<void(*)(void*)>
struct free_fn {};

template<typename U>
static void Free(void* ptr, free_fn<&U::operator delete>*) {
U::operator delete(ptr);
}

template<typename U>
static void Free(void* ptr, ...) {
::operator delete(ptr);
}
};
}
7 changes: 3 additions & 4 deletions autowiring/DataFlow.h
Expand Up @@ -32,12 +32,11 @@ namespace autowiring {
public std::unordered_map<std::type_index, const std::type_info*>
{
public:
template<class Arg>
const std::type_info* source() const {
std::unordered_map<std::type_index, const std::type_info*>::const_iterator itr = find(typeid(Arg));
const std::type_info* source(const std::type_index& arg) const {
std::unordered_map<std::type_index, const std::type_info*>::const_iterator itr = find(arg);
if (itr != end())
return itr->second;
return &typeid(void);
}
};
}
}
6 changes: 5 additions & 1 deletion autowiring/DispatchQueue.h
Expand Up @@ -14,7 +14,11 @@ class DispatchQueue;
/// </summary>
class dispatch_aborted_exception:
public std::exception
{};
{
public:
dispatch_aborted_exception(void);
virtual ~dispatch_aborted_exception(void);
};

/// <summary>
/// This is an asynchronous queue of zero-argument functions
Expand Down
4 changes: 1 addition & 3 deletions autowiring/EventRegistry.h
@@ -1,13 +1,11 @@
// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved.
#pragma once
#include "TypeIdentifier.h"
#include "JunctionBox.h"
#include TYPE_TRAITS_HEADER
#include STL_TUPLE_HEADER
#include MEMORY_HEADER

template<class T>
class JunctionBox;

class JunctionBoxBase;

struct EventRegistryEntry {
Expand Down
5 changes: 3 additions & 2 deletions autowiring/ExceptionFilter.h
@@ -1,9 +1,9 @@
// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved.
#pragma once

#include FUNCTIONAL_HEADER

class JunctionBoxBase;
class Object;

/// <summary>
/// Implements an exception filter type, invoked when an unhandled exception is thrown
Expand Down Expand Up @@ -47,7 +47,8 @@ class JunctionBoxBase;
class ExceptionFilter
{
public:
virtual ~ExceptionFilter(void) {}
ExceptionFilter(void);
virtual ~ExceptionFilter(void);

/// <summary>
/// This method is invoked when an exception has been thrown by CoreThread::Run
Expand Down
3 changes: 2 additions & 1 deletion autowiring/Object.h
Expand Up @@ -7,5 +7,6 @@
/// </summary>
class Object {
public:
virtual ~Object(void) {}
Object(void);
virtual ~Object(void);
};
3 changes: 1 addition & 2 deletions autowiring/TypeIdentifier.h
@@ -1,8 +1,7 @@
// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved.
#pragma once
#include TYPE_INDEX_HEADER

class Object;
#include "Object.h"

// Checks if an Object* listens to a event T;
struct TypeIdentifierBase {
Expand Down
12 changes: 10 additions & 2 deletions autowiring/auto_arg.h
Expand Up @@ -207,7 +207,11 @@ class auto_arg<AutoPacket&>
{
protected:
/// Sigil to distinguish AutoPacket&
class first_call_sigil {};
class first_call_sigil {
public:
first_call_sigil(void);
virtual ~first_call_sigil(void);
};

std::shared_ptr<AutoPacket> m_packet;

Expand Down Expand Up @@ -254,7 +258,11 @@ class auto_arg<const AutoPacket&>
{
protected:
/// Sigil to distinguish const AutoPacket&
class final_call_sigil {};
class final_call_sigil {
public:
final_call_sigil(void);
virtual ~final_call_sigil(void);
};

std::shared_ptr<AutoPacket> m_packet;

Expand Down

0 comments on commit 8050d6f

Please sign in to comment.