diff --git a/LCS/Tools/src/makeClass.py b/LCS/Tools/src/makeClass.py index 957460b95ae6083e66e9d30b115d09c25af6f0b3..a23b91a9f4825791fed6dff3df2683d665bd575c 100755 --- a/LCS/Tools/src/makeClass.py +++ b/LCS/Tools/src/makeClass.py @@ -137,113 +137,40 @@ def addTemplates(type,readFile,writeFile,className,packageName,templateList,auto # replace CLASSUPPER with uppercase classname if aLine.find("%CLASSUPPER%") > -1: aLine = str.replace(aLine,"%CLASSUPPER%",className.upper()) - + + tmpltype = "<" + tmplparm = "<" + i=0 + while i < len(templateList): + if i > 0: + tmpltype += ", " + tmplparm += "," + tmpltype += "typename " + templateList[i] + tmplparm += templateList[i] + i+=1 + tmpltype += ">" + tmplparm += ">" + + # replace TEMPLATETYPE and TEMPLATEPARAM + if aLine.find("%TEMPLATETYPE%") > -1: + aLine = str.replace(aLine,"%TEMPLATETYPE%",tmpltype) + if aLine.find("%TEMPLATEPARAM%") > -1: + aLine = str.replace(aLine,"%TEMPLATEPARAM%",tmplparm) + # Check if !diy, template and .h file, if so include tcc in header file - if aLine.find("Include tcc file here when needed") > -1 and \ - type =="h" and autoTemplate == 1: - if subDirName != "": - writeFile.write("\n#include <"+packageName+"/"+subDirName+"/"+className+".tcc>\n") - else: - writeFile.write("\n#include <"+packageName+"/"+className+".tcc>\n") - aLine="" - elif aLine.find("Include tcc file here when needed") > -1: - aLine ="" - # find place to inserttemplates depending on filetype - if type=="h" and aLine.find("insert templates here") > -1: - writeFile.write("\n template< ") - i=0 - while i < len(templateList): - if i > 0: - writeFile.write(", ") - writeFile.write("typename "+templateList[i]) - i+=1 - writeFile.write(" >") - writeFile.write("\n class "+className) - writeFile.write("\n {") - writeFile.write("\n public:") - writeFile.write("\n\n "+className+"();") - writeFile.write("\n ~"+className+"();") - writeFile.write("\n private:") - writeFile.write("\n // Copying is not allowed") - writeFile.write("\n "+className+"(const "+className+"< ") - i=0 - while i < len(templateList): - if i > 0: - writeFile.write(", ") - writeFile.write(templateList[i]) - i+=1 - writeFile.write(" >& that);") - writeFile.write("\n "+className+"< ") - i=0 - while i < len(templateList): - if i > 0: - writeFile.write(", ") - writeFile.write(templateList[i]) - i+=1 - writeFile.write(" >& operator=(const "+className+"< ") - i=0 - while i < len(templateList): - if i > 0: - writeFile.write(", ") - writeFile.write(templateList[i]) - i+=1 - writeFile.write(" >& that);") - writeFile.write("\n };") - elif (type=="tcc" ) and aLine.find("insert templates here") > -1: - writeFile.write("\n template< ") - i=0 - while i < len(templateList): - if i > 0: - writeFile.write(", ") - writeFile.write("typename "+templateList[i]) - i+=1 - writeFile.write(" >") - writeFile.write("\n "+className+"< ") - i=0 - while i < len(templateList): - if i > 0: - writeFile.write(", ") - writeFile.write(templateList[i]) - i+=1 - writeFile.write(">::"+className+"()") - writeFile.write("\n {") - writeFile.write("\n work to do") - writeFile.write("\n }") - writeFile.write("\n") - - writeFile.write("\n template<") - i=0 - while i < len(templateList): - if i > 0: - writeFile.write(", ") - writeFile.write("typename "+templateList[i]) - i+=1 - writeFile.write(" >") - writeFile.write("\n "+className+"<") - i=0 - while i < len(templateList): - if i > 0: - writeFile.write(", ") - writeFile.write(templateList[i]) - i+=1 - writeFile.write(">::~"+className+"()") - writeFile.write("\n {") - writeFile.write("\n work to do") - writeFile.write("\n }") - writeFile.write("\n") - elif (type=="diy" ) and aLine.find("insert templates here") > -1: - writeFile.write("\n //template class "+className+"< ") - i=0 - while i < len(templateList): - if i > 0: - writeFile.write(", ") - writeFile.write(templateList[i]) - i+=1 - writeFile.write(" >;\n") - else: - writeFile.write(aLine) + if aLine.find("%INCLUDETCC%") > -1: + incstr = "" + if autoTemplate == 1: + if subDirName != "": + incstr = "#include <"+packageName+"/"+subDirName+"/"+className+".tcc>" + else: + incstr = "#include <"+packageName+"/"+className+".tcc>" + aLine = str.replace(aLine,"%INCLUDETCC%",incstr) + + writeFile.write(aLine) aLine=readFile.readline() + def makeDefaultClass(lofarDir,className,packageName,srcDir,incDir,subDirName): # default.h file readFile=openFile(lofarDir+"/LCS/Tools/src/templates/header.h_template","r") @@ -425,8 +352,8 @@ def main(argv): # # get Lofar base dir # - file= os.popen("echo $PWD | sed -e 's%/LOFAR/.*%/LOFAR%'") - lofarDir=str.replace(file.readline(),"\n","") + file = os.popen("echo $PWD | sed -e 's%/LOFAR/.*%/LOFAR%'") + lofarDir = str.replace(file.readline(),"\n","") file.close() baseDir = os.environ["PWD"] subDirName = "" @@ -481,14 +408,20 @@ def main(argv): # See if an include/PACKAGE directory exists. # If so, use that for the .h and .tcc files. # Create possible subdirectory if needed. - incDir=srcDir incDir = os.path.dirname(srcDir)+"/include/"+packageName + hdrDir = incDir if not os.path.exists(incDir): - incDir=srcDir + incDir = srcDir + hdrDir = srcDir + if subDirName != "": + hdrDir = incDir+"/"+subDirName else: - if not os.path.exists(incDir+"/"+subDirName): - os.makedirs(incDir+"/"+subDirName) - print "Created subdirectory "+incDir+"/"+subDirName + if subDirName != "": + hdrDir = incDir+"/"+subDirName + if not os.path.exists(hdrDir): + os.makedirs(hdrDir) + print "Created subdirectory "+hdrDir + # # Make a backup from the Original Makefiles @@ -516,25 +449,16 @@ def main(argv): # Check of given class name allready exists in the working directory as # directory or as file # - - if noMain and noTemplated: - if os.path.isfile(className+".h") or os.path.isfile(className+".cc"): - print "Sorry, that class allready exists. Please take another name" + if noMain: + if os.path.isfile(hdrDir+"/"+className+".h"): + print "Sorry, that class already exists. Please take another name" sys.exit(1) - if noMain and noTemplated==0: - if autoTemplate==0: - ext=".cc" - else: - ext=".tcc" - if os.path.isfile(className+ext): - print "Sorry, that name allready exists. Please take another one" - sys.exit(1) - if noMain==0: + else: if os.path.isfile(className+"Main.cc"): - print "Sorry, that name allready exists. Please take another one" + print "Sorry, that name already exists. Please take another one" sys.exit(1) - if os.path.isfile(className+".h") == 0 or os.path.isfile(className+".cc") == 0: - print "WARNING: the base classes for whom you are creating a Mainprogram" + if os.path.isfile(hdrDir+"/"+className+".h") == 0: + print "WARNING: the base classes for which you are creating a Mainprogram" print " are not available yet." print " please remember that you have to create them.\n" diff --git a/LCS/Tools/src/templates/header.cc_template b/LCS/Tools/src/templates/header.cc_template index b217f01c8b9bd91894c528cbd591cd1ed7662ddf..c4b5a61b3d24d060fe6ab37e3592bf0aa192aa05 100644 --- a/LCS/Tools/src/templates/header.cc_template +++ b/LCS/Tools/src/templates/header.cc_template @@ -36,8 +36,16 @@ namespace LOFAR { %CLASS%::~%CLASS%() {} - - + // Remove lines or remove comments for copy constructor and assignment. + ////%CLASS%::%CLASS% (const %CLASS%& that) + ////{} + ////%CLASS%& %CLASS%::operator= (const %CLASS%& that) + ////{ + //// if (this != &that) { + //// ... copy members ... + //// } + //// return *this; + ////} } // namespace %PACKAGE% } // namespace LOFAR diff --git a/LCS/Tools/src/templates/header.h_template b/LCS/Tools/src/templates/header.h_template index d08ecfaf79049e4b6ba74d2fdfdb4d0e0ef469ea..52226cecafbcf0b42955f1e0d20d4e18790a079d 100644 --- a/LCS/Tools/src/templates/header.h_template +++ b/LCS/Tools/src/templates/header.h_template @@ -20,8 +20,8 @@ //# //# $Id$ -#ifndef LOFAR_%PACKAGEUPPER%%SUBUPPER%%CLASSUPPER%_H -#define LOFAR_%PACKAGEUPPER%%SUBUPPER%%CLASSUPPER%_H +#ifndef LOFAR_%PACKAGEUPPER%_%SUBUPPER%%CLASSUPPER%_H +#define LOFAR_%PACKAGEUPPER%_%SUBUPPER%%CLASSUPPER%_H // \file %SUB%%CLASS%.h // one line description. @@ -52,8 +52,8 @@ namespace LOFAR private: // Copying is not allowed - %CLASS%(const %CLASS%& that); - %CLASS%& operator=(const %CLASS%& that); + %CLASS% (const %CLASS%& that); + %CLASS%& operator= (const %CLASS%& that); //# Datamembers diff --git a/LCS/Tools/src/templates/templated_header.cc_template b/LCS/Tools/src/templates/templated_header.cc_template index fa6984d1dbc80e94a10dae243a571633980d333a..2519a1c5b58599f77002434ff2617c94f130e196 100644 --- a/LCS/Tools/src/templates/templated_header.cc_template +++ b/LCS/Tools/src/templates/templated_header.cc_template @@ -20,8 +20,8 @@ //# //# $Id$ -#ifndef LOFAR_%PACKAGEUPPER%_%SUBUPPER%%CLASSUPPER%_CC -#define LOFAR_%PACKAGEUPPER%_%SUBUPPER%%CLASSUPPER%_CC +//# Always #include <lofar_config.h> first! +#include <lofar_config.h> //# Includes #include <Common/LofarLogger.h> @@ -30,9 +30,10 @@ namespace LOFAR { namespace %PACKAGE% { - //# Force the instantiation of the templates. - // insert templates here + //# Force the instantiation of templates. + // instantiate templates hereafter by replacing %TEMPLATEPARAM% by + // the actual template parameter type(s) + //template class %CLASS%%TEMPLATEPARAM%; } // namespace %PACKAGE% } // namespace LOFAR - diff --git a/LCS/Tools/src/templates/templated_header.h_template b/LCS/Tools/src/templates/templated_header.h_template index 0ee24f8c4e20a713aa14acf2e5d2c191674daa61..2868b321d9a8715ea566cb55aa2d74220d7f5b76 100644 --- a/LCS/Tools/src/templates/templated_header.h_template +++ b/LCS/Tools/src/templates/templated_header.h_template @@ -42,11 +42,27 @@ namespace LOFAR { // Description of class. - // insert templates here + + template %TEMPLATETYPE% + class %CLASS% + { + public: + %CLASS%(); + ~%CLASS%(); + + private: + // Copying is not allowed + %CLASS% (const %CLASS%%TEMPLATEPARAM%& that); + %CLASS%%TEMPLATEPARAM%& operator= (const %CLASS%%TEMPLATEPARAM%& that); + + //# Datamembers + + }; // @} } // namespace %PACKAGE% } // namespace LOFAR -// Include tcc file here when needed. +%INCLUDETCC% + #endif diff --git a/LCS/Tools/src/templates/templated_header.tcc_template b/LCS/Tools/src/templates/templated_header.tcc_template index a13d7457bed86f6ac47b7c82df2bc6eec6317b1f..db963f3d28f5d2dee018dd45b611db288728a208 100644 --- a/LCS/Tools/src/templates/templated_header.tcc_template +++ b/LCS/Tools/src/templates/templated_header.tcc_template @@ -30,8 +30,26 @@ namespace LOFAR { namespace %PACKAGE% { - // insert templates here + template %TEMPLATETYPE% + %CLASS%%TEMPLATEPARAM%::%CLASS%() + {} + + template %TEMPLATETYPE% + %CLASS%%TEMPLATEPARAM%::~%CLASS%() + {} + + // Remove lines or remove comments for copy constructor and assignment. + ////%CLASS%%TEMPLATEPARAM%::%CLASS% (const %CLASS%%TEMPLATEPARAM%& that) + ////{} + ////%CLASS%%TEMPLATEPARAM%& %CLASS%%TEMPLATEPARAM%::operator= (const %CLASS%%TEMPLATEPARAM%& that) + ////{ + //// if (this != &that) { + //// ... copy members ... + //// } + //// return *this; + ////} } // namespace %PACKAGE% } // namespace LOFAR +#endif