本文整理汇总了C++中ObjectFactory::create方法的典型用法代码示例。如果您正苦于以下问题:C++ ObjectFactory::create方法的具体用法?C++ ObjectFactory::create怎么用?C++ ObjectFactory::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectFactory
的用法示例。
在下文中一共展示了ObjectFactory::create方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv) {
try {
std::map<std::string, std::string> engines;
ObjectFactory<std::string, Engine> engineFactory;
ENGINE("groovie", "Groovie", Groovie::GroovieEngine);
ENGINE("kyra2", "Legend of Kyrandia: Hand of Fate", Kyra::Kyra2Engine);
ENGINE("scummv6", "SCUMM v6", Scumm::v6::Scummv6Engine);
po::options_description visible("Options");
visible.add_options()
("help,h", "Produce this help message.")
("engine,e", po::value<std::string>(), "Engine the script originates from.")
("list,l", "List the supported engines.")
("dump-disassembly,d", po::value<std::string>()->implicit_value(""), "Dump the disassembly to a file. Leave out filename to output to stdout.")
("dump-graph,g", po::value<std::string>()->implicit_value(""), "Output the control flow graph in dot format to a file. Leave out filename to output to stdout.")
("only-disassembly,D", "Stops after disassembly. Implies -d.")
("only-graph,G", "Stops after control flow graph has been generated. Implies -g.")
("show-unreachable,u", "Show the address and contents of unreachable groups in the script.")
("variant,v", po::value<std::string>()->default_value(""), "Tell the engine that the script is from a specific variant. To see a list of variants supported by a specific engine, use the -h option and the -e option together.")
("no-stack-effect,s", "Leave out the stack effect when printing raw instructions.");
po::options_description args("");
args.add(visible).add_options()
("input-file", po::value<std::string>(), "Input file");
po::positional_options_description fileArg;
fileArg.add("input-file", -1);
po::variables_map vm;
try {
// FIXME: If specified as the last parameter before the input file name, -d currently requires a filename to specified. -d must be specified earlier than that if outputting to stdout.
po::store(po::command_line_parser(argc, argv).options(args).positional(fileArg).run(), vm);
po::notify(vm);
} catch (std::exception& e) {
std::cout << e.what() << std::endl;
}
if (vm.count("list")) {
std::cout << "Available engines:" << "\n";
std::map<std::string, std::string>::iterator it;
for (it = engines.begin(); it != engines.end(); it++)
std::cout << (*it).first << " " << (*it).second << "\n";
return 0;
}
if (vm.count("help") || !vm.count("input-file")) {
std::cout << "Usage: " << argv[0] << " [option...] file" << "\n";
std::cout << visible << "\n";
if (vm.count("engine") && engines.find(vm["engine"].as<std::string>()) != engines.end()) {
Engine *engine = engineFactory.create(vm["engine"].as<std::string>());
std::vector<std::string> variants;
engine->getVariants(variants);
if (variants.empty()) {
std::cout << engines[vm["engine"].as<std::string>()] << " does not use variants.\n";
} else {
std::cout << "Supported variants for " << engines[vm["engine"].as<std::string>()] << ":\n";
for (std::vector<std::string>::iterator i = variants.begin(); i != variants.end(); ++i) {
std::cout << " " << *i << "\n";
}
}
delete engine;
std::cout << "\n";
}
std::cout << "Note: If outputting to stdout, -d or -g must NOT be specified immediately before the input file.\n";
return 1;
}
if (!vm.count("engine")) {
std::cout << "Engine must be specified.\n";
return 2;
} else if (engines.find(vm["engine"].as<std::string>()) == engines.end()) {
std::cout << "Unknown engine.\n";
return 2;
}
if (vm.count("no-stack-effect")) {
setOutputStackEffect(false);
}
Engine *engine = engineFactory.create(vm["engine"].as<std::string>());
engine->_variant = vm["variant"].as<std::string>();
std::string inputFile = vm["input-file"].as<std::string>();
// Disassembly
InstVec insts;
Disassembler *disassembler = engine->getDisassembler(insts);
disassembler->open(inputFile.c_str());
disassembler->disassemble();
if (vm.count("dump-disassembly")) {
std::streambuf *buf;
std::ofstream of;
if (vm["dump-disassembly"].as<std::string>() != "") {
of.open(vm["dump-disassembly"].as<std::string>().c_str());
buf = of.rdbuf();
} else {
//.........这里部分代码省略.........