<commit_before># Copyright <NAME> 2015 hughperkins at gmail
#
# This Source Code Form is subject to the terms of the Mozilla Public License, 
# v. 2.0. If a copy of the MPL was not distributed with this file, You can 
# obtain one at http://mozilla.org/MPL/2.0/.

# functions to help wrap C++ callback classes in Cython, and more

import cog

def upperFirst( word ):
    """helper method to capitalize the first letter of word"""
    word = word[0].upper() + word[1:]
    return word

def cpp_write_proxy_class( proxy_name, parent_name, defs ):
    """use to create a c++ class that inherits from a (possibly abstract) c++ class
    and handles the c++ side of receiving callback functions into cython,
    and calling these appropriately"""

    cog.outl('// generated using cog (as far as the [[end]] bit:')
    cog.outl( 'class ' + proxy_name + ' : public ' + parent_name + ' {' )
    cog.outl( 'public:')
    cog.outl( '    void *pyObject;')
    cog.outl( '')
    cog.outl( '    CyScenario(void *pyObject) :')
    cog.outl( '        pyObject(pyObject) {')
    cog.outl( '    }')
    cog.outl( '')

    for thisdef in defs:<commit_msg>add more doc to cog_cython.py<commit_after># Copyright <NAME> 2015 hughperkins at gmail
#
# This Source Code Form is subject to the terms of the Mozilla Public License, 
# v. 2.0. If a copy of the MPL was not distributed with this file, You can 
# obtain one at http://mozilla.org/MPL/2.0/.

# functions to help wrap C++ callback classes in Cython, and more
# There are three parts to wrapping C++ callback classes:
#
# - in C++, you need to override the C++-side abstract class
#   => cpp_write_proxy_class
#
# - in the pxd, you need to declare the C++ proxy class
#   => pxd_write_proxy_class
#
# - in the .pyx, you need to write a wrapper class, that can be 
#   overridden in the python files
#   => pyx_write_overrideable_class

import cog

def upperFirst( word ):
    """helper method to capitalize the first letter of word"""
    word = word[0].upper() + word[1:]
    return word

def cpp_write_proxy_class( proxy_name, parent_name, defs ):
    """use to create a c++ class that inherits from a (possibly abstract) c++ class
    and handles the c++ side of receiving callback functions into cython,
    and calling these appropriately"""

    cog.outl('// generated using cog (as far as the [[end]] bit:')
    cog.outl( 'class ' + proxy_name + ' : public ' + parent_name + ' {' )
    cog.outl( 'public:')
    cog.outl( '    void *pyObject;')
    cog.outl( '')
    cog.outl( '    CyScenario(void *pyObject) :')
    cog.outl( '        pyObject(pyObject) {')
    cog.outl( '    }')
    cog.outl( '')

    for thisdef in defs:
{'fraction_non_alphanumeric': 0.11998500187476566, 'fraction_numerical': 0.0074990626171728535, 'mean_word_length': 3.16875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4079216', 'n_tokens_mistral': 903, 'n_tokens_neox': 875, 'n_words': 328}