[pygccxml-commit] SF.net SVN: pygccxml: [694] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-11-02 08:47:28
|
Revision: 694 http://svn.sourceforge.net/pygccxml/?rev=694&view=rev Author: roman_yakovenko Date: 2006-11-02 00:47:11 -0800 (Thu, 02 Nov 2006) Log Message: ----------- fixing few bugs in indexing suite v2 Modified Paths: -------------- pyplusplus_dev/indexing_suite_v2/indexing/algorithms.hpp pyplusplus_dev/indexing_suite_v2/indexing/map.hpp pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp pyplusplus_dev/indexing_suite_v2/indexing/set.hpp pyplusplus_dev/unittests/data/indexing_suites2_to_be_exported.hpp pyplusplus_dev/unittests/indexing_suites2_tester.py Modified: pyplusplus_dev/indexing_suite_v2/indexing/algorithms.hpp =================================================================== --- pyplusplus_dev/indexing_suite_v2/indexing/algorithms.hpp 2006-10-30 16:43:55 UTC (rev 693) +++ pyplusplus_dev/indexing_suite_v2/indexing/algorithms.hpp 2006-11-02 08:47:11 UTC (rev 694) @@ -151,25 +151,11 @@ static size_type count (container &, key_param); static bool contains (container &, key_param); - static boost::python::list keys( container & ); - // Default visit_container_class template<typename PythonClass, typename Policy> static void visit_container_class( PythonClass &pyClass, Policy const &policy) { ContainerTraits::visit_container_class (pyClass, policy); - pyClass.def( "keys", &self_type::keys ); - - //~ object class_name(cl.attr("__name__")); - //~ extract<std::string> class_name_extractor(class_name); - //~ std::string = class_name_extractor() + "_entry"; - - //~ class_<value_type>(elem_name.c_str()) - //~ .def("data", &DerivedPolicies::get_data, get_data_return_policy()) - //~ .def("key", &DerivedPolicies::get_key) - //~ ; - - } @@ -529,25 +515,6 @@ return c.count (key); } - template<typename ContainerTraits, typename Ovr> - boost::python::list - assoc_algorithms<ContainerTraits, Ovr>::keys( container &c ) - { - boost::python::list _keys; - //For some reason code with set could not be compiled - //std::set< key_param > unique_keys; - for( iterator index = most_derived::begin(c); index != most_derived::end(c); ++index ){ - //if( unique_keys.end() == unique_keys.find( index->first ) ){ - // unique_keys.insert( index->first ); - if( !_keys.count( index->first ) ){ - _keys.append( index->first ); - } - //} - } - - return _keys; - } - ///////////////////////////////////////////////////////////////////////// // Some meta-information to select algorithms for const and // non-const qualified containers. All algorithms_selector specializations Modified: pyplusplus_dev/indexing_suite_v2/indexing/map.hpp =================================================================== --- pyplusplus_dev/indexing_suite_v2/indexing/map.hpp 2006-10-30 16:43:55 UTC (rev 693) +++ pyplusplus_dev/indexing_suite_v2/indexing/map.hpp 2006-11-02 08:47:11 UTC (rev 694) @@ -96,8 +96,18 @@ static reference get (container &, index_param); // Version to return only the mapped type + static boost::python::list keys( container & ); + static void assign (container &, index_param, value_param); static void insert (container &, index_param, value_param); + + template<typename PythonClass, typename Policy> + static void visit_container_class( PythonClass &pyClass, Policy const &policy) + { + ContainerTraits::visit_container_class (pyClass, policy); + pyClass.def( "keys", &self_type::keys ); + } + }; #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) @@ -159,6 +169,26 @@ return most_derived::find_or_throw (c, ix)->second; } + + template<typename ContainerTraits, typename Ovr> + boost::python::list + map_algorithms<ContainerTraits, Ovr>::keys( container &c ) + { + boost::python::list _keys; + //For some reason code with set could not be compiled + //std::set< key_param > unique_keys; + for( iterator index = most_derived::begin(c); index != most_derived::end(c); ++index ){ + //if( unique_keys.end() == unique_keys.find( index->first ) ){ + // unique_keys.insert( index->first ); + if( !_keys.count( index->first ) ){ + _keys.append( index->first ); + } + //} + } + + return _keys; + } + ///////////////////////////////////////////////////////////////////////// // Assign a value at a particular index (map version) ///////////////////////////////////////////////////////////////////////// Modified: pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp =================================================================== --- pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp 2006-10-30 16:43:55 UTC (rev 693) +++ pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp 2006-11-02 08:47:11 UTC (rev 694) @@ -93,8 +93,18 @@ static boost::python::list get (container &, index_param); // Version to return only the mapped type + static boost::python::list keys( container & ); + static void assign (container &, index_param, value_param); static void insert (container &, index_param, value_param); + + template<typename PythonClass, typename Policy> + static void visit_container_class( PythonClass &pyClass, Policy const &policy) + { + ContainerTraits::visit_container_class (pyClass, policy); + pyClass.def( "keys", &self_type::keys ); + } + }; template< @@ -124,6 +134,26 @@ return l; } + template<typename ContainerTraits, typename Ovr> + boost::python::list + multimap_algorithms<ContainerTraits, Ovr>::keys( container &c ) + { + boost::python::list _keys; + //For some reason code with set could not be compiled + //std::set< key_param > unique_keys; + for( iterator index = most_derived::begin(c); index != most_derived::end(c); ++index ){ + //if( unique_keys.end() == unique_keys.find( index->first ) ){ + // unique_keys.insert( index->first ); + if( !_keys.count( index->first ) ){ + _keys.append( index->first ); + } + //} + } + + return _keys; + } + + ///////////////////////////////////////////////////////////////////////// // Assign a value at a particular index (map version) ///////////////////////////////////////////////////////////////////////// Modified: pyplusplus_dev/indexing_suite_v2/indexing/set.hpp =================================================================== --- pyplusplus_dev/indexing_suite_v2/indexing/set.hpp 2006-10-30 16:43:55 UTC (rev 693) +++ pyplusplus_dev/indexing_suite_v2/indexing/set.hpp 2006-11-02 08:47:11 UTC (rev 694) @@ -85,6 +85,14 @@ typedef typename Parent::index_param index_param; static void insert (container &, index_param); + + template<typename PythonClass, typename Policy> + static void visit_container_class( PythonClass &pyClass, Policy const &policy) + { + ContainerTraits::visit_container_class (pyClass, policy); + pyClass.def( "add", &self_type::insert ); + } + }; #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) @@ -144,13 +152,15 @@ set_algorithms<ContainerTraits, Ovr>::insert( container &c, index_param ix) { - if (!c.insert (ix).second) - { - PyErr_SetString( - PyExc_ValueError, "Set already holds value for insertion"); + c.insert (ix); + //~ Python set does not raise exception in this situation + //~ if (!c.insert (ix).second) + //~ { + //~ PyErr_SetString( + //~ PyExc_ValueError, "Set already holds value for insertion"); - boost::python::throw_error_already_set (); - } + //~ boost::python::throw_error_already_set (); + //~ } } } } } Modified: pyplusplus_dev/unittests/data/indexing_suites2_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/indexing_suites2_to_be_exported.hpp 2006-10-30 16:43:55 UTC (rev 693) +++ pyplusplus_dev/unittests/data/indexing_suites2_to_be_exported.hpp 2006-11-02 08:47:11 UTC (rev 694) @@ -9,6 +9,7 @@ #include <vector> #include <string> #include <map> +#include <set> namespace indexing_suites2 { @@ -66,6 +67,11 @@ return multimap_ints_t(); } +typedef std::set< std::string > set_strings_t; +inline set_strings_t create_set_strings(){ + return set_strings_t(); } -#endif//__indexing_suites2_to_be_exported_hpp__ \ No newline at end of file +} + +#endif//__indexing_suites2_to_be_exported_hpp__ Modified: pyplusplus_dev/unittests/indexing_suites2_tester.py =================================================================== --- pyplusplus_dev/unittests/indexing_suites2_tester.py 2006-10-30 16:43:55 UTC (rev 693) +++ pyplusplus_dev/unittests/indexing_suites2_tester.py 2006-11-02 08:47:11 UTC (rev 694) @@ -53,7 +53,12 @@ items_ptr = module.items_ptr_t() items_ptr.append( item ) self.failUnless( items_ptr[0].value == 1977 ) - print 'xx' + + set_of_strings = module.create_set_strings() + set_of_strings.add("s") + set_of_strings.add("s1") + set_of_strings.add("s") + def create_suite(): suite = unittest.TestSuite() suite.addTest( unittest.makeSuite(tester_t)) @@ -63,4 +68,4 @@ unittest.TextTestRunner(verbosity=2).run( create_suite() ) if __name__ == "__main__": - run_suite() \ No newline at end of file + run_suite() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |