Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# debug = open('debug.txt', 'a')
# debug.write('foo\n')
# debug.write('infile [' + cog.inFile + ']\n')
infile = cog.inFile
cppfile = infile.replace('.h','.cpp')
splitinfile = infile.replace('\\','/').split('/')
infilename = splitinfile[ len(splitinfile) - 1 ]
classname = infilename.replace('.h','')
# cog.outl('// classname: ' + classname)
# cog.outl('// cppfile: ' + infilename.replace('.h','.cpp'))
f = open(cppfile, 'r')
in_multiline_comment = False
in_header = False;
line = f.readline()
cog.outl('// generated, using cog:')
while(line != ''):
# cog.outl(line)
if(line.strip().find("/*") >= 0):
in_multiline_comment = True
if(line.strip().find("*/") >= 0):
in_multiline_comment = False
if not in_multiline_comment:
if(in_header or line.find(classname + '::') >= 0 and line.find("(") >= 0 and line.strip().find("//") != 0) and line.find(";") < 0:
in_header = True
fnheader = line.replace('template< typename T >', '').replace(classname + '::', '')
fnheader = fnheader.replace('{', '')
fnheader = fnheader.replace(') :', ')')
if fnheader.find(")") >= 0:
in_header = False
fnheader = fnheader.strip().replace(')', ');')
fnheader = fnheader.strip().replace(';const', 'const;')
def write_kernel3( kernelVarName, kernel_filename, kernelName, options ):
# cog.outl( 'string kernelFilename = "' + kernel_filename + '";' )
cog.outl( '// generated using cog:' )
f = open( kernel_filename, 'r')
line = f.readline()
cog.outl( 'const char * ' + kernelVarName + 'Source = R"DELIM(\n' )
while( line != '' ):
cog.outl( '' + line.rstrip() )
line = f.readline()
cog.outl( ')DELIM";')
f.close()
cog.outl( kernelVarName + ' = cl->buildKernelFromString( ' + kernelVarName + 'Source, "' + kernelName + '", ' + options + ', "' + kernel_filename + '" );' )
# cog.outl(fnheader);
if thisdec != '' and not got_all_header:
thisdec += ' '
thisdec += fnheader + '\n'
if got_all_header:
decs_by_acc[thisaccess].append(thisdec)
thisdec = ''
thisaccess = default_access
line = f.readline()
f.close()
cog.outl('// generated, using cog:')
for accessor in ['public', 'protected', 'private']:
decs = decs_by_acc[accessor]
if len(decs) > 0:
cog.outl('')
cog.outl('{accessor}:'.format(accessor=accessor))
for dec in decs:
cog.out(dec)
cog.outl('')
def go(classname, ints = [], floats = []):
cog.outl( '// generated, using cog:' )
for thisint in ints:
cog.outl('int ' + thisint + ' = 0;')
for thisfloat in floats:
cog.outl('float ' + thisfloat + ' = 0;')
for thisint in ints:
thisintTitlecase = thisint[0].upper() + thisint[1:]
cog.outl(classname + ' ' + thisintTitlecase + '( int ' + '_' + thisint + ' ) {')
cog.outl(' this->' + thisint + ' = _' + thisint + ';')
cog.outl(' return *this;')
cog.outl('}')
for thisfloat in floats:
thisfloatTitlecase = thisfloat[0].upper() + thisfloat[1:]
cog.outl(classname + ' ' + thisfloatTitlecase + '( float ' + '_' + thisfloat + ' ) {')
cog.outl(' this->' + thisfloat + ' = _' + thisfloat + ';')
cog.outl(' return *this;')
cog.outl('}')
def write_kernel( var_name, kernel_filename ):
cog.outl( '// generated using cog, from ' + kernel_filename + ':' )
cog.outl( 'const char * ' + var_name + 'Source = ' )
write_file2( kernel_filename )
cog.outl( '"";')
def write_kernel( var_name, kernel_filename ):
cog.outl( '// generated using cog, from ' + kernel_filename + ':' )
cog.outl( 'const char * ' + var_name + 'Source = ' )
write_file2( kernel_filename )
cog.outl( '"";')
' this->c' + upperFirst(name) +
' = c' + upperFirst(name) + ';')
cog.outl(' }')
cog.outl('')
for thisdef in defs:
(name, returnType, parameters) = thisdef
cog.out(' virtual ' + returnType + ' ' + name + '(')
isFirstParam = True
for param in parameters:
(ptype, pname) = param
if not isFirstParam:
cog.out(', ')
cog.out(ptype + ' ' + pname)
isFirstParam = False
cog.outl(') {')
cog.out(' ')
if returnType != 'void':
cog.out('return ')
cog.out('c' + upperFirst(name) + '(')
for param in parameters:
(ptype, pname) = param
cog.out(pname + ', ')
cog.outl('pyObject);')
cog.outl(' }')
cog.outl('};')
if not isFirst:
cog.out(', ')
cog.out(pname)
isFirst = False
cog.outl(')')
cog.outl('')
cog.outl('cdef class ' + pyx_class + ':')
cog.outl(' cdef ' + pxd_module + '.' + pxd_class + ' *thisptr')
cog.outl(' def __cinit__(self):')
cog.outl(
' self.thisptr = new ' +
pxd_module + '.' + pxd_class + '(self)')
cog.outl('')
for thisdef in defs:
(name, returnType, parameters) = thisdef
cog.outl(
' self.thisptr.set' + upperFirst(name) +
'(' + pyx_class + '_' + name + ')')
cog.outl('')
for thisdef in defs:
(name, returnType, parameters) = thisdef
if name in skip_names:
continue
cog.out(' def ' + name + '(self')
for (ptype, pname) in parameters:
cog.out(', ' + pname)
cog.outl('):')
cog.outl(
' raise Exception("Method needs to be overridden: ' +
pyx_class + '.' + name + '()")')
cog.outl('')
for thisint in ints:
cog.outl('int _' + thisint + ' = 0;')
for thisfloat in floats:
cog.outl('float _' + thisfloat + ' = 0;')
for thisint in ints:
thisintTitlecase = thisint[0].upper() + thisint[1:]
cog.outl(classname + ' ' + thisint + '( int ' + '_' + thisint + ' ) {')
cog.outl(' this->_' + thisint + ' = _' + thisint + ';')
cog.outl(' return *this;')
cog.outl('}')
for thisfloat in floats:
thisfloatTitlecase = thisfloat[0].upper() + thisfloat[1:]
cog.outl(classname + ' ' + thisfloat + '( float ' + '_' + thisfloat + ' ) {')
cog.outl(' this->_' + thisfloat + ' = _' + thisfloat + ';')
cog.outl(' return *this;')
cog.outl('}')