int generateCode(ObjectModel& model) { CompositeGenerator generator; generator.setOutputDirectory(options.output_dir); for (std::vector<LiteSQL_String>::const_iterator target= options.targets.begin(); target!=options.targets.end();target++) { if (*target == LiteSQL_L( "c++" )) { CppGenerator* pCppGen = new CppGenerator(); pCppGen->setOutputSourcesDirectory(options.output_sources); pCppGen->setOutputIncludesDirectory(options.output_includes); generator.add(pCppGen); } else if (*target == LiteSQL_L( "graphviz" )) { generator.add(new GraphvizGenerator()); } else if (*target == LiteSQL_L( "ruby-activerecord" )) { generator.add(new RubyActiveRecordGenerator()); } else { throw litesql::Except( LiteSQL_L( "unsupported target: " ) + *target); } } return generator.generateCode(&model)? 0 : 1 ; }
void LitesqlGeneratePanel::OnRunClick( wxCommandEvent& WXUNUSED(event) ) { m_gaugeRunProgress->SetLabel(_("Running")); struct options_t { string output_dir; string output_includes; bool refresh; vector<string> targets; }; options_t options = {"","",true}; options.targets.push_back("c++"); options.output_includes = options.output_dir = m_dirPickerOutputDir->GetPath().ToUTF8(); CompositeGenerator generator; generator.setOutputDirectory(options.output_dir); for (size_t index=0; index < m_checkListGenerators->GetCount();index++) { if (m_checkListGenerators->IsChecked(index)) { string key(m_checkListGenerators->GetString(index).ToUTF8()); CodeGenerator::create(key.c_str()); CodeGenerator::FactoryMap::iterator it = CodeGenerator::getFactoryMap().find(key); if (it != CodeGenerator::getFactoryMap().end() && it->second!=NULL) { generator.add(it->second->create()); } } } wxString s (generator.generateCode( m_pModel.get()) ? _("Success") : _("Fail") ); wxMessageBox(s); }