本文整理汇总了C++中Autowired::NewPacket方法的典型用法代码示例。如果您正苦于以下问题:C++ Autowired::NewPacket方法的具体用法?C++ Autowired::NewPacket怎么用?C++ Autowired::NewPacket使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Autowired
的用法示例。
在下文中一共展示了Autowired::NewPacket方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
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);
}
示例2: main
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.
}