2 * @file rubycontainer_extended.swg
4 * @date Sat May 5 05:36:01 2007
6 * @brief This file contains additional functions that make containers
7 * behave closer to ruby primitive types.
8 * However, some of these functions place some restrictions on
9 * the underlying object inside of the container and the iterator
10 * (that it has to have an == comparison function, that it has to have
11 * an = assignment operator, etc).
17 * Macro used to add extend functions that require operator== in object.
19 * @param Container STL container
20 * @param Type class inside container
23 %define %swig_container_with_equal_operator( Container, Type )
25 VALUE __delete__( const Type& val ) {
27 Container<Type >::iterator e = $self->end();
28 Container<Type >::iterator i = std::remove( $self->begin(), e, val );
29 // remove dangling elements now
33 r = swig::from< Type >( val );
34 else if ( rb_block_given_p() )
39 %enddef // end of %swig_container_with_equal_operator
45 * Macro used to add extend functions that require the assignment
46 * operator (ie. = ) of contained class
48 * @param Container STL container
49 * @param Type class inside container
53 %define %swig_container_with_assignment( Container, Type )
57 // map! -- the equivalent of std::transform
59 Container< Type >* map_bang() {
61 if ( !rb_block_given_p() )
62 rb_raise( rb_eArgError, "No block given" );
65 Container< Type >::iterator i = $self->begin();
66 Container< Type >::iterator e = $self->end();
71 r = swig::from< Type >( *i );
73 *i = swig::as< Type >( r );
76 catch ( const std::invalid_argument& )
78 rb_raise(rb_eTypeError,
79 "Yield block did not return a valid element for " #Container);
86 %enddef // end of %swig_container_with_assignment
93 * Macro used to add all extended functions to a container
95 * @param Container STL container
96 * @param Type class inside container
99 %define %swig_container_extend( Container, Type )
101 %extend Container< Type > {
103 %swig_container_with_assignment( %arg(Container), Type );
104 %swig_container_with_equal_operator( %arg(Container), Type );
112 * Private macro used to add all extended functions to C/C++
115 * @param Container an STL container, like std::vector (with no class template)
118 %define %__swig_container_extend_primtypes( Container )
120 %swig_container_extend( %arg( Container ), bool );
121 %swig_container_extend( %arg( Container ), char );
122 %swig_container_extend( %arg( Container ), short );
123 %swig_container_extend( %arg( Container ), int );
124 %swig_container_extend( %arg( Container ), unsigned short );
125 %swig_container_extend( %arg( Container ), unsigned int );
126 %swig_container_extend( %arg( Container ), float );
127 %swig_container_extend( %arg( Container ), double );
128 %swig_container_extend( %arg( Container ), std::complex );
129 %swig_container_extend( %arg( Container ), std::string );
130 %swig_container_extend( %arg( Container ), swig::GC_VALUE );
131 %swig_container_extend( %arg( Container ), swig::GC_VALUE );
136 %__swig_container_extend_primtypes( std::vector );
137 %__swig_container_extend_primtypes( std::deque );
138 %__swig_container_extend_primtypes( std::list );