[pygccxml-commit] SF.net SVN: pygccxml:[1374] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2008-07-21 20:16:46
|
Revision: 1374
http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1374&view=rev
Author: roman_yakovenko
Date: 2008-07-21 20:16:53 +0000 (Mon, 21 Jul 2008)
Log Message:
-----------
adding ability to expose address of the static variable
Modified Paths:
--------------
pyplusplus_dev/pyplusplus/code_creators/member_variable.py
pyplusplus_dev/pyplusplus/code_repository/ctypes_integration.py
pyplusplus_dev/unittests/data/member_variables_to_be_exported.cpp
pyplusplus_dev/unittests/data/member_variables_to_be_exported.hpp
pyplusplus_dev/unittests/member_variables_tester.py
Modified: pyplusplus_dev/pyplusplus/code_creators/member_variable.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_creators/member_variable.py 2008-07-17 04:31:02 UTC (rev 1373)
+++ pyplusplus_dev/pyplusplus/code_creators/member_variable.py 2008-07-21 20:16:53 UTC (rev 1374)
@@ -656,30 +656,30 @@
def __init__(self, variable, wrapper=None ):
member_variable_base_t.__init__( self, variable=variable, wrapper=wrapper )
- def _create_impl( self ):
- doc = '' #static property does not support documentation
- if self.declaration.type_qualifiers.has_static:
- add_property = 'add_static_property'
- else:
- if self.documentation:
- doc = self.documentation
- add_property = 'add_property'
- answer = [ add_property ]
+ def _create_m_var( self ):
+ answer = [ 'add_property' ]
answer.append( '( ' )
answer.append('"%s"' % self.alias)
answer.append( self.PARAM_SEPARATOR )
-
- if self.declaration.type_qualifiers.has_static:
- answer.append( 'not implemented' )
- else:
- answer.append( 'pyplus_conv::make_addressof_getter(&%s)'
- % self.decl_identifier )
- if doc:
+ answer.append( 'pyplus_conv::make_addressof_getter(&%s)'
+ % self.decl_identifier )
+ if self.documentation:
answer.append( self.PARAM_SEPARATOR )
- answer.append( doc )
+ answer.append( self.documentation )
answer.append( ' ) ' )
-
return ''.join( answer )
+ def _create_s_var( self ):
+ return 'def( %(def_visitor)s("%(name)s", %(var)s) )' \
+ % { 'def_visitor' : 'pyplus_conv::register_addressof_static_var'
+ , 'name' : self.alias
+ , 'var' : self.decl_identifier }
+
+
+ def _create_impl( self ):
+ if self.declaration.type_qualifiers.has_static:
+ return self._create_s_var()
+ else:
+ return self._create_m_var()
def _get_system_headers_impl( self ):
return [code_repository.ctypes_integration.file_name]
Modified: pyplusplus_dev/pyplusplus/code_repository/ctypes_integration.py
===================================================================
--- pyplusplus_dev/pyplusplus/code_repository/ctypes_integration.py 2008-07-17 04:31:02 UTC (rev 1373)
+++ pyplusplus_dev/pyplusplus/code_repository/ctypes_integration.py 2008-07-21 20:16:53 UTC (rev 1374)
@@ -32,18 +32,17 @@
namespace pyplusplus{ namespace convenience{
template< typename TType, typename TMemVarType >
-boost::uintmax_t
+boost::uint32_t
addressof( const TType &inst, const TMemVarType TType::* offset){
- return boost::uintmax_t( boost::addressof( inst.*offset ) );
+ return boost::uint32_t( boost::addressof( inst.*offset ) );
}
template< typename TType >
-boost::uintmax_t
+boost::uint32_t
addressof_inst( const TType &inst){
- return boost::uintmax_t( boost::addressof( inst ) );
+ return boost::uint32_t( boost::addressof( inst ) );
}
-
template< typename TType, typename TMemVarType >
boost::python::object
make_addressof_getter( const TMemVarType TType::* offset ){
@@ -51,7 +50,7 @@
namespace pyppc = pyplusplus::convenience;
return bpl::make_function( boost::bind( &pyppc::addressof< TType, TMemVarType >, _1, offset )
, bpl::default_call_policies()
- , boost::mpl::vector< boost::uintmax_t, const TType& >() );
+ , boost::mpl::vector< boost::uint32_t, const TType& >() );
}
template< typename TType >
@@ -61,9 +60,32 @@
namespace pyppc = pyplusplus::convenience;
return bpl::make_function( boost::bind( &pyppc::addressof_inst< TType >, _1 )
, bpl::default_call_policies()
- , boost::mpl::vector< boost::uintmax_t, const TType& >() );
+ , boost::mpl::vector< boost::uint32_t, const TType& >() );
}
+class register_addressof_static_var : public boost::python::def_visitor<register_addressof_static_var>
+{
+ friend class boost::python::def_visitor_access;
+
+public:
+
+ template< typename TVarType >
+ register_addressof_static_var( const char* name, const TVarType& var )
+ : m_name( name )
+ , m_address( addressof_inst( var ) )
+ {}
+
+ template <class classT>
+ void visit(classT& c) const{
+ boost::python::scope cls_scope( c );
+ cls_scope.attr(m_name) = m_address;
+ }
+
+private:
+ boost::uint32_t m_address;
+ const char* m_name;
+};
+
} /*pyplusplus*/ } /*convenience*/
namespace pyplus_conv = pyplusplus::convenience;
Modified: pyplusplus_dev/unittests/data/member_variables_to_be_exported.cpp
===================================================================
--- pyplusplus_dev/unittests/data/member_variables_to_be_exported.cpp 2008-07-17 04:31:02 UTC (rev 1373)
+++ pyplusplus_dev/unittests/data/member_variables_to_be_exported.cpp 2008-07-21 20:16:53 UTC (rev 1374)
@@ -5,7 +5,7 @@
#include "member_variables_to_be_exported.hpp"
-namespace member_variables{
+namespace member_variables{
int point::instance_count = 0;
const point::color point::default_color = point::red;
@@ -28,17 +28,24 @@
std::auto_ptr<tree_node_t> root( new tree_node_t() );
root->data = new data_t();
root->data->value = 0;
-
+
root->left = new tree_node_t( root.get() );
root->left->data = new data_t();
root->left->data->value = 1;
-
- return root;
+
+ return root;
}
}
-namespace statics{
+namespace statics{
std::string mem_var_str_t::class_name( "mem_var_str_t" );
}
+
+
+namespace ctypes{
+ int xxx = 1997;
+ int* image_t::none_image = &xxx;
}
+
+}
Modified: pyplusplus_dev/unittests/data/member_variables_to_be_exported.hpp
===================================================================
--- pyplusplus_dev/unittests/data/member_variables_to_be_exported.hpp 2008-07-17 04:31:02 UTC (rev 1373)
+++ pyplusplus_dev/unittests/data/member_variables_to_be_exported.hpp 2008-07-21 20:16:53 UTC (rev 1374)
@@ -160,6 +160,8 @@
}
}
int* data;
+
+ static int* none_image;
};
}
Modified: pyplusplus_dev/unittests/member_variables_tester.py
===================================================================
--- pyplusplus_dev/unittests/member_variables_tester.py 2008-07-17 04:31:02 UTC (rev 1373)
+++ pyplusplus_dev/unittests/member_variables_tester.py 2008-07-21 20:16:53 UTC (rev 1374)
@@ -24,6 +24,7 @@
mb.classes().always_expose_using_scope = True
image = mb.class_( 'image_t' )
image.var( 'data' ).expose_address = True
+ image.var( 'none_image' ).expose_address = True
def change_default_color( self, module ):
module.point.default_color = module.point.color.blue
@@ -96,6 +97,9 @@
for j in range(5):
print '%d : %d' % ( j, data[j] )
+ data_type = ctypes.POINTER( ctypes.c_int )
+ data = data_type.from_address( module.image_t.none_image )
+ self.failUnless( 1997 == data.contents.value )
def create_suite():
suite = unittest.TestSuite()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|