Skip to content

Commit

Permalink
Finished basic AutoFilter example
Browse files Browse the repository at this point in the history
  • Loading branch information
gtremper committed Aug 5, 2014
1 parent b5ab0ce commit 2a47179
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions examples/AutoFilterExample.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (C) 2012-2014 Leap Motion, Inc. All rights reserved.
#include <autowiring/Autowired.h>
#include <iostream>
#include <string>

//
// AutoFilter
Expand All @@ -11,8 +12,40 @@
// a ContextMember that implements the AutoFilter(...) member function.
//

class IntDoubler
class StringFilter {
public:
void AutoFilter(std::string msg) {
std::cout << "Filter Update: " << msg << std::endl;
}
};

class StringIntFilter {
public:
void AutoFilter(std::string msg, int num) {
std::cout << "Other Filter Update: " << msg << " : " << num << std::endl;
}
};

int main() {
// Initiate the current context
AutoCurrentContext()->Initiate();

// Inject our AutoFilter enabled context members into the context
AutoRequired<StringFilter>();
AutoRequired<StringIntFilter>();

// Each context automatically includes an AutoPacketFactory type. This
// can be used to create new packets in the AutoFilter network
Autowired<AutoPacketFactory> factory;

// When decorating a packet, all AutoFilters that have that type as an argument
// will be called. It is only called when all argument types have been decorated
auto packet = factory->NewPacket();

packet->Decorate(std::string("Hello World"));

std::cout << "StringIntFilter not called yet" << std::endl;

}
// StringIntFilter will now be called since all AutoFilter arguments have ben decorated
packet->Decorate(42);
}

0 comments on commit 2a47179

Please sign in to comment.