Skip to content

Commit

Permalink
Merge pull request #386 from leapmotion/murder-autodesired
Browse files Browse the repository at this point in the history
Remove AutoDesired
  • Loading branch information
codemercenary committed Feb 2, 2015
2 parents 31e20c0 + 1aca8be commit 60d528f
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 64 deletions.
34 changes: 0 additions & 34 deletions autowiring/Autowired.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,40 +350,6 @@ class AutoEnable
}
};

/// <summary>
/// Attempts to create and inject a dependency, discarding any exceptions.
/// </summary>
/// <remarks>
/// Like AutoRequired, AutoDesired attempts to create an instance of the type
/// to be autowired. However, if creation of the dependency fails, the slot is
/// created and the dependency is satisfied when an instance of the correct type
/// is created and wired later.
///
/// \include snippets/Autowired_AutoDesired.txt
///
/// Use AutoDesired instead of AutoRequired or Autowired when creation of the dependency may fail,
/// while, unlike Autowired, still creating the dependency when possible.
///
/// AutoDesired is functionally equivalent to the following:
///
/// \include snippets/Autowired_AutoDesired_Alternate.txt
///
/// If you want to know whether an exception was thrown, replace uses of AutoDesired with the above
/// and perform your own exception handling.
/// </remarks>
template<class T>
class AutoDesired:
public Autowired<T>
{
public:
AutoDesired(void) {
try { AutoRequired<T>(); }
catch(...) {
CoreContext::CurrentContext()->FilterException();
}
}
};

/// <summary>
/// A version of AutoRequired that forwards constructor arguments to the injected
/// type's constructor function.
Expand Down
2 changes: 1 addition & 1 deletion autowiring/CoreContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class AutoSearchLambdaDefault:
/// * Thread ownership (BasicThread, CoreThread)
/// * AutoPacket filter graph scope
///
/// Dependencies can be injected into a context using AutoRequired (or its cousins Autowired and AutoDesired).
/// Dependencies can be injected into a context using AutoRequired (or its cousin Autowired).
/// The system looks in the current context for an existing object of the required type to satisfy the dependency.
/// If one does not exist, it looks in parent contexts. Finally, if no existing object is found after searching up the
/// context tree, a new instance of the required type is created. When another object of the same type is added to the
Expand Down
2 changes: 1 addition & 1 deletion src/autowiring/AutoPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void AutoPacket::PulseSatisfaction(DecorationDisposition* pTypeSubs[], size_t nI
{
std::lock_guard<std::mutex> lk(m_lock);
for(size_t i = nInfos; i--;)
for(const auto& cur : pTypeSubs[i]->m_subscribers)
for(SatCounter* cur : pTypeSubs[i]->m_subscribers)
cur->Increment();
}
}
Expand Down
28 changes: 0 additions & 28 deletions src/autowiring/test/AutowiringTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,34 +80,6 @@ TEST_F(AutowiringTest, PathologicalAutowiringRace) {
AutoRequired<SimpleObject>();
}

class ChecksForExceptions:
public ExceptionFilter
{
public:
ChecksForExceptions(void):
m_called(false)
{}

bool m_called;

void Filter(void) override {
m_called = true;
}
};

class ThrowsExceptionInCtor {
public:
ThrowsExceptionInCtor(void) {
throw std::exception();
}
};

TEST_F(AutowiringTest, AUTOTHROW_CanSeeThrownAutoDesiredExceptions) {
AutoRequired<ChecksForExceptions> cfe;
AutoDesired<ThrowsExceptionInCtor>();
ASSERT_TRUE(cfe->m_called) << "Exception was not caught by exception filter in Autowiring context";
}

class PublicBase {
public:
PublicBase(void) {}
Expand Down

0 comments on commit 60d528f

Please sign in to comment.