本文整理汇总了C++中MessagePtr::createInstance方法的典型用法代码示例。如果您正苦于以下问题:C++ MessagePtr::createInstance方法的具体用法?C++ MessagePtr::createInstance怎么用?C++ MessagePtr::createInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessagePtr
的用法示例。
在下文中一共展示了MessagePtr::createInstance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv) {
if (argc < 2) {
std::cerr << "Syntax: cpp_introspection_test <filename or path> [<message type>]" << std::endl;
exit(1);
}
load(argv[1]);
if (packages().empty()) return 1;
if (argc < 3) {
PackagePtr package = packages().back();
std::cout << "Introspecting package " << package->getName() << "..." << std::endl;
for(Package::const_iterator it = package->begin(); it != package->end(); ++it) {
MessagePtr message = *it;
std::cout << std::endl << "Creating an instance of " << message->getName() << "..." << std::endl;
VoidPtr instance = message->createInstance();
MessagePtr introspected = message->introspect(instance.get());
print_introspection(introspected);
std::cout << std::endl << "...and expanded ..." << std::endl;
print_introspection(expand(introspected));
}
} else {
std::cout << std::endl << "Introspecting " << argv[2] << ":" << std::endl;
MessagePtr introspected = messageByDataType(argv[2]);
if (!introspected) {
std::cout << "I am sorry, I don't know that message type." << std::endl;
} else {
V_string fields, types;
introspected->getFields(fields, true);
introspected->getTypes(types, true);
assert(fields.size() == types.size());
for(size_t i = 0; i < fields.size(); ++i) {
std::cout << " " << types[i] << "\t" << fields[i] << std::endl;
}
}
}
exit(0);
}