Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
codemercenary committed Dec 17, 2014
2 parents b079fdf + abcfd25 commit ed7719b
Show file tree
Hide file tree
Showing 3,028 changed files with 530,767 additions and 3,426 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -38,3 +38,4 @@ lib/*.*
autowiring-*-*.zip
_CPack_Packages
win64/Autowiring.nuspec
Autowiring.nuspec
4 changes: 3 additions & 1 deletion CMakeLists.txt
Expand Up @@ -97,7 +97,9 @@ if(NOT WIN32 AND autowiring_BUILD_64)
endif()

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
include(CMakeModules/pch.cmake)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules")
include(AddPCH)
include(ConditionalSources)

if(autowiring_BUILD_ARM)
# Currently cannot build Autonet for ARM, so default this off on that platform
Expand Down
27 changes: 0 additions & 27 deletions CMakeModules/pch.cmake

This file was deleted.

13 changes: 10 additions & 3 deletions autowiring/AnySharedPointer.h
Expand Up @@ -72,12 +72,19 @@ struct AnySharedPointer {
return **this = *rhs;
}

/// <summary>
/// Convenience overload for slot assignment
/// </summary>
SharedPointerSlot& operator=(const SharedPointerSlot& rhs) {
return *slot() = rhs;
}

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

Expand All @@ -97,7 +104,7 @@ class AnySharedPointerT:
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 **slot(); }
T& operator*(void) { return *slot()->get(); }
const T& operator*(void) const { return **slot(); }

T* operator->(void) { return slot()->get().get(); }
Expand Down
12 changes: 4 additions & 8 deletions autowiring/AutoCheckout.h
@@ -1,5 +1,6 @@
// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved.
#pragma once
#include "auto_id.h"
#include <typeinfo>
#include MEMORY_HEADER

Expand All @@ -8,29 +9,26 @@ class AutoPacket;
template<class T>
class AutoCheckout {
public:
typedef void (AutoPacket::*t_completion)(bool, const std::type_info&, const std::type_info&);
typedef void (AutoPacket::*t_completion)(bool, const std::type_info&);

AutoCheckout(void) :
m_parent(nullptr),
m_val(nullptr),
m_ready(false),
m_source(&typeid(void)),
completion(nullptr)
{}

AutoCheckout(AutoPacket& parent, const std::shared_ptr<T>& val, t_completion completion, const std::type_info& source = typeid(void)) :
AutoCheckout(AutoPacket& parent, const std::shared_ptr<T>& val, t_completion completion) :
m_parent(&parent),
m_val(val),
m_ready(false),
m_source(&source),
completion(completion)
{}

AutoCheckout(AutoCheckout&& rhs) :
m_parent(rhs.m_parent),
m_val(rhs.m_val),
m_ready(rhs.m_ready),
m_source(rhs.m_source),
completion(rhs.completion)
{
rhs.m_parent = nullptr;
Expand All @@ -40,7 +38,7 @@ class AutoCheckout {

~AutoCheckout(void) {
if(m_val)
(m_parent->*completion)(m_ready, typeid(T), *m_source);
(m_parent->*completion)(m_ready, typeid(auto_id<T>));
}

private:
Expand All @@ -50,7 +48,6 @@ class AutoCheckout {
AutoPacket* m_parent;
std::shared_ptr<T> m_val;
mutable bool m_ready;
const std::type_info* m_source;
t_completion completion;

public:
Expand All @@ -73,7 +70,6 @@ class AutoCheckout {
m_parent = rhs.m_parent;
m_val = rhs.m_val;
m_ready = rhs.m_ready;
m_source = rhs.m_source;
completion = rhs.completion;

rhs.m_parent = nullptr;
Expand Down
76 changes: 76 additions & 0 deletions autowiring/AutoConfig.h
@@ -0,0 +1,76 @@
// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved.
#pragma once
#include "Autowired.h"
#include "AutoConfigManager.h"
#include "ConfigRegistry.h"

#include <string>
#include TYPE_INDEX_HEADER

struct AnySharedPointer;

/// <summary>
/// Utility base type for configuration members
/// </summary>
class AutoConfigBase
{
public:
AutoConfigBase(const std::type_info& tiName);

// Key used to identify this config value
const std::string m_key;
};

/// <summary>
/// Register an attribute with the AutoConfig system. For example
///
/// AutoConfig<int, struct MyNamespace, struct MyKey> m_myVal;
/// defines the key "MyNamespace.MyKey"
///
/// The Namespace field is optional, so
/// AutoConfig<int, struct MyKey> m_myVal;
/// defines the key "MyKey"
///
/// AutoConfig values can be set from the AutoConfigManager. The string key
/// is used as the identifier for the value
/// </summary>
template<class T, class... TKey>
class AutoConfig:
public AutoConfigBase
{
public:
static_assert(sizeof...(TKey)==1 || sizeof...(TKey)==2, "Must provide a key and optional namespace");

AutoConfig(void) :
AutoConfigBase(typeid(ConfigTypeExtractor<TKey...>))
{
// Register with config registry
(void)RegConfig<T, TKey...>::r;
}

protected:
AutoRequired<AutoConfigManager> m_manager;

public:
const T& operator*() const {
return *m_manager->Get(m_key).template as<T>().get();
}

const T* operator->(void) const {
return m_manager->Get(m_key)->template as<T>().get();
}

/// <returns>
/// True if this configurable field has been satisfied with a value
/// </returns>
bool IsConfigured(void) const {
return m_manager->IsConfigured(m_key);
}

// Add a callback for when this config value changes
void operator+=(std::function<void(const T&)>&& fx) {
m_manager->AddCallback(m_key, [fx](const AnySharedPointer& val){
fx(*val.template as<T>().get());
});
}
};
119 changes: 119 additions & 0 deletions autowiring/AutoConfigManager.h
@@ -0,0 +1,119 @@
// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved.
#pragma once
#include "autowiring_error.h"
#include "ConfigRegistry.h"
#include <string>
#include <sstream>
#include <vector>
#include STL_UNORDERED_MAP
#include STL_UNORDERED_SET
#include MEMORY_HEADER

struct AnySharedPointer;

class AutoConfigManager:
public ContextMember
{
public:
AutoConfigManager();
virtual ~AutoConfigManager();

// Callback function type
typedef std::function<void(const AnySharedPointer&)> t_callback;

// Validator function type
typedef std::function<bool(const AnySharedPointer&)> t_validator;

private:
// local map of the config registry
static const std::unordered_map<std::string, const ConfigRegistryEntry*> s_registry;

// map of validators registered for a key
static const std::unordered_map<std::string, std::vector<t_validator>> s_validators;

// lock for all members
std::mutex m_lock;

// Values of AutoConfigs in this context
std::unordered_map<std::string, AnySharedPointer> m_values;

// Set of keys for values set from this context
std::unordered_set<std::string> m_setHere;

// map of callbacks registered for a key
std::unordered_map<std::string, std::vector<t_callback>> m_callbacks;

public:
/// <summary>
/// Check if this key has been set
/// </summary>
bool IsConfigured(const std::string& key);

/// <summary>
/// Check if this key was inherited from an ancestor context
/// </summary>
bool IsInherited(const std::string& key);

/// <summary>
/// Get a reference to where the config value is stored
/// </summary>
/// <remarks>
/// This method will throw an exception if the specified name cannot be found as a configurable value
/// in the application, or if the specified value type does not match the type expected by this field
/// </remarks>
AnySharedPointer& Get(const std::string& key);

/// <summary>
/// Assigns the specified value to an AnySharedPointer slot
/// </summary>
/// <remarks>
/// This method will throw an exception if the specified name cannot be found as a configurable value
/// in the application, or if the specified value type does not match the type expected by this field
/// </remarks>
template<class T>
void Set(const std::string& key, const T& value) {

if (!s_registry.count(key)) {
std::stringstream ss;
ss << "No configuration found for key '" << key << "'";
throw autowiring_error(ss.str());
}

if (!s_registry.find(key)->second->verifyType(typeid(T))) {
std::stringstream ss;
ss << "Attempting to set config '" << key << "' with incorrect type '"
<< autowiring::demangle(typeid(T)) << "'";
throw autowiring_error(ss.str());
}

// Set value in this AutoConfigManager
SetRecursive(key, AnySharedPointer(std::make_shared<T>(value)));
}

/// <summary>
/// Overload for c-style string. Converts to std::string
/// </summary>
void Set(const std::string& key, const char* value);

/// <summary>
/// Coerces the string representation of the specified field to the correct value type
/// </summary>
/// <remarks>
/// This method will throw an exception if there is no string converter available on this type
/// </remarks>
/// <returns>
/// True if value successfully set, False if key not found.
/// </return>
bool SetParsed(const std::string& key, const std::string& value);

// Add a callback for when key is changed in this context
void AddCallback(const std::string& key, t_callback&& fx);

private:
// Handles setting a value recursivly to all child contexts
void SetRecursive(const std::string& key, AnySharedPointer value);

// Set a value in this manager, call callbacks
// Must hold m_lock when calling this
void SetInternal(const std::string& key, const AnySharedPointer& value);
};

0 comments on commit ed7719b

Please sign in to comment.