Skip to content

Commit

Permalink
Merge branch 'develop' into ref-functionaldecoration
Browse files Browse the repository at this point in the history
Conflicts:
	src/autowiring/test/AutoFilterTest.cpp
  • Loading branch information
Gabriel Hare committed Aug 8, 2014
2 parents b7fb1f1 + 83d4d09 commit 25009fd
Show file tree
Hide file tree
Showing 45 changed files with 2,797 additions and 300 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
build/
docs/
CMakeFiles
CMakeCache.txt
*.vcxproj
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -27,7 +27,7 @@ before_script:
script:
- export CPATH=/usr/include/c++/4.8:/usr/include/x86_64-linux-gnu/c++/4.8/:$CPATH
- export LD_LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.8:$LD_LIBRARY_PATH
- make -j 16 || make
- make -j 8 || make
- make test
after_failure:
- cat Testing/Temporary/LastTest.log 2> /dev/null
Expand Down
2,310 changes: 2,310 additions & 0 deletions Doxyfile

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions autowiring/AutoCheckout.h
@@ -1,6 +1,5 @@
// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved.
#pragma once
#include <algorithm>

class AutoPacket;

Expand Down Expand Up @@ -66,4 +65,4 @@ class AutoCheckout {
completion = rhs.completion;
return *this;
}
};
};
1 change: 0 additions & 1 deletion autowiring/AutoFuture.h
Expand Up @@ -46,4 +46,3 @@ class AutoFuture
return true;
}
};

2 changes: 1 addition & 1 deletion autowiring/AutoInjectable.h
Expand Up @@ -23,7 +23,7 @@ class AutoInjectableExpression:
{}

void operator()(AutoFuture* pFuture) const override {
auto added = CallByUnpackingTuple(typename gen_index_tuple<sizeof...(Args)>::type());
auto added = CallByUnpackingTuple(typename make_index_tuple<sizeof...(Args)>::type());
if(pFuture)
*pFuture += added;
}
Expand Down
4 changes: 2 additions & 2 deletions autowiring/AutoNetServer.h
Expand Up @@ -9,7 +9,7 @@
#include <map>
#include <set>

struct EventIdentifierBase;
struct TypeIdentifierBase;

class AutoNetServer:
public CoreThread,
Expand Down Expand Up @@ -153,7 +153,7 @@ class AutoNetServer:
std::map<int, CoreContext*> m_ContextPtrs;

// All event types
std::set<std::shared_ptr<EventIdentifierBase>> m_EventTypes;
std::set<std::shared_ptr<TypeIdentifierBase>> m_EventTypes;

// All ContextMembers
std::map<std::string, std::function<void(void)>> m_AllTypes;
Expand Down
39 changes: 31 additions & 8 deletions autowiring/AutoSelfUpdate.h
@@ -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 "NewAutoFilter.h"
#include "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;
};
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
4 changes: 4 additions & 0 deletions autowiring/AutowiringEvents.h
Expand Up @@ -5,6 +5,10 @@
struct AnySharedPointer;
class CoreContext;

/// <summary>
/// These events are broadcast internally by Autowiring
/// for visualizing internal behavior.
/// </summary
class AutowiringEvents {
public:
virtual void NewContext(CoreContext&)=0;
Expand Down
1 change: 0 additions & 1 deletion autowiring/BasicThreadStateBlock.h
Expand Up @@ -16,4 +16,3 @@ struct BasicThreadStateBlock:
// The current thread, if running
std::thread m_thisThread;
};

2 changes: 1 addition & 1 deletion autowiring/Bolt.h
@@ -1,6 +1,6 @@
// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved.
#pragma once
#include "Decompose.h"
#include "is_any.h"
#include "BoltBase.h"

/// <summary>
Expand Down
23 changes: 20 additions & 3 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 @@ -211,7 +212,7 @@ class CoreContext:
template<typename T, typename... Sigils>
void EnableInternal(T*, Boltable<Sigils...>*) {
bool dummy[] = {
false,
false, // Ensure non-zero array size
(AutoRequireMicroBolt<T, Sigils>(), false)...
};
(void) dummy;
Expand Down Expand Up @@ -315,7 +316,7 @@ class CoreContext:
pBoltBase(autowiring::fast_pointer_cast<BoltBase>(value)),
receivesEvents([this]{
for (auto evt = g_pFirstEventEntry; evt; evt = evt->pFlink) {
auto identifier = evt->NewEventIdentifier();
auto identifier = evt->NewTypeIdentifier();
if (identifier->IsSameAs(pObject.get()))
return true;
}
Expand Down Expand Up @@ -517,10 +518,15 @@ class CoreContext:

/// <summary>
/// Utility method which will inject the specified types into this context
/// Arguments will be passed to the T constructor if provided
/// </summary>
/// <remarks>
/// Arguments will be passed to the T constructor if provided
/// </remarks>
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 +940,16 @@ class CoreContext:
}
};

/// <summary>
/// Forward-declarable version of CoreContext::InjectCurrent
/// </summary>
namespace autowiring {
template<typename T>
void InjectCurrent(void){
CoreContext::InjectCurrent<T>();
}
}

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

1 change: 0 additions & 1 deletion autowiring/CreationRules.h
Expand Up @@ -33,7 +33,6 @@ struct CreationRules {
static 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");
static_assert(!sizeof...(Args) || !has_simple_constructor<U>::value, "Can't inject member with arguments if it has a default constructor");

// Allocate slot first before registration
auto* pSpace = Allocate<U>(nullptr);
Expand Down
19 changes: 0 additions & 19 deletions autowiring/Decompose.h
Expand Up @@ -3,25 +3,6 @@
#include TYPE_TRAITS_HEADER
#include <typeinfo>

/// <summary>
/// Extended version of is_same
/// </summary>
/// <remarks>
/// Inherits from true_type if T is the same as any of Us...
/// </remarks>
template<typename T, typename... Us>
struct is_any_same;

template<typename T>
struct is_any_same<T> {
static const bool value = false;
};

template<typename T, typename U, typename... Us>
struct is_any_same<T, U, Us...> {
static const bool value = std::is_same<T, U>::value || is_any_same<T, Us...>::value;
};

/// <summary>
/// Provides some static reflection support for member function pointers
/// </summary>
Expand Down
49 changes: 2 additions & 47 deletions autowiring/Deserialize.h
Expand Up @@ -5,7 +5,7 @@
/// <summary>
/// Support class for deserializing byte-streams input as std::string into a variety of formats
/// </summary>
namespace Auto {
namespace autowiring {
struct SerializableSigil{};

struct Serialize:
Expand Down Expand Up @@ -40,49 +40,4 @@ namespace Auto {
return t;
}
};


/// <summary>
/// Utility type which enables the composition of a sequence [0, sizeof...(Ts))
/// </summary>
template<unsigned ...Indicies>
struct index_tuple {

/// Generate an index_tuple with an additional element.
template<unsigned N>
struct append {
typedef index_tuple<Indicies..., N> type;
};
};

template<typename ...Members>
struct make_index_tuple; //So linux doesn't bitch

/// Unary metafunction that generates an index_tuple containing [0, Size)
template<typename Head, typename ...Tail>
struct make_index_tuple<Head, Tail...>{
typedef typename make_index_tuple<Tail...>::type::template append<sizeof...(Tail)>::type type;
};

// Terminal case of the recursive metafunction.
template<>
struct make_index_tuple<>{
typedef index_tuple<> type;
};

static_assert(
std::is_same<
make_index_tuple<>::type,
index_tuple<>
>::value,
"Index tuple base case was not correctly specialized"
);

static_assert(
std::is_same<
make_index_tuple<int, int, int>::type,
index_tuple<0, 1, 2>
>::value,
"Index tuple conversion function did not properly index a sample type"
);
}
}
9 changes: 5 additions & 4 deletions autowiring/EventInputStream.h
Expand Up @@ -2,6 +2,7 @@
#pragma once
#include "Decompose.h"
#include "Deserialize.h"
#include "index_tuple.h"
#include <string>
#include <sstream>
#include <deque>
Expand Down Expand Up @@ -39,14 +40,14 @@ struct Expression<R(W::*)(ToBindArgs...) >: public ExpressionBase
/// parameter pack expansion.
/// </summary>
void DeserializeAndForward(std::deque<std::string> & d){
DeserializeAndForward(d, typename Auto::make_index_tuple<ToBindArgs...>::type());
DeserializeAndForward(d, typename make_index_tuple<sizeof...(ToBindArgs)>::type());
}

template<unsigned... I>
void DeserializeAndForward(std::deque<std::string> & d, Auto::index_tuple<I...>){
template<int... I>
void DeserializeAndForward(std::deque<std::string> & d, index_tuple<I...>){
auto it = d.begin();
AutoFired<W> sender;
sender(m_memfunc)(Auto::deser<ToBindArgs>::deserialize(it[I])...);
sender(m_memfunc)(autowiring::deser<ToBindArgs>::deserialize(it[I])...);
}
};

Expand Down
7 changes: 5 additions & 2 deletions autowiring/EventOutputStream.h
Expand Up @@ -71,14 +71,17 @@ class EventOutputStreamBase {

template <class Arg>
//stub out such that if ARGUMENT defines a static method called AutoSerialize which returns an std::string,
typename std::enable_if<std::is_base_of<Auto::Serialize, Arg>::value, void >::type
typename std::enable_if<std::is_base_of<autowiring::Serialize, Arg>::value, void >::type
SerializeMethod(Arg & arg){
m_OutputStream << "\xD8" << arg.AutoSerialize();
}

template <class Arg1>
//SFINAE STUB OUT: replace with check_if overloads <<
typename std::enable_if<!std::is_same<Arg1, std::basic_string<char> const *>::value && !std::is_base_of<Auto::Serialize, Arg1>::value, void >::type
typename std::enable_if<
!std::is_same<Arg1, std::basic_string<char> const *>::value &&
!std::is_base_of<autowiring::Serialize, Arg1>::value,
void>::type
SerializeMethod(Arg1 & arg1){
assert(false);
//static_assert(false, "Fundamental belief about serialized argument types violated");
Expand Down

0 comments on commit 25009fd

Please sign in to comment.