Commit 46374ee9 authored by Emmanuel Promayon's avatar Emmanuel Promayon
Browse files

FIXED clean code and generated code

parent 81042b7d
......@@ -8,4 +8,3 @@ camitk_library( STATIC
CEP_NAME SDK
DESCRIPTION "Create CEP and file skeletons from xml files"
)
......@@ -55,7 +55,7 @@ ComponentExtensionGenerator::ComponentExtensionGenerator(QString xmlFileName, QS
}
try {
std::string xmlFileStr = xmlFileName.toStdString();
std::auto_ptr<ComponentExtension> domComponentExtension = componentExtension(xmlFileStr, xml_schema::flags::dont_validate);
auto domComponentExtension = componentExtension(xmlFileStr, xml_schema::flags::dont_validate);
createFromDom(*domComponentExtension);
}
catch (...) {
......@@ -64,7 +64,7 @@ ComponentExtensionGenerator::ComponentExtensionGenerator(QString xmlFileName, QS
}
}
ComponentExtensionGenerator::ComponentExtensionGenerator( ComponentExtension& domComponentExtension, QString componentExtensionsDirectory, QString licence)
ComponentExtensionGenerator::ComponentExtensionGenerator(ComponentExtension& domComponentExtension, QString componentExtensionsDirectory, QString licence)
: ExtensionGenerator(componentExtensionsDirectory, licence, "Component") {
createFromDom(domComponentExtension);
}
......@@ -184,97 +184,107 @@ void ComponentExtensionGenerator::writeCFile(QString directory) {
}
}
else if (text.contains(QRegExp("@EXTENSIONSDEF@"))) {
for (QStringList::const_iterator suffixe = suffixesList.constBegin(); suffixe != suffixesList.constEnd(); suffixe++) {
outc << " ext << \"" << (*suffixe) << "\";" << endl;
}
}
else if (text.contains(QRegExp("@IF_NO_SUFFIX@"))) {
std::cout << " inside @IF_NO_SUFFIX@" << std::endl;
text = inc.readLine();
if (suffixesList.isEmpty()) {
std::cout << "No suffix !" << std::endl;
// Copy what is between @IF_NO_SUFFIX@ and @ELSE_IF_ONLY_ONE_SUFFIX@
while (! text.contains(QRegExp("@ELSE_IF_ONLY_ONE_SUFFIX@"))) {
outc << text << endl;
text = inc.readLine();
}
// Disregard what is between @ELSE_IF_ONLY_ONE_SUFFIX@ and @END_IF_NO_SUFFIX@
while (! text.contains(QRegExp("@END_IF_NO_SUFFIX@"))) {
text = inc.readLine();
}
}
else if (suffixesList.size() == 1) {
std::cout << "One suffix !" << std::endl;
// Disregard what is between @IF_NO_SUFFIX@ and @ELSE_IF_ONLY_ONE_SUFFIX@
while (! text.contains(QRegExp("@ELSE_IF_ONLY_ONE_SUFFIX@"))) {
text = inc.readLine();
}
text = inc.readLine();
// Find the component class corresponding to the extension
QString componentClassName = findComponentClass(suffixesList.at(0));
// Copy what is between @ELSE_IF_ONLY_ONE_SUFFIX@ and @ELSE_IF_SEVERAL_SUFFIX@
while (! text.contains(QRegExp("@ELSE_IF_SEVERAL_SUFFIX@"))) {
text.replace(QRegExp("@TOPLEVELCOMPONENTCLASSNAME@"), componentClassName);
outc << text;
text = inc.readLine();
else {
if (text.contains(QRegExp("@EXTENSIONSDEF@"))) {
for (QStringList::const_iterator suffixe = suffixesList.constBegin(); suffixe != suffixesList.constEnd(); suffixe++) {
outc << " ext << \"" << (*suffixe) << "\";" << endl;
}
// Disregard what is between @ELSE_IF_SEVERAL_SUFFIX@ and @END_IF_NO_SUFFIX@
while (! text.contains(QRegExp("@END_IF_NO_SUFFIX@"))) {
text = inc.readLine();
}
}
else { // several suffixes
std::cout << "Several suffixes !" << std::endl;
// Disregard what is between @IF_NO_SUFFIX@ and @ELSE_IF_SEVERAL_SUFFIX@
while (! text.contains(QRegExp("@ELSE_IF_SEVERAL_SUFFIX@"))) {
else {
if (text.contains(QRegExp("@IF_NO_SUFFIX@"))) {
std::cout << "inside @IF_NO_SUFFIX@" << std::endl;
text = inc.readLine();
}
// Copy what is between @ELSE_IF_SEVERAL_SUFFIX@ and @END_IF_NO_SUFFIX@
while (! text.contains(QRegExp("@END_IF_NO_SUFFIX@"))) {
text = inc.readLine();
text.replace(QRegExp("@EXTENSIONCLASSNAME@"), className);
if (text.contains(QRegExp("@EXTENSIONSDEF@"))) {
for (QStringList::const_iterator suffixe = suffixesList.constBegin(); suffixe != suffixesList.constEnd(); suffixe++) {
outc << " ext << \"" << (*suffixe) << "\";" << endl;
if (suffixesList.isEmpty()) {
std::cout << "No suffix" << std::endl;
// Copy what is between @IF_NO_SUFFIX@ and @ELSE_IF_ONLY_ONE_SUFFIX@
while (! text.contains(QRegExp("@ELSE_IF_ONLY_ONE_SUFFIX@"))) {
outc << text << endl;
text = inc.readLine();
}
}
else if (text.contains(QRegExp("@CASES@"))) {
int suffixeIdx;
for (suffixeIdx = 0; suffixeIdx < suffixesList.size(); suffixeIdx ++) {
QString componentClassName = findComponentClass(suffixesList.at(suffixeIdx));
outc << " case " << suffixeIdx << ": " << endl;
outc << " component = new " << componentClassName << "(fileName);" << endl;
outc << " break;" << endl;
// Disregard what is between @ELSE_IF_ONLY_ONE_SUFFIX@ and @END_IF_NO_SUFFIX@
while (! text.contains(QRegExp("@END_IF_NO_SUFFIX@"))) {
text = inc.readLine();
}
}
else {
if (! text.contains(QRegExp("@END_IF_NO_SUFFIX@"))) {
outc << text << endl;
if (suffixesList.size() == 1) {
std::cout << "One suffix" << std::endl;
// Disregard what is between @IF_NO_SUFFIX@ and @ELSE_IF_ONLY_ONE_SUFFIX@
while (! text.contains(QRegExp("@ELSE_IF_ONLY_ONE_SUFFIX@"))) {
text = inc.readLine();
}
text = inc.readLine();
// Find the component class corresponding to the extension
QString componentClassName = findComponentClass(suffixesList.at(0));
// Copy what is between @ELSE_IF_ONLY_ONE_SUFFIX@ and @ELSE_IF_SEVERAL_SUFFIX@
while (! text.contains(QRegExp("@ELSE_IF_SEVERAL_SUFFIX@"))) {
text.replace(QRegExp("@TOPLEVELCOMPONENTCLASSNAME@"), componentClassName);
outc << text;
text = inc.readLine();
}
// Disregard what is between @ELSE_IF_SEVERAL_SUFFIX@ and @END_IF_NO_SUFFIX@
while (! text.contains(QRegExp("@END_IF_NO_SUFFIX@"))) {
text = inc.readLine();
}
}
else { // several suffixes
std::cout << "Several suffixes" << std::endl;
// Disregard what is between @IF_NO_SUFFIX@ and @ELSE_IF_SEVERAL_SUFFIX@
while (! text.contains(QRegExp("@ELSE_IF_SEVERAL_SUFFIX@"))) {
text = inc.readLine();
}
// Copy what is between @ELSE_IF_SEVERAL_SUFFIX@ and @END_IF_NO_SUFFIX@
while (! text.contains(QRegExp("@END_IF_NO_SUFFIX@"))) {
text = inc.readLine();
text.replace(QRegExp("@EXTENSIONCLASSNAME@"), className);
if (text.contains(QRegExp("@EXTENSIONSDEF@"))) {
for (QStringList::const_iterator suffixe = suffixesList.constBegin(); suffixe != suffixesList.constEnd(); suffixe++) {
outc << " ext << \"" << (*suffixe) << "\";" << endl;
}
}
else {
if (text.contains(QRegExp("@CASES@"))) {
int suffixeIdx;
for (suffixeIdx = 0; suffixeIdx < suffixesList.size(); suffixeIdx ++) {
QString componentClassName = findComponentClass(suffixesList.at(suffixeIdx));
outc << " case " << suffixeIdx << ": " << endl;
outc << " component = new " << componentClassName << "(fileName);" << endl;
outc << " break;" << endl;
}
}
else {
if (! text.contains(QRegExp("@END_IF_NO_SUFFIX@"))) {
outc << text << endl;
}
}
}
}
}
}
// current line
outc << endl;
}
else {
outc << text << endl;
}
}
}
else {
outc << text << endl;
}
}
while (! text.isNull());
extFileC.close();
initCFile.close();
}
......
......@@ -24,13 +24,12 @@ QStringList @EXTENSIONCLASSNAME@::getFileExtensions() const {
// --------------- Open -------------------
Component * @EXTENSIONCLASSNAME@::open(const QString & fileName) throw (AbortException) {
@IF_NO_SUFFIX@
@IF_NO_SUFFIX@
// Complete this function by creating a component responding to the fileName suffix.
return NULL;
@ELSE_IF_ONLY_ONE_SUFFIX@
@ELSE_IF_ONLY_ONE_SUFFIX@
return new @TOPLEVELCOMPONENTCLASSNAME@(fileName);
@ELSE_IF_SEVERAL_SUFFIX@
@ELSE_IF_SEVERAL_SUFFIX@
Component * component;
QStringList ext;
@EXTENSIONSDEF@
......@@ -49,7 +48,7 @@ Component * @EXTENSIONCLASSNAME@::open(const QString & fileName) throw (AbortExc
break;
}
return component;
@END_IF_NO_SUFFIX@
@END_IF_NO_SUFFIX@
}
// --------------- Save --------------------
......
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