30 #include <boost/lexical_cast.hpp> 36 int main(
int argc,
char **argv) {
38 std::cerr <<
"Syntax: cpp_introspection_test <filename or path> [<message type>]" << std::endl;
47 std::cout <<
"Introspecting package " <<
package->getName() <<
"..." << std::endl;
50 std::cout << std::endl <<
"Creating an instance of " << message->getName() <<
"..." << std::endl;
51 VoidPtr instance = message->createInstance();
52 MessagePtr introspected = message->introspect(instance.get());
54 std::cout << std::endl <<
"...and expanded ..." << std::endl;
59 std::cout << std::endl <<
"Introspecting " << argv[2] <<
":" << std::endl;
62 std::cout <<
"I am sorry, I don't know that message type." << std::endl;
65 introspected->getFields(fields,
true);
66 introspected->getTypes(types,
true);
67 assert(fields.size() == types.size());
68 for(
size_t i = 0; i < fields.size(); ++i) {
69 std::cout <<
" " << types[i] <<
"\t" << fields[i] << std::endl;
78 if (!message->hasInstance()) {
79 std::cout <<
"No instance!" << std::endl;
85 std::cout << prefix << std::string(field->getDataType()) <<
" " << std::string(field->getName()) <<
" = ";
86 if (field->isContainer()) std::cout <<
"[";
88 if (field->isMessage()) {
89 std::cout << std::endl;
90 for(std::size_t i = 0; i < field->size(); i++) {
93 std::cout << prefix <<
" (unknown)" << std::endl;
100 for(std::size_t i = 0; i < field->size(); i++) {
101 if (i > 0) std::cout <<
", ";
102 std::cout << field->as<std::string>(i);
105 if (field->isContainer()) std::cout <<
"]";
106 std::cout << std::endl;
PackagePtr load(const std::string &package_or_library_or_path)
MessagePtr expand(const MessagePtr &message, const std::string &separator=".", const std::string &prefix="")
const V_Package & packages()
std::vector< std::string > V_string
V_Field::const_iterator const_iterator
void print_introspection(MessagePtr message, const std::string &prefix="")
PackagePtr package(const std::string &pkg)
int main(int argc, char **argv)
V_Message::const_iterator const_iterator
MessagePtr messageByDataType(const std::string &data_type, const std::string &package=std::string())