Trees | Indices | Help |
|
---|
|
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 import os 7 import pygccxml 8 import algorithm 9 import code_creator 10 import declaration_based 11 import registration_based 12 from pygccxml import declarations 13 from pyplusplus import code_repository 14 from pyplusplus import decl_wrappers 1516 -class global_variable_base_t( registration_based.registration_based_t 17 , declaration_based.declaration_based_t ):18 """ 19 Base class for all global variables code creators. Mainly exists to 20 simplify file writers algorithms. 21 """3523 registration_based.registration_based_t.__init__( self ) 24 declaration_based.declaration_based_t.__init__( self, declaration=variable) 25 self._wrapper = wrapper26 31 wrapper = property( _get_wrapper, _set_wrapper ) 3237 """ 38 Creates boost.python code that exposes global variable. 39 """ 426144 if self.declaration.already_exposed: 45 return '' 46 47 assert isinstance( self.declaration, pygccxml.declarations.variable_t ) 48 result = [] 49 result.append( algorithm.create_identifier( self, '::boost::python::scope' ) ) 50 result.append( '().attr("%s")' % self.alias ) 51 dtype = self.declaration.type 52 if decl_wrappers.python_traits.is_immutable( dtype ) \ 53 or pygccxml.declarations.is_const( dtype ) \ 54 or pygccxml.declarations.smart_pointer_traits.is_smart_pointer( dtype ): 55 result.append( ' = %s;' % self.decl_identifier ) 56 else: 57 obj_identifier = algorithm.create_identifier( self, '::boost::python::object' ) 58 ref_identifier = algorithm.create_identifier( self, '::boost::ref' ) 59 result.append( ' = %s( %s( %s ) );' % ( obj_identifier, ref_identifier, self.decl_identifier ) ) 60 return ''.join( result )63 """ 64 Creates boost.python code that exposes array global variable. 65 """ 66 67 _PARAM_SEPARATOR = ', ' 70 738575 if self.declaration.already_exposed: 76 return '' 77 78 answer = [] 79 answer.append( algorithm.create_identifier( self, '::boost::python::scope' ) ) 80 answer.append( '().attr("%s")' % self.alias ) 81 answer.append( ' = ' ) 82 answer.append( self.wrapper.wrapper_creator_full_name ) 83 answer.append( '();' ) 84 return ''.join( answer )86 -class array_gv_wrapper_t( code_creator.code_creator_t 87 , declaration_based.declaration_based_t ):88 """ 89 Creates C++ code that register array class. 90 """ 9116093 code_creator.code_creator_t.__init__( self ) 94 declaration_based.declaration_based_t.__init__( self, declaration=variable)9597 ns_name = code_repository.array_1.namespace 98 if declarations.is_const( self.declaration.type ): 99 class_name = 'const_array_1_t' 100 else: 101 class_name = 'array_1_t' 102 103 decl_string = declarations.templates.join( 104 '::'.join( [ns_name, class_name] ) 105 , [ declarations.array_item_type( self.declaration.type ).decl_string 106 , str( declarations.array_size( self.declaration.type ) ) 107 ]) 108 109 return declarations.dummy_type_t( decl_string )110 wrapper_type = property( _get_wrapper_type ) 111113 return declarations.free_function_type_t.create_decl_string( 114 return_type=self.wrapper_type 115 , arguments_types=[] 116 , with_defaults=False)117 wrapper_creator_type = property( _get_wrapper_creator_type ) 118 121 wrapper_creator_name = property( _get_wrapper_creator_name ) 122124 ns_names = declarations.declaration_path( self.declaration.parent ) 125 if len(ns_names) >= 1 and ns_names[0] == '::': 126 ns_names = ns_names[1:] 127 return ns_names128130 names = self._create_namespaces() 131 names.append( self.wrapper_creator_name ) 132 return '::'.join( names )133 wrapper_creator_full_name = property( _get_wrapper_creator_full_name ) 134136 temp = [] 137 for ns_name in self._create_namespaces(): 138 temp.append( ''.join( ['namespace ', ns_name, '{ '] ) ) 139 return ''.join( temp )140142 if self.declaration.already_exposed: 143 return '' 144 145 answer = [self._create_namespaces_name()] 146 answer.append( self.wrapper_type.decl_string ) 147 answer.append( ''.join([ self.wrapper_creator_name, '(){']) ) 148 temp = ''.join([ 'return ' 149 , self.wrapper_type.decl_string 150 , '( ' 151 , declarations.full_name( self.declaration ) 152 , ' );']) 153 answer.append( self.indent( temp ) ) 154 answer.append('}') 155 answer.append( '}' * len( self._create_namespaces() ) ) 156 return os.linesep.join( answer )157162 """ 163 Creates boost.python code that exposes address of global variable. 164 165 This functionality is pretty powerful if you use it with "ctypes" - 166 standard package. 167 """ 170185172 if self.declaration.already_exposed: 173 return '' 174 175 assert isinstance( self.declaration, pygccxml.declarations.variable_t ) 176 result = [] 177 #TODO: porting to 64Bit is welcome 178 result.append( algorithm.create_identifier( self, '::boost::python::scope' ) ) 179 result.append( '().attr("%s")' % self.alias ) 180 result.append( ' = boost::uint32_t( boost::addressof( %s ) );' % self.decl_identifier ) 181 return ''.join( result )182
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Mon Oct 20 08:51:48 2008 | http://epydoc.sourceforge.net |