How to use the pygccxml.declarations.templates.split function in pygccxml

To help you get started, we’ve selected a few pygccxml 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 gccxml / pygccxml / unittests / test_pattern_parser.py View on Github external
self.assertEqual(args, l)

            l = [p1, p2]
            name, args = declarations.templates.split(
                "myClass0b<" + ", ".join(l) + ">")
            self.assertEqual(name, "myClass0b")
            self.assertEqual(args, l)

            l = [p1, p2, p2]
            name, args = declarations.templates.split(
                "myClass0c<" + ", ".join(l) + ">")
            self.assertEqual(name, "myClass0c")
            self.assertEqual(args, l)

            l = [p1 + " (" + arg + ")"]
            name, args = declarations.templates.split(
                "myClass1<" + ", ".join(l) + ">")
            self.assertEqual(name, "myClass1")
            self.assertEqual(args, l)

            l = [p1 + " (" + arg + ", " + arg + ")"]
            name, args = declarations.templates.split(
                "myClass2<" + ", ".join(l) + ">")
            self.assertEqual(name, "myClass2")
            self.assertEqual(args, l)

            l = [p2 + " (" + arg + ", " + arg + ")"]
            name, args = declarations.templates.split(
                "myClass3<" + ", ".join(l) + ">")
            self.assertEqual(name, "myClass3")
            self.assertEqual(args, l)
github tkn-tub / ns3-gym / bindings / python / ns3modulescan-modular.py View on Github external
## classes
        if isinstance(pygccxml_definition, class_t):
            print >> sys.stderr, pygccxml_definition
            # no need for helper classes to allow subclassing in Python, I think...
            #if pygccxml_definition.name.endswith('Helper'):
            #    global_annotations['allow_subclassing'] = 'false'

            #
            # If a class is template instantiation, even if the
            # template was defined in some other module, if a template
            # argument belongs to this module then the template
            # instantiation will belong to this module.
            # 
            if templates.is_instantiation(pygccxml_definition.decl_string):
                cls_name, template_parameters = templates.split(pygccxml_definition.name)
                template_parameters_decls = [find_declaration_from_name(module_parser.global_ns, templ_param)
                                             for templ_param in template_parameters]
                #print >> sys.stderr, "********************", cls_name, repr(template_parameters_decls)
                
                template_parameters_modules = []
                for templ in template_parameters_decls:
                    if not hasattr(templ, 'location'):
                        continue
                    try:
                        h = get_ns3_relative_path(templ.location.file_name)
                    except ValueError:
                        continue
                    template_parameters_modules.append(self.headers_map[h])

                for templ_mod in template_parameters_modules:
                    if templ_mod == self.module:
github gccxml / pygccxml / pygccxml / declarations / class_declaration.py View on Github external
def get_partial_name(name):
    from . import container_traits  # prevent cyclic dependencies
    ct = container_traits.find_container_traits(name)

    if ct:
        return ct.remove_defaults(name)

    if templates.is_instantiation(name):
        tmpl_name, args = templates.split(name)
        for i, arg_name in enumerate(args):
            args[i] = get_partial_name(arg_name.strip())
        return templates.join(tmpl_name, args)

    return name
github InsightSoftwareConsortium / ITK / pygccxml / declarations / container_traits.py View on Github external
def erase_hash_allocator(cls_name):
        cls_name = defaults_eraser.replace_basic_string(cls_name)
        c_name, c_args = templates.split(cls_name)
        if len(c_args) < 3:
            return

        default_hash = None
        default_less = 'std::less'
        default_equal_to = 'std::equal_to'
        default_allocator = 'std::allocator'

        tmpl = None
        if 3 == len(c_args):
            default_hash = 'hash_compare'
            tmpl = (
                "$container< $value_type, $hash<$value_type, " +
                "$less<$value_type> >, $allocator<$value_type> >")
        elif 4 == len(c_args):
            default_hash = 'hash'
github gjcarneiro / pybindgen / pybindgen / castxmlparser.py View on Github external
postpone_class(cls, ("waiting for implicit conversion target class %s to be registered first"
                                     % (operator.return_type.partial_decl_string,)))
                continue

            is_exception = self._apply_class_annotations(cls, global_annotations, kwargs)

            timings.append(time.time())

            custom_template_class_name = None
            template_parameters = ()
            if typedef is None:
                alias = None
                isinst = templates.is_instantiation(cls.decl_string)
                timings.append(time.time())
                if isinst:
                    cls_name, template_parameters = templates.split(cls.name)
                    assert template_parameters
                    if '::' in cls_name:
                        cls_name = cls_name.split('::')[-1]
                    template_instance_names = global_annotations.get('template_instance_names', '')
                    if template_instance_names:
                        for mapping in template_instance_names.split('|'):
                            type_names, name = mapping.split('=>')
                            instance_types = type_names.split(',')
                            if instance_types == template_parameters:
                                custom_template_class_name = name
                                break
                else:
                    cls_name = cls.name
            else:
                timings.append(time.time())
                cls_name = typedef.name
github InsightSoftwareConsortium / ITK / pygccxml / declarations / container_traits.py View on Github external
def erase_map_compare_allocator(
            cls_name,
            default_compare='std::less',
            default_allocator='std::allocator'):
        cls_name = defaults_eraser.replace_basic_string(cls_name)
        c_name, c_args = templates.split(cls_name)
        if 4 != len(c_args):
            return
        key_type = c_args[0]
        mapped_type = c_args[1]
        tmpls = [
            string.Template(
                "$container< $key_type, $mapped_type, $compare<$key_type>, " +
                "$allocator< std::pair< const $key_type, $mapped_type> > >"),
            string.Template(
                "$container< $key_type, $mapped_type, $compare<$key_type>, " +
                "$allocator< std::pair< $key_type const, $mapped_type> > >"),
            string.Template(
                "$container< $key_type, $mapped_type, $compare<$key_type>, " +
                "$allocator< std::pair< $key_type, $mapped_type> > >")]
        for tmpl in tmpls:
            tmpl = tmpl.substitute(
github tkn-tub / ns3-gym / bindings / python / ns3modulescan-modular.py View on Github external
def scan_callback_classes(module_parser, callback_classes_file):
    callback_classes_file.write("callback_classes = [\n")
    for cls in module_parser.module_namespace.classes(function=module_parser.location_filter,
                                                      recursive=False):
        if not cls.name.startswith("Callback<"):
            continue
        assert templates.is_instantiation(cls.decl_string), "%s is not a template instantiation" % cls
        dummy_cls_name, template_parameters = templates.split(cls.decl_string)
        callback_classes_file.write("    %r,\n" % template_parameters)
    callback_classes_file.write("]\n")
github InsightSoftwareConsortium / ITK / pygccxml / declarations / container_traits.py View on Github external
def erase_allocator(cls_name, default_allocator='std::allocator'):
        cls_name = defaults_eraser.replace_basic_string(cls_name)
        c_name, c_args = templates.split(cls_name)
        if 2 != len(c_args):
            return
        value_type = c_args[0]
        tmpl = string.Template(
            "$container< $value_type, $allocator<$value_type> >")
        tmpl = tmpl.substitute(
            container=c_name,
            value_type=value_type,
            allocator=default_allocator)
        if defaults_eraser.normalize(cls_name) == \
                defaults_eraser.normalize(tmpl):
            return templates.join(
                c_name, [defaults_eraser.erase_recursive(value_type)])
github Gabrielcarvfer / NS3 / bindings / python / ns3modulescan-modular.py View on Github external
## classes
        if isinstance(pygccxml_definition, class_t):
            print(pygccxml_definition, file=sys.stderr)
            # no need for helper classes to allow subclassing in Python, I think...
            #if pygccxml_definition.name.endswith('Helper'):
            #    global_annotations['allow_subclassing'] = 'false'

            #
            # If a class is template instantiation, even if the
            # template was defined in some other module, if a template
            # argument belongs to this module then the template
            # instantiation will belong to this module.
            # 
            if templates.is_instantiation(pygccxml_definition.decl_string):
                cls_name, template_parameters = templates.split(pygccxml_definition.name)
                template_parameters_decls = [find_declaration_from_name(module_parser.global_ns, templ_param)
                                             for templ_param in template_parameters]
                #print >> sys.stderr, "********************", cls_name, repr(template_parameters_decls)
                
                template_parameters_modules = []
                for templ in template_parameters_decls:
                    if not hasattr(templ, 'location'):
                        continue
                    try:
                        h = get_ns3_relative_path(templ.location.file_name)
                    except ValueError:
                        continue
                    template_parameters_modules.append(self.headers_map[h])

                for templ_mod in template_parameters_modules:
                    if templ_mod == self.module: