/* linphone Copyright (C) 2013 Belledonne Communications SARL Simon Morlat (simon.morlat@linphone.org) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include "generator.hh" #ifdef WIN32 #include #endif CplusplusGenerator::CplusplusGenerator(){ } void CplusplusGenerator::generate(Project *proj){ list classes=proj->getClasses(); mCurProj=proj; #ifndef WIN32 mkdir(proj->getName().c_str(),S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IROTH); #else _mkdir(proj->getName().c_str()); #endif for_each(classes.begin(),classes.end(),bind1st(mem_fun(&CplusplusGenerator::writeClass),this)); } void CplusplusGenerator::writeClass(Class *klass){ ostringstream filename; if (klass->getType()!=Type::Class) return; filename<getName()<<"/"<getName()<<".hh"; mOutfile.open(filename.str().c_str()); if (!mOutfile.is_open()){ cerr<<"Could not write into "< &methods=klass->getMethods(); mCurClass=klass; mOutfile<<"/* Wrapper generated by lp-gen-wrappers, do not edit*/"<"<getName().empty()) mOutfile<<"namespace "<getName()<<"{"<getName()<<"{"<getName().empty()) mOutfile<<"} //end of namespace "<getName()<getType(); if (type->getBasicType()==Type::Class){ if (arg->isConst()){ mOutfile<<"const "; } mOutfile<getName(); if (arg->isPointer()) mOutfile<<"*"; }else if (type->getBasicType()==Type::Integer){ mOutfile<<"int"; }else if (type->getBasicType()==Type::Enum){ mOutfile<getName(); }else if (type->getBasicType()==Type::String){ if (!isReturn) mOutfile<<"const std::string &"; else mOutfile<<"std::string"; }else if (type->getBasicType()==Type::Void){ mOutfile<<"void"; }else if (type->getBasicType()==Type::Boolean){ mOutfile<<"bool"; } if (!isReturn && !arg->getName().empty()) mOutfile<<" "<getName(); } void CplusplusGenerator::writeTabs(int ntabs){ int i; for(i=0;i100 && comment[i]==' ')){ mOutfile<getReturnArg(); const list &args=method->getArgs(); list::const_iterator it; writeTabs(1); mOutfile<<"/**"<getHelp(),1); mOutfile<getName()<<"("; for(it=args.begin();it!=args.end();++it){ if (it!=args.begin()) mOutfile<<", "; writeArgument(*it); } mOutfile<<")"; if (method->isConst()) mOutfile<<"const"; mOutfile<<";"< classes=proj->getClasses(); mCurProj=proj; #ifndef WIN32 unlink(proj->getName().c_str()); mkdir(proj->getName().c_str(),S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IROTH); #else _mkdir(proj->getName().c_str()); #endif for_each(classes.begin(),classes.end(),bind1st(mem_fun(&JavascriptGenerator::writeClass),this)); } void JavascriptGenerator::writeClass(Class *klass){ ostringstream filename; if (klass->getType()!=Type::Class) return; filename<getName()<<"/"<getName()<<".js"; mOutfile.open(filename.str().c_str()); if (!mOutfile.is_open()){ cerr<<"Could not write into "< &methods=klass->getMethods(); mCurClass=klass; mOutfile<<"/* Wrapper generated by lp-gen-wrappers, do not edit*/"<getName().empty()) // mOutfile<<"namespace "<getName()<<"{"<getHelp()<getName()< properties=klass->getProperties(); for_each(properties.begin(),properties.end(),bind1st(mem_fun(&JavascriptGenerator::writeProperty),this)); mOutfile<getName().empty()) // mOutfile<<"} //end of namespace "<getName()<getBasicType()){ case Type::Float: case Type::Integer: mOutfile<<"number"; break; case Type::String: mOutfile<<"string"; break; case Type::Boolean: mOutfile<<"boolean"; break; case Type::Class: case Type::Enum: mOutfile<<"external:"<getName(); break; case Type::Void: mOutfile<<"void"; break; case Type::Callback: break; } } void JavascriptGenerator::writeArgument(Argument *arg, bool isReturn){ if (!isReturn){ mOutfile<<" * @param {"; writeType(arg->getType()); mOutfile<<"} "<getName()<<" - "<getHelp()<getType()); mOutfile<<"} "<getHelp()<100 && comment[i]==' ')){ mOutfile<getHelp(),0); mOutfile<getType()); mOutfile<<"} external:"<getName()<<"#"<getName()<getAttribute()==Property::ReadOnly) mOutfile<<" * @readonly"<getReturnArg(); const list &args=method->getArgs(); list::const_iterator it; if (method->getPropertyBehaviour()!=Method::None) return; if (method->getName()=="ref" || method->getName()=="unref") return; mOutfile<<"/**"<getHelp(),0); mOutfile<getName()<<"#"<getName()<