pygccxml.declarations.namespace

Package pygccxml :: Package declarations :: Module namespace |

# Source Code for Module pygccxml.declarations.namespace

      1  # Copyright 2004-2008 Roman Yakovenko.
      2  # Distributed under the Boost Software License, Version 1.0. (See
      3  # accompanying file LICENSE_1_0.txt or copy at
      4  # http://www.boost.org/LICENSE_1_0.txt)
      5
      6  """defines class, that describes C++ namespace declaration"""
      7
      8  import declaration
      9  import scopedef
     10  import algorithm
     11
     12 -class namespace_t( scopedef.scopedef_t ):
     13      """
     14      describes C++ namespace
     15      """
     16
     17 -    def __init__( self, name='', declarations=None ):
     18          """creates class that describes C++ namespace declaration"""
     19          scopedef.scopedef_t.__init__( self, name )
     20          if not declarations:
     21              declarations = []
     22          self._declarations = declarations # list of all declarations belongs to this namespace
     23
     24 -    def __str__(self):
     25          name = algorithm.full_name(self)
     26          if name!="::" and name[:2]=="::":
     27              name = name[2:]
     28          return "%s [namespace]"%name
     29
     30 -    def _get__cmp__scope_items(self):
     31          """implementation details"""
     32          return [ self._sorted_list( self.declarations ) ]
     33
     34 -    def _get_declarations_impl(self):
     35          return self._declarations
     36 -    def _set_declarations(self, declarations):
     37          self._declarations = declarations
     38      declarations = property( scopedef.scopedef_t._get_declarations
     39                               , _set_declarations
     40                               , doc="list of all declarations, defined in the namespace")
     41
     42 -    def take_parenting( self, inst ):
     43          """Takes parenting from inst and transfers it to self"""
     44          if self is inst:
     45              return
     46          for decl in inst.declarations:
     47              decl.parent = self
     48              self.declarations.append( decl )
     49          inst.declarations = []
     50
     51 -    def adopt_declaration( self, decl ):
     52          self.declarations.append( decl )
     53          decl.parent = self
     54          decl.cache.reset()
     55
     56 -    def remove_declaration( self, decl ):
     57          """
     58          removes decl from  members list
     59
     60          @param decl: declaration to be removed
     61          @type decl: L{declaration_t}
     62          """
     63          del self.declarations[ self.declarations.index( decl ) ]
     64          decl.cache.reset()
     65          #add more comment about this.
     66          #if not keep_parent:
     67          #    decl.parent=None
     68
     69 -    def namespace( self, name=None, function=None, recursive=None ):
     70          """returns reference to namespace declaration, that is matched defined criterias"""
     71          return self._find_single( scopedef.scopedef_t._impl_matchers[ namespace_t.namespace ]
     72                                    , name=name
     73                                    , function=function
     74                                    , recursive=recursive )
     75      ns = namespace
     76
     77 -    def namespaces( self, name=None, function=None, recursive=None, allow_empty=None ):
     78          """returns a set of namespace declarations, that are matched defined criterias"""
     79          return self._find_multiple( scopedef.scopedef_t._impl_matchers[ namespace_t.namespace ]
     80                                      , name=name
     81                                      , function=function
     82                                      , recursive=recursive
     83                                      , allow_empty=allow_empty)
     84      nss = namespaces
     85
     86 -    def free_function( self, name=None, function=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None ):
     87          """returns reference to free function declaration, that is matched defined criterias"""
     88          return self._find_single( scopedef.scopedef_t._impl_matchers[ namespace_t.free_function ]
     89                                    , name=name
     90                                    , function=function
     91                                    , decl_type=self._impl_decl_types[ namespace_t.free_function ]
     92                                    , return_type=return_type
     93                                    , arg_types=arg_types
     94                                    , header_dir=header_dir
     95                                    , header_file=header_file
     96                                    , recursive=recursive )
     97      free_fun = free_function
     98
     99 -    def free_functions( self, name=None, function=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None, allow_empty=None ):
    100          """returns a set of free function declarations, that are matched defined criterias"""
    101          return self._find_multiple( scopedef.scopedef_t._impl_matchers[ namespace_t.free_function ]
    102                                      , name=name
    103                                      , function=function
    104                                      , decl_type=self._impl_decl_types[ namespace_t.free_function ]
    105                                      , return_type=return_type
    106                                      , arg_types=arg_types
    107                                      , header_dir=header_dir
    108                                      , header_file=header_file
    109                                      , recursive=recursive
    110                                      , allow_empty=allow_empty)
    111      free_funs = free_functions
    112
    113 -    def free_operator( self, name=None, function=None, symbol=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None ):
    114          """returns reference to free operator declaration, that is matched defined criterias"""
    115          return self._find_single( scopedef.scopedef_t._impl_matchers[ namespace_t.free_operator ]
    116                                    , name=self._build_operator_name( name, function, symbol )
    117                                    , symbol=symbol
    118                                    , function=self._build_operator_function( name, function )
    119                                    , decl_type=self._impl_decl_types[ namespace_t.free_operator ]
    120                                    , return_type=return_type
    121                                    , arg_types=arg_types
    122                                    , header_dir=header_dir
    123                                    , header_file=header_file
    124                                    , recursive=recursive )
    125
    126 -    def free_operators( self, name=None, function=None, symbol=None, return_type=None, arg_types=None, header_dir=None, header_file=None, recursive=None, allow_empty=None ):
    127          """returns a set of free operator declarations, that are matched defined criterias"""
    128          return self._find_multiple( scopedef.scopedef_t._impl_matchers[ namespace_t.free_operator ]
    129                                      , name=self._build_operator_name( name, function, symbol )
    130                                      , symbol=symbol
    131                                      , function=self._build_operator_function( name, function )
    132                                      , decl_type=self._impl_decl_types[ namespace_t.free_operator ]
    133                                      , return_type=return_type
    134                                      , arg_types=arg_types
    135                                      , header_dir=header_dir
    136                                      , header_file=header_file
    137                                      , recursive=recursive
    138                                      , allow_empty=allow_empty)
    139
    140 -    def i_depend_on_them( self, recursive=True ):
    141          answer = []
    142          if recursive:
    143              map( lambda decl: answer.extend( decl.i_depend_on_them() ), self.declarations )
    144          return answer
    145