Revision: 1799
http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1799&view=rev
Author: roman_yakovenko
Date: 2010-01-13 11:43:23 +0000 (Wed, 13 Jan 2010)
Log Message:
-----------
add conditional registration of std:pair type
Modified Paths:
--------------
pyplusplus_dev/indexing_suite_v2/indexing_suite/pair.hpp
Added Paths:
-----------
pyplusplus_dev/indexing_suite_v2/indexing_suite/registry_utils.hpp
Modified: pyplusplus_dev/indexing_suite_v2/indexing_suite/pair.hpp
===================================================================
--- pyplusplus_dev/indexing_suite_v2/indexing_suite/pair.hpp 2010-01-13 10:38:19 UTC (rev 1798)
+++ pyplusplus_dev/indexing_suite_v2/indexing_suite/pair.hpp 2010-01-13 11:43:23 UTC (rev 1799)
@@ -20,6 +20,7 @@
#include <boost/config.hpp>
#include <indexing_suite/container_traits.hpp>
#include <indexing_suite/container_suite.hpp>
+#include <indexing_suite/registry_utils.hpp>
#include <indexing_suite/algorithms.hpp>
#include <boost/detail/workaround.hpp>
@@ -36,11 +37,16 @@
typedef pair_exposer_t< TValueType, TValueCallPolicies > exposer_type;
pair_exposer_t(const std::string& name){
- class_< pair_type >( name.c_str() )
- .def( "__len__", &exposer_type::len )
- .def( "__getitem__", &exposer_type::get_item )
- .add_property( "key", &exposer_type::get_key )
- .add_property( "value", &exposer_type::get_mapped );
+ if( boost::python::registry::utils::is_registered< pair_type >() ){
+ boost::python::registry::utils::register_alias<pair_type>( name.c_str() );
+ }
+ else{
+ class_< pair_type >( name.c_str() )
+ .def( "__len__", &exposer_type::len )
+ .def( "__getitem__", &exposer_type::get_item )
+ .add_property( "key", &exposer_type::get_key )
+ .add_property( "value", &exposer_type::get_mapped );
+ }
}
private:
Added: pyplusplus_dev/indexing_suite_v2/indexing_suite/registry_utils.hpp
===================================================================
--- pyplusplus_dev/indexing_suite_v2/indexing_suite/registry_utils.hpp (rev 0)
+++ pyplusplus_dev/indexing_suite_v2/indexing_suite/registry_utils.hpp 2010-01-13 11:43:23 UTC (rev 1799)
@@ -0,0 +1,41 @@
+// Header file registry_utils.hpp
+//
+// provides few convenience functions for dealing with boost:python registry
+//
+// Copyright (c) 2010 Roman Yakovenko
+//
+// Use, modification and distribution is subject to the Boost Software
+// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
+// at http://www.boost.org/LICENSE_1_0.txt)
+//
+// History
+// =======
+// 2010/01/12 Roman File creation
+//
+
+#ifndef REGISTRY_UTILS_12_01_2010_HPP
+#define REGISTRY_UTILS_12_01_2010_HPP
+
+#include <boost/config.hpp>
+#include "boost/python.hpp"
+#include "boost/python/converter/registry.hpp"
+
+namespace boost{ namespace python{ namespace registry{ namespace utils{
+
+template<class T>
+bool is_registered(){
+ namespace bpl = boost::python;
+ bpl::handle<> class_obj( bpl::objects::registered_class_object( bpl::type_id< T >()));
+ return class_obj.get() ? true : false;
+}
+
+template< class T >
+void register_alias( const char* name ){
+ namespace bpl = boost::python;
+ bpl::handle<> class_obj( bpl::objects::registered_class_object( bpl::type_id< T >()));
+ boost::python::scope().attr( name ) = bpl::object( class_obj );
+}
+
+}}}}
+
+#endif // REGISTRY_UTILS_12_01_2010_HPP
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|