Added new typemap and function to turn a
std::set<T>::iterator and std::multiset<T>::iterator into a ruby const iterator so that the key value cannot be changed. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10055 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
4ace915a56
commit
7bc4e56614
1 changed files with 39 additions and 2 deletions
|
|
@ -32,12 +32,49 @@
|
||||||
return traits_from_stdseq<std::set<T> >::from(vec);
|
return traits_from_stdseq<std::set<T> >::from(vec);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Template specialization to construct a closed iterator for sets
|
||||||
|
// this turns a nonconst iterator into a const one for ruby to avoid
|
||||||
|
// allowing the user to change the value
|
||||||
|
template< typename InOutIter >
|
||||||
|
inline ConstIterator*
|
||||||
|
make_set_nonconst_iterator(const InOutIter& current,
|
||||||
|
const InOutIter& begin,
|
||||||
|
const InOutIter& end,
|
||||||
|
VALUE seq = Qnil)
|
||||||
|
{
|
||||||
|
return new ConstIteratorClosed_T< InOutIter >(current,
|
||||||
|
begin, end, seq);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Template specialization to construct an open iterator for sets
|
||||||
|
// this turns a nonconst iterator into a const one for ruby to avoid
|
||||||
|
// allowing the user to change the value
|
||||||
|
template< typename InOutIter >
|
||||||
|
inline ConstIterator*
|
||||||
|
make_set_nonconst_iterator(const InOutIter& current,
|
||||||
|
VALUE seq = Qnil)
|
||||||
|
{
|
||||||
|
return new ConstIteratorOpen_T< InOutIter >(current, seq);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
%define %swig_set_methods(set...)
|
%define %swig_set_methods(set...)
|
||||||
%swig_sequence_iterator(set)
|
|
||||||
%swig_sequence_methods_common(set);
|
%swig_sequence_methods_common(%arg(set));
|
||||||
|
|
||||||
|
// Redefine std::set iterator/reverse_iterator typemap
|
||||||
|
%typemap(out,noblock=1)
|
||||||
|
iterator, reverse_iterator {
|
||||||
|
$result = SWIG_NewPointerObj(swig::make_set_nonconst_iterator(%static_cast($1,const $type &),
|
||||||
|
self),
|
||||||
|
swig::ConstIterator::descriptor(),SWIG_POINTER_OWN);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
%extend {
|
%extend {
|
||||||
%alias push "<<";
|
%alias push "<<";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue