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); }
int main () { // Initialization of context, injection of context members, obtaining access to the factory. AutoCurrentContext()->Initiate(); AutoRequired<Hippo1> hippo1; AutoRequired<Hippo2> hippo2; AutoRequired<Hippo3> hippo3; AutoRequired<Hippo4> hippo4; AutoRequired<Hippo5> hippo5; AutoRequired<Hippo6> hippo6; Autowired<AutoPacketFactory> factory; // Declare a packet to use in the following code blocks. std::shared_ptr<AutoPacket> packet; /// At this point we will execute the filter network a number of times, each with a different type related to `std::string`, /// in order to observe which filters are executed. The first six executions demonstrate the types that are equivalent to /// `std::string` as input parameters (in which we expect only `Hippo#::AutoFilter` to be called). { packet = factory->NewPacket(); std::cout << "Decorating packet with instance of `std::string`:\n"; std::string s("std::string"); packet->Decorate(s); std::cout << '\n'; } { packet = factory->NewPacket(); std::cout << "Decorating packet with instance of `const std::string`:\n"; const std::string s("const std::string"); packet->Decorate(s); std::cout << '\n'; } { packet = factory->NewPacket(); std::cout << "Decorating packet with instance of `std::shared_ptr<std::string>`:\n"; std::shared_ptr<std::string> s = std::make_shared<std::string>("std::shared_ptr<std::string>"); packet->Decorate(s); std::cout << '\n'; } { packet = factory->NewPacket(); std::cout << "Decorating packet with instance of `const std::shared_ptr<std::string>`:\n"; const std::shared_ptr<std::string> s = std::make_shared<std::string>("const std::shared_ptr<std::string>"); packet->Decorate(s); std::cout << '\n'; } { packet = factory->NewPacket(); std::cout << "Decorating packet with instance of `std::shared_ptr<const std::string>`:\n"; std::shared_ptr<const std::string> s = std::make_shared<const std::string>("std::shared_ptr<const std::string>"); packet->Decorate(s); std::cout << '\n'; } { packet = factory->NewPacket(); std::cout << "Decorating packet with instance of `const std::shared_ptr<const std::string>`:\n"; const std::shared_ptr<const std::string> s = std::make_shared<const std::string>("const std::shared_ptr<const std::string>"); packet->Decorate(s); std::cout << '\n'; } /// Verify that the accumulated values in the `m_received_input_decoration_types` for each context member are what we expect. { std::unordered_set<std::string> expected_hippo_inputs({ "std::string", "const std::string", "std::shared_ptr<std::string>", "const std::shared_ptr<std::string>", "std::shared_ptr<const std::string>", "const std::shared_ptr<const std::string>" }); if (hippo1->m_received_input_decoration_types != expected_hippo_inputs) throw std::runtime_error("Hippo1 did not receive the expected inputs."); if (hippo1->m_received_input_decoration_types != expected_hippo_inputs) throw std::runtime_error("Hippo2 did not receive the expected inputs."); if (hippo1->m_received_input_decoration_types != expected_hippo_inputs) throw std::runtime_error("Hippo3 did not receive the expected inputs."); if (hippo1->m_received_input_decoration_types != expected_hippo_inputs) throw std::runtime_error("Hippo4 did not receive the expected inputs."); if (hippo1->m_received_input_decoration_types != expected_hippo_inputs) throw std::runtime_error("Hippo5 did not receive the expected inputs."); if (hippo1->m_received_input_decoration_types != expected_hippo_inputs) throw std::runtime_error("Hippo6 did not receive the expected inputs."); std::cout << "All Hippo# context members received the expected inputs.\n"; } std::cout << "All verifications passed.\n"; return 0; // Return with no error. }