Crazy Eddie's GUI System  ${CEGUI_VERSION}
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
pair.hpp
1 // This file has been generated by Py++.
2 
3 // Header file pair.hpp
4 //
5 // Exposes std::pair< key, value > class
6 //
7 // Copyright (c) 2007 Roman Yakovenko
8 //
9 // Use, modification and distribution is subject to the Boost Software
10 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
11 // at http://www.boost.org/LICENSE_1_0.txt)
12 //
13 // History
14 // =======
15 // 2007/2/11 rmg File creation
16 // 2008/12/08 Roman Change indexing suite layout
17 //
18 
19 #ifndef BOOST_PYTHON_STD_PAIR_KEY_VALUE_11_02_2007_HPP
20 #define BOOST_PYTHON_STD_PAIR_KEY_VALUE_11_02_2007_HPP
21 
22 #include <boost/config.hpp>
23 #include <indexing_suite/container_traits.hpp>
24 #include <indexing_suite/container_suite.hpp>
25 #include <indexing_suite/registry_utils.hpp>
26 #include <indexing_suite/algorithms.hpp>
27 #include <boost/detail/workaround.hpp>
28 
29 namespace boost { namespace python { namespace indexing { namespace mapping{
30 
31 namespace details{
32 
33 template< typename TValueType, typename TValueCallPolicies >
35 
36  typedef TValueType pair_type;
37  typedef BOOST_DEDUCED_TYPENAME pair_type::first_type key_type;
38  typedef BOOST_DEDUCED_TYPENAME pair_type::second_type mapped_type;
40 
41  pair_exposer_t(const std::string& name){
42  if( boost::python::registry::utils::is_registered< pair_type >() ){
43  boost::python::registry::utils::register_alias<pair_type>( name.c_str() );
44  }
45  else{
46  class_< pair_type >( name.c_str() )
47  .def( "__len__", &exposer_type::len )
48  .def( "__getitem__", &exposer_type::get_item )
49  .add_property( "key", &exposer_type::get_key )
50  .add_property( "value", &exposer_type::get_mapped );
51  }
52  }
53 
54 private:
55 
56  static size_t len( const pair_type& ){
57  return 2;
58  }
59 
60  static object get_item( pair_type& p, size_t index ){
61  switch( index ){
62  case 0:{
63  return get_key( p );
64  }
65  case 1:{
66  return get_mapped( p );
67  }
68  case 2:{
69  objects::stop_iteration_error();
70  return object(); //will not reach this line
71  }
72  default:{
73  PyErr_SetString( PyExc_IndexError, "the only valid index numbers are: 0 and 1");
74  throw_error_already_set();
75  return object(); //will not reach this line
76  }
77  }
78  }
79 
80  static object get_key( const pair_type& p ){
81  return object( p.first );
82  }
83 
84  static object get_mapped( pair_type& p ){
85  typedef BOOST_DEDUCED_TYPENAME TValueCallPolicies::result_converter rc_type;
86  typedef BOOST_DEDUCED_TYPENAME rc_type:: template apply< mapped_type >::type converter_type;
87  converter_type converter;
88  return object( handle<>( converter( p.second ) ) );
89  }
90 
91 };
92 } //details
93 
94 template< typename TPythonClass, typename TValueType, typename TValueCallPolicies >
95 inline void register_value_type(TPythonClass &pyClass){
97 
98  object class_name(pyClass.attr("__name__"));
99  extract<std::string> class_name_extractor(class_name);
100  std::string pair_name = class_name_extractor() + "_entry";
101 
102  exposer_type expose( pair_name );
103 }
104 
105 } } } }
106 
107 #endif // BOOST_PYTHON_STD_PAIR_KEY_VALUE_11_02_2007_HPP
108 
109 
110 
Definition: python_CEGUI.h:11