Revision: 688
http://svn.sourceforge.net/pygccxml/?rev=688&view=rev
Author: roman_yakovenko
Date: 2006-10-27 15:38:20 -0700 (Fri, 27 Oct 2006)
Log Message:
-----------
adding mutlimap container support + new method "keys" for map and multimap containers
Modified Paths:
--------------
pyplusplus_dev/indexing_suite_v2/indexing/algorithms.hpp
Added Paths:
-----------
pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp
Modified: pyplusplus_dev/indexing_suite_v2/indexing/algorithms.hpp
===================================================================
--- pyplusplus_dev/indexing_suite_v2/indexing/algorithms.hpp 2006-10-25 08:35:41 UTC (rev 687)
+++ pyplusplus_dev/indexing_suite_v2/indexing/algorithms.hpp 2006-10-27 22:38:20 UTC (rev 688)
@@ -12,6 +12,7 @@
// =======
// 2003/ 9/11 rmg File creation from suite_utils.hpp
// 2003/10/28 rmg Split container-specific versions into separate headers
+// 2006/10/25 Roman Adding keys function to assoc_algorithms class
//
// $Id: algorithms.hpp,v 1.1.2.15 2004/02/08 18:57:42 raoulgough Exp $
//
@@ -31,6 +32,7 @@
#include <functional>
#include <stdexcept>
#include <string>
+#inllude <set>
namespace boost { namespace python { namespace indexing {
template<typename ContainerTraits, typename Ovr = detail::no_override>
@@ -149,6 +151,28 @@
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)
+ //~ ;
+
+
+ }
+
+
protected:
static iterator find_or_throw (container &, index_param);
};
@@ -505,6 +529,22 @@
return c.count (key);
}
+ template<typename ContainerTraits, typename Ovr>
+ boost::python::list
+ assoc_algorithms<ContainerTraits, Ovr>::keys( container &c )
+ {
+ boost::python::list _keys;
+ 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( unique_keys );
+ _keys.append( index->first );
+ }
+ }
+
+ return _keys;
+ }
+
/////////////////////////////////////////////////////////////////////////
// Some meta-information to select algorithms for const and
// non-const qualified containers. All algorithms_selector specializations
Added: pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp
===================================================================
--- pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp (rev 0)
+++ pyplusplus_dev/indexing_suite_v2/indexing/multimap.hpp 2006-10-27 22:38:20 UTC (rev 688)
@@ -0,0 +1,165 @@
+// 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)
+//
+// Header file multimap.hpp
+//
+// Indexing algorithms support for std::multimap instances
+//
+// History
+// =======
+// 2006/10/27 Roman File creation from map.hpp
+//
+
+#ifndef BOOST_PYTHON_INDEXING_MULTIMAP_HPP
+#define BOOST_PYTHON_INDEXING_MULTIMAP_HPP
+
+#include <boost/python/suite/indexing/container_traits.hpp>
+#include <boost/python/suite/indexing/container_suite.hpp>
+#include <boost/python/suite/indexing/algorithms.hpp>
+#include <boost/detail/workaround.hpp>
+#include <functional>
+#include <map>
+
+namespace boost { namespace python { namespace indexing {
+ /////////////////////////////////////////////////////////////////////////
+ // ContainerTraits implementation for std::map instances
+ /////////////////////////////////////////////////////////////////////////
+
+ template<typename Container>
+ class multimap_traits : public base_container_traits<Container>
+ {
+ typedef base_container_traits<Container> base_class;
+
+ public:
+# if BOOST_WORKAROUND (BOOST_MSVC, <= 1200)
+ // MSVC6 has a nonstandard name for mapped_type in std::multimap
+ typedef typename Container::referent_type value_type;
+# else
+ typedef typename Container::mapped_type value_type;
+# endif
+ typedef value_type & reference;
+ typedef typename Container::key_type index_type; // operator[]
+ typedef typename Container::key_type key_type; // find, count, ...
+
+ typedef typename BOOST_PYTHON_INDEXING_CALL_TRAITS <value_type>::param_type
+ value_param;
+ typedef typename BOOST_PYTHON_INDEXING_CALL_TRAITS <key_type>::param_type
+ key_param;
+ typedef typename BOOST_PYTHON_INDEXING_CALL_TRAITS <index_type>::param_type
+ index_param;
+
+ BOOST_STATIC_CONSTANT(
+ method_set_type,
+ supported_methods = (
+ method_iter
+
+ | method_getitem
+ | method_contains
+ | method_count
+ | method_has_key
+
+ | detail::method_set_if<
+ base_class::is_mutable,
+ method_setitem
+ | method_delitem
+ | method_insert
+ >::value
+ ));
+ };
+
+ /////////////////////////////////////////////////////////////////////////
+ // Algorithms implementation for std::multimap instances
+ /////////////////////////////////////////////////////////////////////////
+
+ template<typename ContainerTraits, typename Ovr = detail::no_override>
+ class multimap_algorithms
+ : public assoc_algorithms
+ <ContainerTraits,
+ typename detail::maybe_override
+ <multimap_algorithms<ContainerTraits, Ovr>, Ovr>
+ ::type>
+ {
+ typedef multimap_algorithms<ContainerTraits, Ovr> self_type;
+ typedef typename detail::maybe_override<self_type, Ovr>::type most_derived;
+ typedef assoc_algorithms<ContainerTraits, most_derived> Parent;
+
+ public:
+ typedef typename Parent::container container;
+ typedef typename Parent::reference reference;
+ typedef typename Parent::index_param index_param;
+ typedef typename Parent::value_param value_param;
+
+ static boost::python::list get (container &, index_param);
+ // Version to return only the mapped type
+
+ static void assign (container &, index_param, value_param);
+ static void insert (container &, index_param, value_param);
+ };
+
+ template<
+ class Container,
+ method_set_type MethodMask = all_methods,
+ class Traits = multimap_traits<Container>
+ >
+ struct multimap_suite
+ : container_suite<Container, MethodMask, multimap_algorithms<Traits> >
+ {
+ };
+
+ /////////////////////////////////////////////////////////////////////////
+ // Index into a container (multimap version)
+ /////////////////////////////////////////////////////////////////////////
+
+ template<typename ContainerTraits, typename Ovr>
+ boost::python::list
+ multimap_algorithms<ContainerTraits, Ovr>::get (container &c, index_param ix)
+ {
+ boost::python::list l;
+ typedef BOOST_DEDUCED_TYPENAME container::iterator iter_type;
+ for( iter_type index = c.lower_bound( ix ); index != c.upper_bound( ix ); ++index ){
+ boost::python::object v( index->second );
+ l.append( v );
+ }
+ return l;
+ }
+
+ /////////////////////////////////////////////////////////////////////////
+ // Assign a value at a particular index (map version)
+ /////////////////////////////////////////////////////////////////////////
+
+ template<typename ContainerTraits, typename Ovr>
+ void
+ multimap_algorithms<ContainerTraits, Ovr>::assign(
+ container &c, index_param ix, value_param val)
+ {
+ typedef std::pair<
+ BOOST_DEDUCED_TYPENAME self_type::container_traits::index_type
+ , BOOST_DEDUCED_TYPENAME self_type::container_traits::value_type>
+ pair_type;
+
+ // Can't use std::make_pair, because param types may be references
+ c.insert (pair_type (ix, val));
+ }
+
+
+ /////////////////////////////////////////////////////////////////////////
+ // Insert a new key, value pair into a map
+ /////////////////////////////////////////////////////////////////////////
+
+ template<typename ContainerTraits, typename Ovr>
+ void
+ multimap_algorithms<ContainerTraits, Ovr>::insert(
+ container &c, index_param ix, value_param val)
+ {
+ typedef std::pair
+ <BOOST_DEDUCED_TYPENAME self_type::container_traits::index_type,
+ BOOST_DEDUCED_TYPENAME self_type::container_traits::value_type>
+ pair_type;
+
+ // Can't use std::make_pair, because param types may be references
+ c.insert (pair_type (ix, val) );
+ }
+} } }
+
+#endif // BOOST_PYTHON_INDEXING_MULTIMAP_HPP
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|