Skip to content
Snippets Groups Projects
Commit b91ba0f6 authored by Ger van Diepen's avatar Ger van Diepen
Browse files

BugID: 528

Put templated class code in template file
Added _ in include guard
Check correctly on existence of class
parent 13c53fe2
No related branches found
No related tags found
No related merge requests found
......@@ -138,112 +138,39 @@ def addTemplates(type,readFile,writeFile,className,packageName,templateList,auto
if aLine.find("%CLASSUPPER%") > -1:
aLine = str.replace(aLine,"%CLASSUPPER%",className.upper())
# 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+"< ")
tmpltype = "<"
tmplparm = "<"
i=0
while i < len(templateList):
if i > 0:
writeFile.write(", ")
writeFile.write(templateList[i])
tmpltype += ", "
tmplparm += ","
tmpltype += "typename " + templateList[i]
tmplparm += 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")
tmpltype += ">"
tmplparm += ">"
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")
# 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("%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")
......@@ -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
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:
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"
......
......@@ -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
......@@ -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.
......
......@@ -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
......@@ -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
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment