Skip to content

Commit

Permalink
Combined 2 definitions of index_tuple and put it in its own header
Browse files Browse the repository at this point in the history
  • Loading branch information
gtremper committed Aug 6, 2014
1 parent 1f5f622 commit a8519a5
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 72 deletions.
3 changes: 1 addition & 2 deletions autowiring/AutoCheckout.h
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,3 @@ class AutoFuture
return true;
}
};

2 changes: 1 addition & 1 deletion autowiring/AutoInjectable.h
Original file line number Diff line number Diff line change
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: 4 additions & 0 deletions autowiring/AutowiringEvents.h
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ struct BasicThreadStateBlock:
// The current thread, if running
std::thread m_thisThread;
};

47 changes: 1 addition & 46 deletions autowiring/Deserialize.h
Original file line number Diff line number Diff line change
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"
);
}
}
7 changes: 4 additions & 3 deletions autowiring/EventInputStream.h
Original file line number Diff line number Diff line change
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,11 +40,11 @@ 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])...);
Expand Down
15 changes: 2 additions & 13 deletions autowiring/InvokeRelay.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved.
#pragma once
#include "is_any.h"
#include "index_tuple.h"
#include "JunctionBox.h"

class Deferred;

template<typename T>
class JunctionBox;

// Generate and index tuple
template<int ...>
struct index_tuple {};

template<int N, int... S>
struct gen_index_tuple: gen_index_tuple<N - 1, N - 1, S...> {};

template<int... S>
struct gen_index_tuple<0, S...> {
typedef index_tuple<S...> type;
};

/// <summary>
/// A fully bound member function call
/// </summary>
Expand Down Expand Up @@ -55,7 +44,7 @@ class CurriedInvokeRelay:

public:
void operator()(void) override {
CallByUnpackingTuple(typename gen_index_tuple<sizeof...(Args)>::type());
CallByUnpackingTuple(typename make_index_tuple<sizeof...(Args)>::type());
}
};

Expand Down
2 changes: 1 addition & 1 deletion autowiring/SharedPointerSlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,4 +372,4 @@ struct SharedPointerSlotT:
T& operator*(void) const {
return *get();
}
};
};
Empty file added autowiring/TypeIdentifier.h
Empty file.
3 changes: 1 addition & 2 deletions autowiring/TypeUnifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ template<class T>
class TypeUnifierSimple:
public T,
public TypeUnifier
{
};
{};

/// <summary>
/// Utility class which allows us to either use the pure type T, or a unifier, as appropriate
Expand Down
23 changes: 23 additions & 0 deletions autowiring/index_tuple.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved.
#pragma once

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

template<unsigned int N, unsigned int... S>
struct make_index_tuple: make_index_tuple<N - 1, N - 1, S...> {};

template<unsigned int... S>
struct make_index_tuple<0, S...> {
typedef index_tuple<S...> type;
};

static_assert(
std::is_same<
make_index_tuple<3>::type,
index_tuple<0,1,2>
>::value,
"Index tuple base case was not correctly specialized"
);
3 changes: 1 addition & 2 deletions src/autowiring/AutowirableSlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ using namespace std;
DeferrableAutowiring::DeferrableAutowiring(const std::shared_ptr<CoreContext>& context) :
m_context(context),
m_pFlink(nullptr)
{
}
{}

DeferrableAutowiring::~DeferrableAutowiring(void) {
// Clients MUST call CancelAutowiring from their destructor--if this line is being hit,
Expand Down
2 changes: 2 additions & 0 deletions src/autowiring/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ set(Autowiring_SRCS
has_autofilter.h
has_simple_constructor.h
has_static_new.h
index_tuple.h
is_any.h
is_shared_ptr.h
InterlockedExchange.h
Expand All @@ -98,6 +99,7 @@ set(Autowiring_SRCS
ThreadStatusBlock.h
ThreadStatusBlock.cpp
thread_specific_ptr.h
TypeIdentifier.h
TypeRegistry.h
TypeRegistry.cpp
TypeUnifier.h
Expand Down

0 comments on commit a8519a5

Please sign in to comment.