Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
codemercenary committed Jul 31, 2015
2 parents 0e1fb97 + a327059 commit 3986129
Show file tree
Hide file tree
Showing 94 changed files with 2,355 additions and 1,092 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Expand Up @@ -10,6 +10,10 @@ if(APPLE)
set(CMAKE_OSX_ARCHITECTURES "x86_64;i386" CACHE STRING "Mac OS X build architectures" FORCE)
endif()

if(NOT (MSVC OR CMAKE_BUILD_TYPE))
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release." FORCE)
endif()

# Need to classify the architecture before we run anything else
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm")
set(autowiring_BUILD_ARM ON)
Expand Down
2 changes: 1 addition & 1 deletion Doxyfile
Expand Up @@ -32,7 +32,7 @@ PROJECT_NAME = Autowiring
# This could be handy for archiving the generated documentation or
# if some version control system is used.

PROJECT_NUMBER = "0.7.1"
PROJECT_NUMBER = "0.7.2"

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer
Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -78,3 +78,5 @@ to find Autowiring once the package is installed by this means.

Generally speaking, there is not really much reason to build an installer yourself unless you're testing out the bleeding edge. The
[releases page](https://github.com/leapmotion/autowiring/releases) lists the officially supported Autowiring releases.

[![ZenHub Badge](https://raw.githubusercontent.com/ZenHubIO/support/master/zenhub-badge.png)](https://zenhub.io)
143 changes: 87 additions & 56 deletions autowiring/AnySharedPointer.h
@@ -1,110 +1,141 @@
// Copyright (C) 2012-2015 Leap Motion, Inc. All rights reserved.
#pragma once
#include "SharedPointerSlot.h"

/// \file SharedPointerSlot.h
/// \internal
#include "auto_id.h"
#include "fast_pointer_cast.h"

/// AnySharedPointer
struct AnySharedPointer {
public:
AnySharedPointer(void);
AnySharedPointer(void) = default;
AnySharedPointer(AnySharedPointer&& rhs);
AnySharedPointer(const AnySharedPointer& rhs);
AnySharedPointer(const SharedPointerSlot&& rhs);
AnySharedPointer(const SharedPointerSlot& rhs);
AnySharedPointer(const AnySharedPointer& rhs) = default;

template<class T>
AnySharedPointer(const std::shared_ptr<T>& rhs) {
// Delegate the remainder to the assign operation:
new (m_space) SharedPointerSlotT<T>(rhs);
}
AnySharedPointer(const std::shared_ptr<T>& rhs) :
m_ti(auto_id_t<T>{}),
m_ptr(rhs)
{}

~AnySharedPointer(void);

protected:
unsigned char m_space[sizeof(SharedPointerSlot)];
auto_id m_ti;
std::shared_ptr<void> m_ptr;

public:
// Convenience method to cast the space to a slot
SharedPointerSlot* slot(void) { return (SharedPointerSlot*) m_space; }
const SharedPointerSlot* slot(void) const { return (const SharedPointerSlot*) m_space; }
explicit operator bool(void) const { return (bool)m_ptr; }
void* ptr(void) const { return m_ptr.get(); }
bool empty(void) const { return !m_ptr; }
auto_id type(void) const { return m_ti; }

explicit operator bool(void) const { return slot()->operator bool(); }
std::shared_ptr<void>& operator*(void) { return m_ptr; }
const std::shared_ptr<void>& operator*(void) const { return m_ptr; }

SharedPointerSlot& operator*(void) { return *slot(); }
const SharedPointerSlot& operator*(void) const { return *slot(); }
void reset(void) {
m_ptr.reset();
}

SharedPointerSlot* operator->(void) { return slot(); }
const SharedPointerSlot* operator->(void) const { return slot(); }
std::shared_ptr<CoreObject> as_obj(void) const {
return
m_ti.block->pToObj ?
m_ti.block->pToObj(m_ptr) :
nullptr;
}

/// <summary>
/// Attempts to dynamically assign this slot to the specified object without changing the current type
/// </summary>
/// <returns>True if the assignment succeeds</returns>
bool try_assign(const std::shared_ptr<CoreObject>& rhs) {
if (!m_ti.block->pFromObj)
return nullptr;
auto ptr = m_ti.block->pFromObj(rhs);
if (!ptr)
return false;
m_ptr = std::move(ptr);
return true;
}

/// <summary>
/// Attempts to dynamically assign this slot to the specified object without changing the current type
/// </summary>
/// <returns>True if the assignment succeeds</returns>
bool try_assign(const AnySharedPointer& rhs) {
auto obj = rhs.as_obj();
return obj && try_assign(obj);
}

template<class T>
SharedPointerSlotT<T>& as(void) const { return (SharedPointerSlotT<T>&)*slot(); }
const std::shared_ptr<T>& as(void) const {
// The safety of this routine is verified by the AnySharedPointer unit tests
return *reinterpret_cast<const std::shared_ptr<T>*>(&m_ptr);
}

bool operator==(const AnySharedPointer& rhs) const {
return *slot() == *rhs.slot();
// Need to compare the control blocks, not the pointer values, because we could be pointing to
// different spots in the same object.
return
!m_ptr.owner_before(rhs.m_ptr) &&
!rhs.m_ptr.owner_before(m_ptr);
}

template<class T>
template<typename T>
bool operator==(const std::shared_ptr<T>& rhs) const {
return *slot() == rhs;
return m_ptr == rhs;
}

// Additional operator overloads:
bool operator<(const AnySharedPointer& rhs) const { return *slot() < *rhs.slot();}
bool operator!=(const AnySharedPointer& rhs) const { return !(*this == rhs); }
bool operator!=(std::nullptr_t) const {
return !!m_ptr;
}

/// <summary>
/// Copy assignment operator
/// </summary>
/// <remarks>
/// Consumer beware: This is a transformative assignment. The true polymorphic
/// type will be carried from the right-hand side into this element, which is a
/// different behavior from how things are normally done during assignment. Other
/// than that, however, the behavior is very similar to boost::any's assignment
/// implementation.
/// </remarks>
SharedPointerSlot& operator=(const AnySharedPointer& rhs) {
return **this = *rhs;
template<typename T>
void init(void) {
m_ti = auto_id_t<T>{};
m_ptr.reset();
}

/// <summary>
/// Convenience overload for slot assignment
/// </summary>
SharedPointerSlot& operator=(const SharedPointerSlot& rhs) {
return *slot() = rhs;
// Additional operator overloads:
bool operator<(const AnySharedPointer& rhs) const { return m_ptr < rhs.m_ptr;}
bool operator!=(const AnySharedPointer& rhs) const { return !(*this == rhs); }

void operator=(const AnySharedPointer& rhs) {
m_ti = rhs.m_ti;
m_ptr = rhs.m_ptr;
}

/// <summary>
/// Convenience overload for shared pointer assignment
/// </summary>
template<class T>
void operator=(const std::shared_ptr<T>& rhs) {
**this = rhs;
m_ptr = rhs;
}
};

/// <summary>
/// Convenience implementation of AnySharedPointer which is initially of type T
/// </summary>
/// <remarks>
/// Using this type will automatically ensure that the underlying auto_id is fully instantiated
/// </remarks>
template<class T>
class AnySharedPointerT:
public AnySharedPointer
{
public:
AnySharedPointerT(void) {
new (m_space) SharedPointerSlotT<T>();
}
AnySharedPointerT(void):
AnySharedPointer(std::shared_ptr<T>{})
{}

// Convenience method to cast the space to a slot, but with the expected type
SharedPointerSlotT<T>* slot(void) { return (SharedPointerSlotT<T>*) m_space; }
const SharedPointerSlotT<T>* slot(void) const { return (const SharedPointerSlotT<T>*) m_space; }
T& operator*(void) { return *as<T>(); }
const T& operator*(void) const { return *as<T>(); }

T& operator*(void) { return *slot()->get(); }
const T& operator*(void) const { return **slot(); }
T* operator->(void) { return as<T>()->get(); }
const T* operator->(void) const { return as<T>()->get(); }

T* operator->(void) { return slot()->get().get(); }
const T* operator->(void) const { return slot()->get().get(); }
const std::shared_ptr<T>& get(void) const {
return AnySharedPointer::as<T>();
}
};

template<class T>
Expand Down
14 changes: 8 additions & 6 deletions autowiring/AutoFilterArgument.h
Expand Up @@ -9,31 +9,33 @@
struct AutoFilterArgument {
AutoFilterArgument(void) = default;

protected:
AutoFilterArgument(
bool is_input,
bool is_output,
bool is_shared,
bool is_multi,
const std::type_info* ti,
auto_id id,
int tshift
) :
is_input(is_input),
is_output(is_output),
is_shared(is_shared),
is_multi(is_multi),
ti(ti),
id(id),
tshift(tshift)
{}

public:
const bool is_input = false;
const bool is_output = false;
const bool is_shared = false;
const bool is_multi = false;
const std::type_info* const ti = nullptr;
const auto_id id = auto_id_t<void>{};
const int tshift = 0;

operator bool(void) const {
return !!ti;
explicit operator bool(void) const {
return static_cast<bool>(id);
}
};

Expand All @@ -47,7 +49,7 @@ struct AutoFilterArgumentT:
auto_arg<T>::is_output,
auto_arg<T>::is_shared,
auto_arg<T>::is_multi,
&typeid(typename auto_arg<T>::id_type),
typename auto_arg<T>::id_type(),
auto_arg<T>::tshift
)
{}
Expand Down

0 comments on commit 3986129

Please sign in to comment.