bool ActiveRecordClassGenerator::generate(const xml::ObjectPtr& object) { LITESQL_String fname = getOutputFilename(toLower(object->name + LITESQL_L(".rb"))); LITESQL_ofSstream os(fname.c_str()); LITESQL_String baseClass = object->parentObject.get() ? object->inherits : LITESQL_L("ActiveRecord::Base"); os << LITESQL_L("class ") << object->name << LITESQL_L(" < ") << baseClass << std::endl; for (RelationHandle::sequence::const_iterator it = object->handles.begin(); it!= object->handles.end(); it++) { os << ((*it)->relate->hasLimit() ? LITESQL_L("has_one") : LITESQL_L("has_many")) << LITESQL_L(" :") << (*it)->name; if (!(*it)->name.empty()) os << LITESQL_L(", :through => :") << (*it)->name; os << std::endl; } os << LITESQL_L("end") << std::endl; os.close(); return true; }
bool GraphvizGenerator::generateCode(const ObjectModel* model) { LITESQL_String fname = getOutputFilename(toLower(model->db.name + LITESQL_L(".dot"))); LITESQL_ofSstream os(fname.c_str()); os << LITESQL_L("digraph database {") << std::endl << LITESQL_L(" node[shape=box,color=black];") << std::endl << LITESQL_L(" subgraph inheritance {") << std::endl << LITESQL_L(" edge[style=dashed,dir=forward,arrowhead=normal];") << std::endl; CodeGenerator::generate(model->objects,os,4); os << LITESQL_L(" }") << std::endl << LITESQL_L(" subgraph relations {") << std::endl << LITESQL_L(" edge[dir=forward,arrowhead=vee];") << std::endl; CodeGenerator::generate(model->relations,os,4); os << LITESQL_L(" }") << std::endl << LITESQL_L("}") << std::endl; os.close(); return true; }
int atoi(const LITESQL_String &s) { return _tstoi(s.c_str()); }