[C++-sig] pyste suggestion: easier overriding of exporters
Nicodemus
nicodemus at globalite.com.br
Sat Oct 18 00:20:22 CEST 2003
Hi Scott,
scott snyder wrote:
>hi -
>
>In the course of playing with pyste, i've made numerous minor
>fixes and extensions. In such cases, i'd like to be able to keep
>my new code in the .pyste file (or something imported from there)
>rather than having to change the pyste code itself.
>
>One way of extending pyste is to use one's own Exporter classes.
>In most cases, these can derive from the existing ones, modifying
>any needed behaviors.
>
>There is, however, no clean way to specify in a .pyste file that you
>want to use a custom exporter class. In the past, i've done this
>by duplicating the classes that derive from DeclarationInfo and
>changing the Exporter class, i.e., doing something like this:
>
>class Class (DeclarationInfo):
> def __init__(self, name, include, tail=None, otherInfo=None):
> DeclarationInfo.__init__(self, otherInfo)
> self._Attribute('name', name)
> self._Attribute('include', include)
> self._Attribute('exclude', False)
> # create a ClassExporter
> exporter = My_Class_Exporter(InfoWrapper(self), tail)
> exporters.exporters.append(exporter)
> exporter.interface_file = exporters.current_interface
>
>and then importing this into the pyste file.
>
>This is not entirely satisfactory, due to the pyste code that must
>be duplicated here. One also runs into a problem with ClassExporter,
>as its ExportNestedClasses method also has a reference to
>`ClassExporter' literally coded.
>
>I would suggest allowing for such extensions by adding an (optional)
>argument to the constructors of the info classes giving the class
>to use for the exporter. Thus, if someone wants to use a non-standard
>exporter for a particular declaration, it can just be specified
>in the Class() or whatever call. Then if i want all classes to use
>my custom exporter, i can do something like this:
>
>def Class (name, include, tail=None, otherInfo=None):
> return ClassInfo (name, include, tail, otherInfo,
> exporter_class = My_Class_Exporter)
>
>avoiding having to duplicate the code from ClassInfo.
>
>The patches below implement this.
>I added an optional parameter `exporter_class' to the info class
>constructors, giving the class to use for the exporter. I also
>modified ClassExporter.ExportNestedClasses to create the nested
>class exporters using the same class as the current exporter,
>rather than hardwiring in ClassExporter.
>
>
(Sorry about the delay in responding)
Thanks a lot for your patch, it has been applied! Thanks again.
><snip patch>
>
>
Regards,
Nicodemus.
More information about the Cplusplus-sig
mailing list