Commit 8f8c3c57 authored by Sebastien Ponce's avatar Sebastien Ponce
Browse files

Improvements in order to support generation of code that is not inside castor namespace

parent 078476e3
......@@ -2,28 +2,40 @@
if ("$1" == "-h") then
echo "Usage :"
echo " gencastor [-w castor_workdir] [-h] [-v|--version] XMIFile"
echo " gencastor [-w castor_workdir] [-c topNamespace] [-h] [-v|--version] XMIFile"
exit
else if ("$1" == "-v" || "$1" == "--version") then
/usr/bin/gencastor.bin --version
exit
else if ("$1" == "-w") then
set WORKDIR=$2
set XMIFILE=$3
if ("$3" == "-c") then
set TOPNS = $4
set XMIFILE=$5
else
set TOPNS = 'castor'
set XMIFILE=$3
endif
else
set WORKDIR=`pwd`
set XMIFILE=$1
if ("$1" == "-c") then
set TOPNS = $2
set XMIFILE=$3
else
set TOPNS = 'castor'
set XMIFILE=$1
endif
endif
set TMPDIR=`mktemp /tmp/gencastor-XXXXXX`
rm -rf ${TMPDIR}
mkdir -p ${TMPDIR}/castor/db
cp ${WORKDIR}/castor/db/*.sql ${TMPDIR}/castor/db/
mkdir -p ${TMPDIR}/${TOPNS}/db
cp ${WORKDIR}/${TOPNS}/db/*.sql ${TMPDIR}/${TOPNS}/db/
/usr/bin/gencastor.bin -o ${TMPDIR} --nocrashhandler ${XMIFILE}
/usr/bin/gencastor.bin -o ${TMPDIR} -c ${TOPNS} --nocrashhandler ${XMIFILE}
set pushdsilent
pushd ${TMPDIR}
rm -f castor/db/*Generated*
rm -f ${TOPNS}/db/*Generated*
foreach f (`find . -type f`)
#echo $f
if !(-f ${WORKDIR}/${f}) then
......
......@@ -20,6 +20,11 @@
// 2004-01-13 : Sebastien Ponce
//-----------------------------------------------------------------------------
//=============================================================================
// initialization of static variables
//=============================================================================
QString CppCastorWriter::s_topNS = "castor";
//=============================================================================
// Standard constructor, initializes variables
//=============================================================================
......
......@@ -43,7 +43,7 @@ class CppCastorWriter : public SimpleCodeGenerator {
/**
* accessor to topNS
*/
void setTopNS(QString value) { m_topNS = value; }
void setTopNS(QString value) { s_topNS = value; }
protected:
/**
......@@ -61,7 +61,7 @@ class CppCastorWriter : public SimpleCodeGenerator {
std::set<QString> m_ignoreClasses;
/** The top namespace of the generated software */
QString m_topNS;
static QString s_topNS;
};
......
......@@ -415,7 +415,8 @@ void CppCppClassWriter::writeClone(CppBaseWriter* obj,
//=============================================================================
void CppCppClassWriter::writeTYPE(CppBaseWriter* obj,
QTextStream &stream) {
obj->addInclude("\"castor/Constants.hpp\"");
obj->addInclude(QString("\"") + s_topNS +
"/Constants.hpp\"");
stream << obj->getIndent() << "return OBJ_"
<< obj->classInfo()->className << ";" << endl;
}
......@@ -427,7 +428,7 @@ void CppCppClassWriter::writePrint(CppBaseWriter* obj,
QTextStream &stream) {
stream << obj->getIndent()
<< obj->fixTypeName("ObjectSet",
obj->getNamespace("ObjectSet"),
"castor",
obj->classInfo()->packageName)
<< " alreadyPrinted;" << endl << obj->getIndent()
<< "print(std::cout, \"\", alreadyPrinted);"
......
......@@ -39,18 +39,18 @@ void CppCppMyCnvWriter::startSQLFile() {
// Preparing SQL file for creation/deletion of the database
QFile file;
openFile(file,
"castor/db/mysql.sql",
s_topNS + "/db/mysql.sql",
IO_WriteOnly | IO_Truncate);
QTextStream stream(&file);
insertFileintoStream(stream, "castor/db/mysqlHeader.sql");
insertFileintoStream(stream, s_topNS + "/db/mysqlHeader.sql");
file.close();
openFile(file, "castor/db/mysqlGeneratedHeader.sql",
openFile(file, s_topNS + "/db/mysqlGeneratedHeader.sql",
IO_WriteOnly | IO_Truncate);
file.close();
openFile(file, "castor/db/mysqlGeneratedCore.sql",
openFile(file, s_topNS + "/db/mysqlGeneratedCore.sql",
IO_WriteOnly | IO_Truncate);
file.close();
openFile(file, "castor/db/mysqlGeneratedTrailer.sql",
openFile(file, s_topNS + "/db/mysqlGeneratedTrailer.sql",
IO_WriteOnly | IO_Truncate);
file.close();
}
......@@ -78,13 +78,13 @@ void CppCppMyCnvWriter::endSQLFile() {
// Preparing SQL file for creation/deletion of the database
QFile file;
openFile(file,
"castor/db/mysql.sql",
s_topNS + "/db/mysql.sql",
IO_WriteOnly | IO_Append);
QTextStream stream(&file);
insertFileintoStream(stream, "castor/db/mysqlGeneratedHeader.sql");
insertFileintoStream(stream, "castor/db/mysqlGeneratedCore.sql");
insertFileintoStream(stream, "castor/db/mysqlGeneratedTrailer.sql");
insertFileintoStream(stream, "castor/db/mysqlTrailer.sql");
insertFileintoStream(stream, s_topNS + "/db/mysqlGeneratedHeader.sql");
insertFileintoStream(stream, s_topNS + "/db/mysqlGeneratedCore.sql");
insertFileintoStream(stream, s_topNS + "/db/mysqlGeneratedTrailer.sql");
insertFileintoStream(stream, s_topNS + "/db/mysqlTrailer.sql");
file.close();
}
......@@ -96,8 +96,8 @@ bool CppCppMyCnvWriter::init(UMLClassifier* c, QString fileName) {
this->CppBaseWriter::init(c, fileName);
// fixes the namespace
m_originalPackage = m_classInfo->fullPackageName;
m_classInfo->packageName = "castor::db::mysql";
m_classInfo->fullPackageName = "castor::db::mysql::";
m_classInfo->packageName = s_topNS + "::db::mysql";
m_classInfo->fullPackageName = s_topNS + "::db::mysql::";
// includes converter header file and object header file
m_includes.insert(QString("\"My") + m_classInfo->className + "Cnv.hpp\"");
......@@ -531,15 +531,15 @@ void CppCppMyCnvWriter::writeConstants() {
void CppCppMyCnvWriter::writeSqlStatements() {
QFile file, hFile, tFile;
openFile(hFile,
"castor/db/mysqlGeneratedHeader.sql",
s_topNS + "/db/mysqlGeneratedHeader.sql",
IO_WriteOnly | IO_Append);
QTextStream hStream(&hFile);
openFile(file,
"castor/db/mysqlGeneratedCore.sql",
s_topNS + "/db/mysqlGeneratedCore.sql",
IO_WriteOnly | IO_Append);
QTextStream stream(&file);
openFile(tFile,
"castor/db/mysqlGeneratedTrailer.sql",
s_topNS + "/db/mysqlGeneratedTrailer.sql",
IO_WriteOnly | IO_Append);
QTextStream tStream(&tFile);
stream << "/* SQL statements for type "
......@@ -956,7 +956,7 @@ void CppCppMyCnvWriter::writeFillRep() {
!isEnum(as->remotePart.typeName)) {
if (as->type.multiRemote == MULT_ONE ||
as->type.multiRemote == MULT_N) {
addInclude("\"castor/Constants.hpp\"");
addInclude(QString("\"") + s_topNS + "/Constants.hpp\"");
*m_stream << getIndent() << "case castor::OBJ_"
<< capitalizeFirstLetter(as->remotePart.typeName)
<< " :" << endl;
......@@ -1067,7 +1067,7 @@ void CppCppMyCnvWriter::writeFillObj() {
!isEnum(as->remotePart.typeName)) {
if (as->type.multiRemote == MULT_ONE ||
as->type.multiRemote == MULT_N) {
addInclude("\"castor/Constants.hpp\"");
addInclude(QString("\"") + s_topNS + "/Constants.hpp\"");
*m_stream << getIndent() << "case castor::OBJ_"
<< capitalizeFirstLetter(as->remotePart.typeName)
<< " :" << endl;
......@@ -1253,7 +1253,7 @@ void CppCppMyCnvWriter::writeBasicMult1FillRep(Assoc* as) {
<< "if (rset.size() != 1) {"
<< endl;
m_indent++;
addInclude("\"castor/Constants.hpp\"");
addInclude(QString("\"") + s_topNS + "/Constants.hpp\"");
*m_stream << getIndent()
<< fixTypeName("BaseAddress",
"castor",
......@@ -2281,7 +2281,7 @@ void CppCppMyCnvWriter::writeDeleteRepContent() {
<< "() != 0) {" << endl;
m_indent++;
fixTypeName("MyCnvSvc",
"castor::db::mysql",
s_topNS + "::db::mysql",
m_classInfo->packageName);
*m_stream << getIndent()
<< "cnvSvc()->deleteRep(0, obj->"
......@@ -2306,7 +2306,7 @@ void CppCppMyCnvWriter::writeDeleteRepContent() {
<< " it++) {" << endl;
m_indent++;
fixTypeName("MyCnvSvc",
"castor::db::mysql",
s_topNS + "::db::mysql",
m_classInfo->packageName);
*m_stream << getIndent()
<< "cnvSvc()->deleteRep(0, *it, false);"
......@@ -2717,7 +2717,7 @@ QString CppCppMyCnvWriter::getSQLType(QString& type) {
void CppCppMyCnvWriter::printSQLError(QString name,
MemberList& members,
AssocList& assocs) {
fixTypeName("MyCnvSvc", "castor::db::mysql", m_classInfo->packageName);
fixTypeName("MyCnvSvc", s_topNS + "::db::mysql", m_classInfo->packageName);
*m_stream << getIndent() << "try {" << endl;
m_indent++;
*m_stream << getIndent()
......
......@@ -70,8 +70,8 @@ bool CppCppOraCnvWriter::init(UMLClassifier* c, QString fileName) {
this->CppBaseWriter::init(c, fileName);
// fixes the namespace
m_originalPackage = m_classInfo->fullPackageName;
m_classInfo->packageName = "castor::db::ora";
m_classInfo->fullPackageName = "castor::db::ora::";
m_classInfo->packageName = s_topNS + "::db::ora";
m_classInfo->fullPackageName = s_topNS + "::db::ora::";
// includes converter header file and object header file
m_includes.insert(QString("\"Ora") + m_classInfo->className + "Cnv.hpp\"");
m_includes.insert(QString("\"") +
......@@ -505,19 +505,19 @@ void CppCppOraCnvWriter::writeSqlStatements() {
/*
QFile file, tFile, fileD, hFileD;
openFile(file,
"castor/db/oracleGeneratedCore_create.sql",
s_topNS + "/db/oracleGeneratedCore_create.sql",
IO_WriteOnly | IO_Append);
QTextStream stream(&file);
openFile(tFile,
"castor/db/oracleGeneratedTrailer_create.sql",
s_topNS + "/db/oracleGeneratedTrailer_create.sql",
IO_WriteOnly | IO_Append);
QTextStream tStream(&tFile);
openFile(hFileD,
"castor/db/oracleGeneratedHeader_drop.sql",
s_topNS + "/db/oracleGeneratedHeader_drop.sql",
IO_WriteOnly | IO_Append);
QTextStream hStreamD(&hFileD);
openFile(fileD,
"castor/db/oracleGeneratedCore_drop.sql",
s_topNS + "/db/oracleGeneratedCore_drop.sql",
IO_WriteOnly | IO_Append);
QTextStream streamD(&fileD);
......@@ -961,7 +961,7 @@ void CppCppOraCnvWriter::writeFillRep() {
!isEnum(as->remotePart.typeName)) {
if (as->type.multiRemote == MULT_ONE ||
as->type.multiRemote == MULT_N) {
addInclude("\"castor/Constants.hpp\"");
addInclude(QString("\"") + s_topNS + "/Constants.hpp\"");
*m_stream << getIndent() << "case castor::OBJ_"
<< capitalizeFirstLetter(as->remotePart.typeName)
<< " :" << endl;
......@@ -1073,7 +1073,7 @@ void CppCppOraCnvWriter::writeFillObj() {
!isEnum(as->remotePart.typeName)) {
if (as->type.multiRemote == MULT_ONE ||
as->type.multiRemote == MULT_N) {
addInclude("\"castor/Constants.hpp\"");
addInclude(QString("\"") + s_topNS + "/Constants.hpp\"");
*m_stream << getIndent() << "case castor::OBJ_"
<< capitalizeFirstLetter(as->remotePart.typeName)
<< " :" << endl;
......@@ -1259,7 +1259,7 @@ void CppCppOraCnvWriter::writeBasicMult1FillRep(Assoc* as) {
<< "if (oracle::occi::ResultSet::END_OF_FETCH == rset->next()) {"
<< endl;
m_indent++;
addInclude("\"castor/Constants.hpp\"");
addInclude(QString("\"") + s_topNS + "/Constants.hpp\"");
*m_stream << getIndent()
<< fixTypeName("BaseAddress",
"castor",
......@@ -2283,7 +2283,7 @@ void CppCppOraCnvWriter::writeDeleteRepContent() {
<< "() != 0) {" << endl;
m_indent++;
fixTypeName("OraCnvSvc",
"castor::db::ora",
s_topNS + "::db::ora",
m_classInfo->packageName);
*m_stream << getIndent()
<< "cnvSvc()->deleteRep(0, obj->"
......@@ -2308,7 +2308,7 @@ void CppCppOraCnvWriter::writeDeleteRepContent() {
<< " it++) {" << endl;
m_indent++;
fixTypeName("OraCnvSvc",
"castor::db::ora",
s_topNS + "::db::ora",
m_classInfo->packageName);
*m_stream << getIndent()
<< "cnvSvc()->deleteRep(0, *it, false);"
......@@ -2723,7 +2723,7 @@ QString CppCppOraCnvWriter::getSQLType(QString& type) {
void CppCppOraCnvWriter::printSQLError(QString name,
MemberList& members,
AssocList& assocs) {
fixTypeName("OraCnvSvc", "castor::db::ora", m_classInfo->packageName);
fixTypeName("OraCnvSvc", s_topNS + "::db::ora", m_classInfo->packageName);
*m_stream << getIndent() << "try {" << endl;
m_indent++;
*m_stream << getIndent()
......
......@@ -27,8 +27,8 @@ bool CppCppStreamCnvWriter::init(UMLClassifier* c, QString fileName) {
this->CppBaseWriter::init(c, fileName);
// fixes the namespace
m_originalPackage = m_classInfo->fullPackageName;
m_classInfo->packageName = "castor::io";
m_classInfo->fullPackageName = "castor::io::";
m_classInfo->packageName = s_topNS + "::io";
m_classInfo->fullPackageName = s_topNS + "::io::";
// includes converter header file and object header file
m_includes.insert(QString("\"Stream") + m_classInfo->className + "Cnv.hpp\"");
m_includes.insert(QString("\"") +
......@@ -71,7 +71,11 @@ void CppCppStreamCnvWriter::writeConstructors() {
"castor",
m_classInfo->packageName)
<< " cnvSvc) :" << endl
<< getIndent() << " StreamBaseCnv(cnvSvc) {}"
<< getIndent() << " "
<< fixTypeName("StreamBaseCnv",
"castor::io",
m_classInfo->packageName)
<< "(cnvSvc) {}"
<< endl << endl;
// Destructor
writeWideHeaderComment("Destructor", getIndent(), *m_stream);
......@@ -356,9 +360,10 @@ void CppCppStreamCnvWriter::writeUnmarshal() {
<< ") {" << endl;
m_indent++;
fixTypeName("StreamCnvSvc", "castor::io", m_classInfo->packageName);
addInclude("\"castor/Constants.hpp\"");
*m_stream << getIndent()
<< fixTypeName("StreamAddress", "castor::io", "")
<< " ad(stream, \"StreamCnvSvc\", SVC_STREAMCNV);"
<< " ad(stream, \"StreamCnvSvc\", castor::SVC_STREAMCNV);"
<< endl << getIndent()
<< fixTypeName("IObject*",
"castor",
......
......@@ -218,12 +218,11 @@ void CppHBaseCnvWriter::writeClassDecl(const QString& doc) {
<< formatDoc (doc, getIndent() + " * ")
<< getIndent()<<" */" << endl
<< getIndent() << "class " << m_prefix << m_classInfo->className
<< "Cnv : public " << m_prefix
<< "BaseCnv {" << endl << endl;
<< "Cnv : public "
<< fixTypeName(m_prefix + "BaseCnv",
"castor::io",
m_classInfo->packageName)
<< " {" << endl << endl;
m_indent++;
// Take care to include the base class declaration
fixTypeName(m_prefix + "BaseCnv",
m_classInfo->packageName,
m_classInfo->packageName);
}
......@@ -25,7 +25,7 @@ bool CppHMyCnvWriter::init(UMLClassifier* c, QString fileName) {
// call upper class init
this->CppBaseWriter::init(c, fileName);
// fixes the namespace
m_classInfo->packageName = "castor::db::mysql";
m_classInfo->packageName = s_topNS + "::db::mysql";
// calls the postinit of this class
postinit(c, fileName);
return true;
......
......@@ -25,7 +25,7 @@ bool CppHOraCnvWriter::init(UMLClassifier* c, QString fileName) {
// call upper class init
this->CppBaseWriter::init(c, fileName);
// fixes the namespace
m_classInfo->packageName = "castor::db::ora";
m_classInfo->packageName = s_topNS + "::db::ora";
// calls the postinit of this class
postinit(c, fileName);
return true;
......
......@@ -25,7 +25,7 @@ bool CppHStreamCnvWriter::init(UMLClassifier* c, QString fileName) {
// call upper class init
this->CppBaseWriter::init(c, fileName);
// fixes the namespace
m_classInfo->packageName = "castor::io";
m_classInfo->packageName = s_topNS + "::io";
// calls the postinit of this class
postinit(c, fileName);
return true;
......
......@@ -69,7 +69,7 @@ void CppWriter::configGenerator(CppBaseWriter *cg) {
CodeGenerationPolicy *childPolicy = cg->getPolicy();
childPolicy->setHeadingFileDir(parentPolicy->getHeadingFileDir());
childPolicy->setOutputDirectory(parentPolicy->getOutputDirectory());
cg->setTopNS(m_topNS);
cg->setTopNS(s_topNS);
}
void CppWriter::runGenerator(CppBaseWriter *cg,
......@@ -112,8 +112,8 @@ void CppWriter::writeClass(UMLClassifier *c) {
// build information on the calss
ClassifierInfo classInfo(c, m_doc);
// If not in namespace castor, ignore the class
if (classInfo.packageName.left(6) != "castor") {
// If not in our namespace, ignore the class
if (classInfo.packageName.left(s_topNS.length()) != s_topNS) {
return;
}
......@@ -221,21 +221,21 @@ void CppWriter::writeClass(UMLClassifier *c) {
if (classInfo->allImplementedAbstracts.contains(concept)) {
// check existence of the directory
QDir outputDirectory = getPolicy()->getOutputDirectory();
QDir packageDir(getPolicy()->getOutputDirectory().absPath() + "/castor/db");
QDir packageDir(getPolicy()->getOutputDirectory().absPath() + "/" + s_topNS + "/db");
if (! (packageDir.exists() || packageDir.mkdir(packageDir.absPath()) ) ) {
std::cerr << "Cannot create the package folder "
<< packageDir.absPath().ascii()
<< "\nPlease check the access rights" << std::endl;
return;
}
QDir packageDirOra(getPolicy()->getOutputDirectory().absPath() + "/castor/db/ora");
QDir packageDirOra(getPolicy()->getOutputDirectory().absPath() + "/" + s_topNS + "/db/ora");
if (! (packageDirOra.exists() || packageDirOra.mkdir(packageDirOra.absPath()) ) ) {
std::cerr << "Cannot create the package folder "
<< packageDirOra.absPath().ascii()
<< "\nPlease check the access rights" << std::endl;
return;
}
QDir packageDirDb(getPolicy()->getOutputDirectory().absPath() + "/castor/db/cnv");
QDir packageDirDb(getPolicy()->getOutputDirectory().absPath() + "/" + s_topNS + "/db/cnv");
if (! (packageDirDb.exists() || packageDirDb.mkdir(packageDirDb.absPath()) ) ) {
std::cerr << "Cannot create the package folder "
<< packageDirDb.absPath().ascii()
......@@ -246,10 +246,10 @@ void CppWriter::writeClass(UMLClassifier *c) {
// run generation
int i = fileName.findRev('/') + 1;
QString file = fileName.right(fileName.length()-i);
runGenerator(dbhw, "castor/db/cnv/Db" + file + "Cnv.hpp", c);
runGenerator(dbcppw, "castor/db/cnv/Db" + file + "Cnv.cpp", c);
runGenerator(orahw, "castor/db/ora/Ora" + file + "Cnv.hpp", c);
runGenerator(oracppw, "castor/db/ora/Ora" + file + "Cnv.cpp", c);
runGenerator(dbhw, s_topNS + "/db/cnv/Db" + file + "Cnv.hpp", c);
runGenerator(dbcppw, s_topNS + "/db/cnv/Db" + file + "Cnv.cpp", c);
runGenerator(orahw, s_topNS + "/db/ora/Ora" + file + "Cnv.hpp", c);
runGenerator(oracppw, s_topNS + "/db/ora/Ora" + file + "Cnv.cpp", c);
}
}
UMLObject* obj = m_doc->findUMLObject(QString("castor::IStreamable"),
......@@ -257,7 +257,7 @@ void CppWriter::writeClass(UMLClassifier *c) {
const UMLClassifier *concept = dynamic_cast<UMLClassifier*>(obj);
if (classInfo->allImplementedAbstracts.contains(concept)) {
// check existence of the directory
QDir packageDir(getPolicy()->getOutputDirectory().absPath() + "/castor/io");
QDir packageDir(getPolicy()->getOutputDirectory().absPath() + "/" + s_topNS + "/io");
if (! (packageDir.exists() || packageDir.mkdir(packageDir.absPath()) ) ) {
std::cerr << "Cannot create the package folder "
<< packageDir.absPath().ascii()
......@@ -267,8 +267,8 @@ void CppWriter::writeClass(UMLClassifier *c) {
// run generation
int i = fileName.findRev('/') + 1;
QString file = fileName.right(fileName.length()-i);
runGenerator(streamhw, "castor/io/Stream" + file + "Cnv.hpp", c);
runGenerator(streamcppw, "castor/io/Stream" + file + "Cnv.cpp", c);
runGenerator(streamhw, s_topNS + "/io/Stream" + file + "Cnv.hpp", c);
runGenerator(streamcppw, s_topNS + "/io/Stream" + file + "Cnv.cpp", c);
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment