-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,4 @@ lib/*.* | |
autowiring-*-*.zip | ||
_CPack_Packages | ||
win64/Autowiring.nuspec | ||
Autowiring.nuspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}; |
Oops, something went wrong.