Example #1
0
def generate(module_builder, local_ns, global_ns):
    """
    global_ns: is the module builder for the entire library
    local_ns: is the namespace that coresponds to the given namespace
    """
    local_ns.include()

    # Free function which deals with a std::vector<boost::shared_ptr<T> >
    f = local_ns.free_fun( 'funcVectorShared' )
    AList = declarations.remove_declarated(f.return_type)
    wrap.fix_shared_ptr_vector(AList)
    AList.alias = 'AList'

    # CodeInject Class
    CodeInject = local_ns.class_('CodeInject')

    # Return type only function
    CodeInject.add_declaration_code("""
  int injectedFunc( samples::CodeInject& code ){
      return code.getValue();
  }
    """);
    CodeInject.add_registration_code(
        'def( "injectedFunc", &::injectedFunc )', works_on_instance = True)
                                     
    # Return and set type function
    CodeInject.add_declaration_code("""
    int otherInjectedFunc(samples::CodeInject& code, int value) {
        return code.setValue(value);
    }
    """);
    CodeInject.add_registration_code(
        'def("otherInjectedFunc", (int (*)(samples::CodeInject&, int))(&::otherInjectedFunc))',
        works_on_instance = True)


    # This does not work, because its append with a ".bp..."
    # if it wasn't this would work perfectly
    #CodeInject.add_registration_code(
    #    'bp::implicitly_convertible< int, samples::CodeInject >()')

    wrap.add_needed_includes([CodeInject])
    wrap.set_implicit_conversions([CodeInject], False)

    return ['include/SharedPtrVector.h']
Example #2
0
def generate(module_builder, local_ns, global_ns):
    """
    global_ns: is the module builder for the entire library
    local_ns: is the namespace that coresponds to the given namespace
    """
    local_ns.include()

    # Free function which deals with a std::vector<boost::shared_ptr<T> >
    f = local_ns.free_fun('funcVectorShared')
    AList = declarations.remove_declarated(f.return_type)
    wrap.fix_shared_ptr_vector(AList)
    AList.alias = 'AList'

    # CodeInject Class
    CodeInject = local_ns.class_('CodeInject')

    # Return type only function
    CodeInject.add_declaration_code("""
  int injectedFunc( samples::CodeInject& code ){
      return code.getValue();
  }
    """)
    CodeInject.add_registration_code('def( "injectedFunc", &::injectedFunc )',
                                     works_on_instance=True)

    # Return and set type function
    CodeInject.add_declaration_code("""
    int otherInjectedFunc(samples::CodeInject& code, int value) {
        return code.setValue(value);
    }
    """)
    CodeInject.add_registration_code(
        'def("otherInjectedFunc", (int (*)(samples::CodeInject&, int))(&::otherInjectedFunc))',
        works_on_instance=True)

    # This does not work, because its append with a ".bp..."
    # if it wasn't this would work perfectly
    #CodeInject.add_registration_code(
    #    'bp::implicitly_convertible< int, samples::CodeInject >()')

    wrap.add_needed_includes([CodeInject])
    wrap.set_implicit_conversions([CodeInject], False)

    return ['include/SharedPtrVector.h']
Example #3
0
def generate(module_builder, local_ns, global_ns):
    """
    global_ns: is the module builder for the entire library
    local_ns: is the namespace that coresponds to the given namespace
    """
    classes = []

    # Find all the classes to wrap
    Radian = local_ns.class_('Radian')
    Degree = local_ns.class_('Degree')
    Vector2 = local_ns.class_('Vector2')
    Vector3 = local_ns.class_('Vector3')
    Quaternion = local_ns.class_('Quaternion')
    Matrix2 = local_ns.class_('Matrix2')
    Matrix3 = local_ns.class_('Matrix3')

    # Include them
    Radian.include()
    Degree.include()
    Vector2.include()
    Vector3.include()
    Quaternion.include()
    Matrix2.include()
    Matrix3.include()

    classes.extend(
        [Radian, Degree, Vector2, Vector3, Quaternion, Matrix2, Matrix3])

    # Map operator<< to __str__
    wrap.str_from_ostream(local_ns)

    # Fix '[]' operators on matrices
    c = Matrix2.operators('[]')
    c.call_policies= call_policies.convert_array_to_tuple(2, \
        call_policies.memory_managers.none)
    c.include()
    c.documentation = wrap.docit("Return Type Change", "None",
                                 "Tuple with 2 floats's (the matrix 'line')")

    c = Matrix3.operators('[]')
    c.call_policies= call_policies.convert_array_to_tuple(3, \
        call_policies.memory_managers.none)
    c.include()
    c.documentation = wrap.docit("Return Type Change", "None",
                                 "Tuple with 3 floats's (the matrix 'line')")

    # Handle the 'ptr' functions
    wrap.fix_pointer_returns([Vector2, Vector3, Quaternion, Matrix2, Matrix3],
                             ignore_names=['ptr'])
    wrap.fix_pointer_args([Vector2, Vector3, Quaternion, Matrix2, Matrix3])

    # Remove float -> Radian/Degree implicit conversions
    Degree.constructor(arg_types=['double']).allow_implicit_conversion = False
    Radian.constructor(arg_types=['double']).allow_implicit_conversion = False

    # Wrap Events
    events = wrap.expose_events(local_ns)

    if events:
        module_builder.class_('::ram::core::Event').already_exposed = True
        classes += events

    # Append the approaite include files
    wrap.add_needed_includes(classes)
    Quaternion.include_files.append(Matrix3.location.file_name)

    # Remove implicit conversions
    wrap.set_implicit_conversions(
        [Vector2, Vector3, Quaternion, Matrix2, Matrix3], False)

    include_files = set([cls.location.file_name for cls in classes])
    for cls in classes:
        include_files.update(cls.include_files)
    return ['math/include/Math.h'] + list(include_files)
Example #4
0
def generate(module_builder, local_ns, global_ns):
    """
    global_ns: is the module builder for the entire library
    local_ns: is the namespace that coresponds to the given namespace
    """
    classes = []

    # Find all the classes to wrap
    Radian = local_ns.class_('Radian')
    Degree = local_ns.class_('Degree')
    Vector2 = local_ns.class_('Vector2')
    Vector3 = local_ns.class_('Vector3')
    Quaternion = local_ns.class_('Quaternion')
    Matrix2 = local_ns.class_('Matrix2')
    Matrix3 = local_ns.class_('Matrix3')

    # Include them
    Radian.include()
    Degree.include()
    Vector2.include()
    Vector3.include()
    Quaternion.include()
    Matrix2.include()
    Matrix3.include()

    classes.extend([Radian, Degree, Vector2, Vector3, Quaternion, Matrix2,
                    Matrix3])

    # Map operator<< to __str__
    wrap.str_from_ostream(local_ns)

    # Fix '[]' operators on matrices
    c = Matrix2.operators('[]')
    c.call_policies= call_policies.convert_array_to_tuple(2, \
        call_policies.memory_managers.none)
    c.include()
    c.documentation = wrap.docit("Return Type Change", "None",
                                 "Tuple with 2 floats's (the matrix 'line')")
    
    c = Matrix3.operators('[]')
    c.call_policies= call_policies.convert_array_to_tuple(3, \
        call_policies.memory_managers.none)
    c.include()
    c.documentation = wrap.docit("Return Type Change", "None",
                                 "Tuple with 3 floats's (the matrix 'line')")

    # Handle the 'ptr' functions
    wrap.fix_pointer_returns([Vector2, Vector3, Quaternion, Matrix2, Matrix3],
                             ignore_names = ['ptr'])
    wrap.fix_pointer_args([Vector2, Vector3, Quaternion, Matrix2, Matrix3])

    # Remove float -> Radian/Degree implicit conversions
    Degree.constructor(arg_types = ['double']).allow_implicit_conversion = False
    Radian.constructor(arg_types = ['double']).allow_implicit_conversion = False

    # Wrap Events
    events = wrap.expose_events(local_ns)

    if events:
        module_builder.class_('::ram::core::Event').already_exposed = True
        classes += events

    # Append the approaite include files
    wrap.add_needed_includes(classes)
    Quaternion.include_files.append(Matrix3.location.file_name)
    
    # Remove implicit conversions
    wrap.set_implicit_conversions([Vector2, Vector3, Quaternion, Matrix2,
                                   Matrix3], False)

    include_files = set([cls.location.file_name for cls in classes])
    for cls in classes:
        include_files.update(cls.include_files)
    return ['math/include/Math.h'] + list(include_files)
Example #5
0
def generate(module_builder, local_ns, global_ns):
    """
    local_ns: is the namespace that coresponds to the given namespace
    global_ns: is the module builder for the entire library
    """

    local_ns.exclude()
    classes = []

    # ConfigNode
    ConfigNode = local_ns.class_('ConfigNode')
    ConfigNode.include()
    ConfigNode.constructors().exclude()
    classes.append(ConfigNode)

    # Event Subsystem
    EventPublisher = expose_publisher(local_ns, 'EventPublisher')
    EventPublisher.include_files.append('core/include/EventHub.h')

    # Apply return value policy
    lookupByName = EventPublisher.member_function('lookupByName')
    lookupByName.call_policies = \
        mod_builder.call_policies.return_value_policy(
            mod_builder.call_policies.manage_new_object)
    classes.append(EventPublisher)

    QueuedEventPublisher = expose_publisher(local_ns, 'QueuedEventPublisher')
    classes.append(QueuedEventPublisher)

    # EventConnection
    EventConnection = local_ns.class_('EventConnection')
    EventConnection.include()
    EventConnection.include_files.append('core/include/EventConnection.h')
    classes.append(EventConnection)

    # IUpdatable
    IUpdatable = local_ns.class_('IUpdatable')
    IUpdatable.include()
    classes.append(IUpdatable)

    # Application
    Application = local_ns.class_('Application')
    Application.include()

    # Replace getSubsystem with one which uses our converter
    Application.member_function('getSubsystem').exclude()
    Application.add_declaration_code("""
    boost::python::object pyGetSubsystem(ram::core::Application& app,
                                         std::string subsystemName)
    {
        ram::core::SubsystemPtr subsystem = app.getSubsystem(subsystemName);
        return ram::core::SubsystemConverter::convertObject(subsystem);
    }
    """)
    Application.add_registration_code('def("getSubsystem", &::pyGetSubsystem)',
                                      works_on_instance=True)
    Application.include_files.append('core/include/SubsystemConverter.h')

    classes.append(Application)

    # Wrap Events
    Event = local_ns.class_('Event')
    Event.include()
    classes.append(Event)

    def filterFunc(val):
        return val.name.endswith('Event') and val.name != 'Event'

    events = wrap.expose_events(local_ns, filter_func=filterFunc)
    classes += events

    # Add registrations functions for hand wrapped classes
    module_builder.add_registration_code("registerSubsystemList();")
    module_builder.add_registration_code("registerSubsystemClass();")
    module_builder.add_registration_code("registerSubsystemMakerClass();")
    module_builder.add_registration_code("registerEventHubClass();")
    module_builder.add_registration_code("registerQueuedEventHubClass();")

    # Do class wide items
    wrap.set_implicit_conversions(
        [Application, QueuedEventPublisher, EventPublisher], False)
    wrap.add_needed_includes(classes)

    include_files = set([cls.location.file_name for cls in classes])
    for cls in classes:
        include_files.update(cls.include_files)
    return ['wrappers/core/include/RegisterFunctions.h'] + list(include_files)
Example #6
0
def generate(module_builder, local_ns, global_ns):
    """
    global_ns: is the module builder for the entire library
    local_ns: is the namespace that coresponds to the given namespace
    """
    global_ns.exclude()
    classes = []

    # Lets Py++ know to make VisionSystem a subclass of Subsystem
    module_builder.class_('::ram::core::Subsystem').already_exposed = True
    module_builder.class_('::ram::core::Event').already_exposed = True

    # Vision System
    VisionSystem = local_ns.class_('VisionSystem')
    VisionSystem.include()
    VisionSystem.include_files.append('vision/include/Camera.h')
    classes.append(VisionSystem)   

    # Wrap Events
    EventType = local_ns.class_('EventType')
    EventType.include()
    classes.append(EventType)

    Symbol = local_ns.class_('Symbol')
    Symbol.include()
    Symbol.member_function('getSymbolNames').exclude()
    Symbol.member_function('symbolToText').exclude()
    classes.append(Symbol)

    Color = local_ns.class_('Color')
    Color.include()
    Color.member_function('getColorNames').exclude()
    Color.member_function('colorToText').exclude()
    classes.append(Color)
    
    events = wrap.expose_events(local_ns)
    classes += events

    ImageEvent = local_ns.class_('ImageEvent')
    ImageEvent.include_files.append('vision/include/Image.h')
    wrap.set_implicit_conversions([ImageEvent], False)

    BinEvent = local_ns.class_('BinEvent')
    wrap.set_implicit_conversions([BinEvent], False)

    if events:
        wrap.make_already_exposed(global_ns, 'ram::core', ['Event'])
        classes += events

    # Append the approaite include files
#    for cls in classes:
#        cls.include()
    wrap.add_needed_includes(classes)

    module_builder.add_registration_code("registerImageClass();")
    module_builder.add_registration_code("registerCameraClass();")

    include_files = set([cls.location.file_name for cls in classes])
    for cls in classes:
        include_files.update(cls.include_files)
    return ['wrappers/vision/include/RegisterFunctions.h'] + list(include_files)
Example #7
0
def generate(module_builder, local_ns, global_ns):
    """
    local_ns: is the namespace that coresponds to the given namespace
    global_ns: is the module builder for the entire library
    """

    local_ns.exclude()
    classes = []

    # ConfigNode
    ConfigNode = local_ns.class_('ConfigNode')
    ConfigNode.include()
    ConfigNode.constructors().exclude()
    classes.append(ConfigNode)

    # Event Subsystem
    EventPublisher = expose_publisher(local_ns, 'EventPublisher')    
    EventPublisher.include_files.append('core/include/EventHub.h')

    # Apply return value policy
    lookupByName = EventPublisher.member_function('lookupByName')
    lookupByName.call_policies = \
        mod_builder.call_policies.return_value_policy(
            mod_builder.call_policies.manage_new_object)
    classes.append(EventPublisher)

    QueuedEventPublisher = expose_publisher(local_ns, 'QueuedEventPublisher')
    classes.append(QueuedEventPublisher)

    # EventConnection
    EventConnection = local_ns.class_('EventConnection')
    EventConnection.include()
    EventConnection.include_files.append('core/include/EventConnection.h')
    classes.append(EventConnection)

    # IUpdatable
    IUpdatable = local_ns.class_('IUpdatable')
    IUpdatable.include()
    classes.append(IUpdatable)

    # Application
    Application = local_ns.class_('Application')
    Application.include()

    # Replace getSubsystem with one which uses our converter
    Application.member_function('getSubsystem').exclude()
    Application.add_declaration_code("""
    boost::python::object pyGetSubsystem(ram::core::Application& app,
                                         std::string subsystemName)
    {
        ram::core::SubsystemPtr subsystem = app.getSubsystem(subsystemName);
        return ram::core::SubsystemConverter::convertObject(subsystem);
    }
    """)
    Application.add_registration_code(
        'def("getSubsystem", &::pyGetSubsystem)', works_on_instance = True )
    Application.include_files.append('core/include/SubsystemConverter.h')
    
    classes.append(Application)

    # Wrap Events
    Event = local_ns.class_('Event')
    Event.include()
    classes.append(Event)

    def filterFunc(val):
        return val.name.endswith('Event') and val.name != 'Event'
    events = wrap.expose_events(local_ns, filter_func = filterFunc)
    classes += events

    # Add registrations functions for hand wrapped classes
    module_builder.add_registration_code("registerSubsystemList();")
    module_builder.add_registration_code("registerSubsystemClass();")
    module_builder.add_registration_code("registerSubsystemMakerClass();")
    module_builder.add_registration_code("registerEventHubClass();")
    module_builder.add_registration_code("registerQueuedEventHubClass();")


    # Do class wide items
    wrap.set_implicit_conversions([Application, QueuedEventPublisher,
                                   EventPublisher], False)
    wrap.add_needed_includes(classes)

    include_files = set([cls.location.file_name for cls in classes])
    for cls in classes:
        include_files.update(cls.include_files)
    return ['wrappers/core/include/RegisterFunctions.h'] + list(include_files)