How to use cog - 10 common examples

To help you get started, we’ve selected a few cog examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hughperkins / DeepCL / cog-batteries / cog_addheaders.py View on Github external
#    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;')
github hughperkins / DeepCL / cog-batteries / cog_addheaders.py View on Github external
def add_templated():
#    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):
github hughperkins / DeepCL / cog-batteries / cog_addheaders.py View on Github external
def add(classname=''):
#    debug = open('debug.txt', 'a')
#    debug.write('foo\n')
#    debug.write('infile [' + cog.inFile + ']\n')

    infile = cog.inFile
    splitinfile = infile.replace('\\','/').split('/')
    infilename = splitinfile[ len(splitinfile) - 1 ]
    if classname == '':
        classname = infilename.replace('.h','')
    cppfile = infile.replace('.h','.cpp')
    # 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
github hughperkins / DeepCL / cog-batteries / stringify.py View on Github external
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 + '" );' )
github hughperkins / DeepCL / cog-batteries / cog_addheaders.py View on Github external
# 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('')
github hughperkins / DeepCL / cog-batteries / cog_fluent.py View on Github external
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('}')
github hughperkins / EasyCL / cog-batteries / stringify.py View on Github external
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( '"";')
github hughperkins / DeepCL / cog-batteries / stringify.py View on Github external
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( '"";')
github jgarvin / Cogflect / cog-recipes / cogflect / Enum.py View on Github external
"    // it to be a function using the 'constexpr' keyword.\n")
        cog.out("    static const unsigned size = %d;\n\n" % len(self.fields))

        cog.out("};\n\n") # close class

        for f in self.fields:
            cog.out("template<>\n"
                    "struct type::info_with_hash<%du>\n"
                    "{\n"
                    "    typedef %s_INFO type;\n"
                    "};\n\n" % (self.__get_name_hash(f.name), f.name))

        cog.out("namespace {\n\n")
        for f in self.fields:
            cog.out("const type %s(type::make_from_info<%s_INFO>());\n" % (f.name, f.name))
        cog.out("\n}\n\n") # close anonymous namespace

        cog.out("}\n") # close enum namespace
github fabioz / LiClipseText / plugins / org.brainwy.liclipsetext.editor / install.py View on Github external
with file(plugin_file, 'r') as f:
        for line in f.readlines():
            if line.strip().startswith('EDITORS_LST = '):
                found = True
                line = '    EDITORS_LST = %s\n' % (lst,)
            new_lines.append(line)
    assert found
    with file(plugin_file, 'w') as f:
        f.write(''.join(new_lines))

    cog.RunCogInFiles([plugin_file])
    cog.RunCogInFiles([
        os.path.join(parent_dir, 'src', 'org', 'brainwy', 'liclipsetext', 'editor', 'common',
            'partitioning', 'rules', 'RulesFactory.java')])
    cog.RunCogInFiles([os.path.join(parent_dir, 'languages', 'html.liclipse')])
    cog.RunCogInFiles([os.path.join(parent_dir, 'languages', 'dart.liclipse')])


    base_compare = os.path.join(parent_dir, 'src', 'org', 'brainwy', 'liclipsetext', 'editor', 'compare')


    for x in lst:
        x['kind_upper'] = x['kind'].title().replace(' ', '').replace('.', '')

        template = '''// Automatically Generated in install.py
package org.brainwy.liclipsetext.editor.compare;

public class %(kind_upper)sContentViewerCreator extends AbstractContentViewerCreator {

    public %(kind_upper)sContentViewerCreator() {
        super("%(kind)s");
    }