Skip to content

Commit

Permalink
Fix bad overload logic, add another test
Browse files Browse the repository at this point in the history
  • Loading branch information
codemercenary committed Mar 1, 2016
1 parent f390d0e commit 033795f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/autowiring/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@ namespace autowiring {
explicit config(const T& value) { values[0] = value; }
explicit config(T&& value) { values[0] = std::move(value); }

template<typename U>
explicit config(U&& value) {
values[0] = std::forward<U&&>(value);
}

private:
// Lock, used to move the asyncrhonous value to the value field
autowiring::spin_lock lock;

// Tracks whether the backing value has been updated
bool dirty = false;
bool dirty = true;

// The index of the currently active value
size_t valueIndex = 0;
Expand Down
9 changes: 7 additions & 2 deletions src/autowiring/test/AutoConfigTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ class AutoConfigTest:
namespace {
class MyConfigurableClass {
public:
autowiring::config<std::string> a = "Hello world!";
autowiring::config<std::string> a{ "Hello world!" };
std::atomic<int> b = 929;
std::atomic<unsigned int> bUnsigned = 92999;
volatile bool c = false;
volatile float d = 1.0f;
volatile double e = 99.2;
autowiring::observable<int> obs = 44;
autowiring::config<int> cfg = 929999;
autowiring::config<int> cfg{ 929999 };

static autowiring::config_descriptor GetConfigDescriptor(void) {
return {
Expand All @@ -44,6 +44,11 @@ namespace {
static_assert(autowiring::has_getconfigdescriptor<MyConfigurableClass>::value, "Static new not correctly detected");
static_assert(!autowiring::has_getconfigdescriptor<BadClass>::value, "Bad class cannot have a configuration descriptor");

TEST_F(AutoConfigTest, ConfigFieldAssign) {
autowiring::config<std::string> x{ "Hello world!" };
ASSERT_FALSE(x.is_dirty()) << "Config values are assumed to be initially dirty";
}

TEST_F(AutoConfigTest, String) {
MyConfigurableClass c;

Expand Down

0 comments on commit 033795f

Please sign in to comment.