[C++-sig] pygccxml not picking up optional parameters in std::vector constructor

Nindi Singh nindi73 at yahoo.co.uk
Fri Dec 28 20:52:19 CET 2007



----- Original Message ----
> From: Nindi Singh <nindi73 at yahoo.co.uk>
> To: c++-sig at python.org
> Sent: Friday, 28 December, 2007 6:35:01 PM
> Subject: Re: [C++-sig] pygccxml not picking up optional parameters in std::vector constructor
> 
> Roman,
> The output from gccxml -v is :
> __________________________________________________
> #include wrapper search starts here:
>  /usr/share/gccxml-0.7/GCC/4.1
> #include "..." search starts here:
> #include <...> search starts here:
>  /usr/include/c++/4.1.3
>  /usr/include/c++/4.1.3/x86_64-linux-gnu
>  /usr/include/c++/4.1.3/backward
>  /usr/local/include
>  /usr/lib/gcc/x86_64-linux-gnu/4.1.3/include
>  /usr/include
> End of search list.
> __________________________________________________
> 
> The header file example.hpp is
> _________________________________________________
> #ifndef TESTVECTOR
> #define TESTVECTOR
> #include
> template std::vector;
> #endif
> ________________________________________________
> 
> The pygccxml script is 
> ________________________________________________
> import sys
> from pygccxml import parser
> from pygccxml import declarations
> from pygccxml.declarations import templates
> from pygccxml.declarations import type_traits 
> 
> decls = parser.parse( ['example.hpp'])#, config )
> global_ns = declarations.get_global_namespace( decls )
> 
> query = declarations.custom_matcher_t (lambda vec
> :
> 
 templates.name(vec.name)=='vector')
> vectorClass = global_ns.classes(function=query)
> 
> def processArgument(arg):
>     if type_traits.is_const(arg):
>         return 'const
> '+processArgument(type_traits.remove_const(arg))
> 
 + ' '
>     if type_traits.is_reference(arg):
>         return processArgument(type_traits.remove_reference(arg)) 
> +
> 
 '&'
>     if type_traits.is_pointer(arg):
>         return processArgument(type_traits.remove_pointer(arg))   + '*'
>     if type_traits.is_fundamental(arg):
>         return  str(arg)
>     if type_traits.is_class(arg):
>                 theType = type_traits.remove_declarated(arg)
>         return theType.demangled  
>     if type_traits.is_class_declaration(arg):
>                 theType = type_traits.remove_declarated(arg)
>         return theType.demangled  
> 
> for class_ in vectorClass:
>     theConstructors =  class_.constructors()
>     for c in theConstructors:
>         print '\n\n'
>         print 'name         :',c.demangled
>         print 'location     :',c.location.file_name
>         if len(c.required_args)==0:
>           print 'No required args'
>         else :
>           print 'required args:'
>           for a in c.required_args:
>             print ' ',processArgument(a.type)
>         if len(c.optional_args)==0:
>           print 'No optional args'
>         else :
>           print 'optional args:'
>           for a in c.optional_args:
>             print ' ',processArgument(a.type)
> ______________________________________________________________________
> INFO Parsing source file "example.hpp" ... 
> 
> INFO gccxml cmd: /usr/bin/gccxml  -I"."  
> "example.hpp"
> 
 -fxml="/tmp/tmpJvYj92.xml"
> 
> name         : std::vector
> std::allocator
> 
 >::vector(std::allocator const&)
> location     : /usr/include/c++/4.1.3/bits/stl_vector.h
> required args:
>   const std::allocator &
> No optional args
> 
> name         : std::vector
> std::allocator
> 
 >::vector(unsigned long, double const&, std::allocator const&)
> location     : /usr/include/c++/4.1.3/bits/stl_vector.h
> required args:
>   size_t
>   const double &
>   const std::allocator &
> No optional args
> 
> name         : std::vector
> std::allocator
> 
 >::vector(std::vector > const&)
> location     : /usr/include/c++/4.1.3/bits/stl_vector.h
> required args:
>   const std::vector > &
> No optional args
> The output from this script is 
> ____________________________________________________
> 
> In /usr/include/c++/4.1.3/bits/stl_vector.h
> 
> line 202        : vector(const allocator_type& __a = allocator_type())
> line 214-215  : vector(size_type __n, const value_type& __value
> =
> 
 value_type(),
>                      const allocator_type& __a = allocator_type())
> line 232        : vector(const vector& __x)
> 
> I just cannot figure out why the optional parameters ( allocator )
> do
> 
 not show up as optional
> 
> 

Ok, I have the much more simplified header file, with similar problem. In this header file I use my own class instead of std::vector

____________________________________________________________________
#ifndef TESTVECTOR
#define TESTVECTOR


template<class T>
class myAlloc{
  typedef T type;
};

template <class T, class  Alloc=myAlloc<T>  >
class vector {
  typedef Alloc alloc;
  vector(const alloc & a = alloc()){}
  vector(unsigned long , const alloc & a =alloc()){}
};


template vector<double>;

#endif
__________________________________________________________________________















 




      __________________________________________________________
Sent from Yahoo! Mail - a smarter inbox http://uk.mail.yahoo.com




More information about the Cplusplus-sig mailing list