better support for string and def. args, plus adding allocator + sstream

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6818 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-12-01 01:22:30 +00:00
commit ee3e53c9cd
10 changed files with 309 additions and 118 deletions

View file

@ -0,0 +1 @@
%include <std/std_alloc.i>

View file

@ -1,8 +1,8 @@
namespace std
{
%pythoncallback(1) endl;
%pythoncallback(1) ends;
%pythoncallback(1) flush;
%callback(1) endl;
%callback(1) ends;
%callback(1) flush;
}
%include <std/std_iostream.i>

View file

@ -0,0 +1 @@
%include <std/std_sstream.i>

View file

@ -1,87 +1 @@
%include <std_ios.i>
%{
#include <streambuf>
%}
namespace std {
template<typename _CharT, typename _Traits>
class basic_streambuf
{
public:
// Types:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
typedef basic_streambuf<char_type, traits_type> __streambuf_type;
public:
virtual
~basic_streambuf();
// Locales:
locale
pubimbue(const locale &__loc);
locale
getloc() const;
// Buffer and positioning:
__streambuf_type*
pubsetbuf(char_type* __s, streamsize __n);
pos_type
pubseekoff(off_type __off, ios_base::seekdir __way,
ios_base::openmode __mode = std::ios_base::in | std::ios_base::out);
pos_type
pubseekpos(pos_type __sp,
ios_base::openmode __mode = std::ios_base::in | std::ios_base::out);
int
pubsync() ;
// Get and put areas:
// Get area:
streamsize
in_avail();
int_type
snextc();
int_type
sbumpc();
int_type
sgetc();
streamsize
sgetn(char_type* __s, streamsize __n);
// Putback:
int_type
sputbackc(char_type __c);
int_type
sungetc();
// Put area:
int_type
sputc(char_type __c);
streamsize
sputn(const char_type* __s, streamsize __n);
protected:
basic_streambuf();
};
}
namespace std {
%template(streambuf) basic_streambuf<char, char_traits<char> >;
%template(wstreambuf) basic_streambuf<wchar_t, char_traits<wchar_t> >;
}
%include <std/std_streambuf.i>

77
SWIG/Lib/std/std_alloc.i Normal file
View file

@ -0,0 +1,77 @@
namespace std
{
/**
* @brief The "standard" allocator, as per [20.4].
*
* The private _Alloc is "SGI" style. (See comments at the top
* of stl_alloc.h.)
*
* The underlying allocator behaves as follows.
* - __default_alloc_template is used via two typedefs
* - "__single_client_alloc" typedef does no locking for threads
* - "__alloc" typedef is threadsafe via the locks
* - __new_alloc is used for memory requests
*
* (See @link Allocators allocators info @endlink for more.)
*/
template<typename _Tp>
class allocator
{
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef _Tp* pointer;
typedef const _Tp* const_pointer;
typedef _Tp& reference;
typedef const _Tp& const_reference;
typedef _Tp value_type;
template<typename _Tp1>
struct rebind;
allocator() throw();
allocator(const allocator&) throw();
template<typename _Tp1>
allocator(const allocator<_Tp1>&) throw();
~allocator() throw();
pointer
address(reference __x) const;
const_pointer
address(const_reference __x) const;
// NB: __n is permitted to be 0. The C++ standard says nothing
// about what the return value is when __n == 0.
_Tp*
allocate(size_type __n, const void* = 0);
// __p is not permitted to be a null pointer.
void
deallocate(pointer __p, size_type __n);
size_type
max_size() const throw();
void construct(pointer __p, const _Tp& __val);
void destroy(pointer __p);
};
template<>
class allocator<void>
{
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef void* pointer;
typedef const void* const_pointer;
typedef void value_type;
template<typename _Tp1>
struct rebind;
};
} // namespace std

View file

@ -1,5 +1,6 @@
%include <exception.i>
%include <std_container.i>
%include <std_alloc.i>
%include <std_char_traits.i>
%{
@ -8,7 +9,7 @@
namespace std {
template <class _CharT, class _Traits = char_traits<_CharT> >
template <class _CharT, class _Traits = std::char_traits<_CharT>, typename _Alloc = std::allocator<_CharT> >
class basic_string
{
#if !defined(SWIG_STD_MODERN_STL) || defined(SWIG_STD_NOMODERN_STL)
@ -181,7 +182,7 @@ namespace std {
#ifdef %swig_basic_string
// Add swig/language extra methods
%swig_basic_string(std::basic_string<_CharT >);
%swig_basic_string(std::basic_string<_CharT, _Traits, _Alloc >);
#endif
#ifdef SWIG_EXPORT_ITERATOR_METHODS
@ -223,27 +224,27 @@ namespace std {
replace(iterator __i1, iterator __i2, const_iterator __k1, const_iterator __k2);
#endif
std::basic_string<_CharT>& operator +=(const basic_string& v);
basic_string& operator +=(const basic_string& v);
%newobject __add__;
%newobject __radd__;
%extend {
std::basic_string<_CharT>* __add__(const basic_string& v) {
std::basic_string<_CharT>* res = new std::basic_string<_CharT>(*self);
std::basic_string<_CharT,_Traits,_Alloc >* __add__(const basic_string& v) {
std::basic_string<_CharT,_Traits,_Alloc >* res = new std::basic_string<_CharT,_Traits,_Alloc >(*self);
*res += v;
return res;
}
std::basic_string<_CharT>* __radd__(const basic_string& v) {
std::basic_string<_CharT>* res = new std::basic_string<_CharT>(v);
std::basic_string<_CharT,_Traits,_Alloc >* __radd__(const basic_string& v) {
std::basic_string<_CharT,_Traits,_Alloc >* res = new std::basic_string<_CharT,_Traits,_Alloc >(v);
*res += *self;
return res;
}
const std::basic_string<_CharT>& __str__() {
std::basic_string<_CharT,_Traits,_Alloc > __str__() {
return *self;
}
}
std::basic_ostream<_CharT, std::char_traits<_CharT> >&
__rlshift__(std::basic_ostream<_CharT, std::char_traits<_CharT> >& out) {

View file

@ -11,7 +11,7 @@
namespace std
{
// 27.6.2.1 Template class basic_ostream
template<typename _CharT, typename _Traits>
template<typename _CharT, typename _Traits = char_traits<_CharT> >
class basic_ostream : virtual public basic_ios<_CharT, _Traits>
{
public:
@ -33,22 +33,29 @@ namespace std
// 27.6.2.5.3 basic_ostream::operator<<
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& (*__pf)(basic_ostream<_CharT, _Traits>&));
basic_ostream<_CharT, _Traits>&
operator<<(basic_ios<_CharT, _Traits>& (*__pf)(basic_ios<_CharT, _Traits>&));
basic_ostream<_CharT, _Traits>&
operator<<(ios_base& (*__pf) (ios_base&));
// 27.6.2.5.2 Arithmetic Inserters
basic_ostream<_CharT, _Traits>&
operator<<(long __n);
basic_ostream<_CharT, _Traits>&
operator<<(unsigned long __n);
basic_ostream<_CharT, _Traits>&
operator<<(bool __n);
basic_ostream<_CharT, _Traits>&
operator<<(short __n);
@ -56,9 +63,11 @@ namespace std
basic_ostream<_CharT, _Traits>&
operator<<(unsigned short __n);
basic_ostream<_CharT, _Traits>&
operator<<(int __n);
basic_ostream<_CharT, _Traits>&
operator<<(unsigned int __n);
@ -68,6 +77,8 @@ namespace std
basic_ostream<_CharT, _Traits>&
operator<<(unsigned long long __n);
basic_ostream<_CharT, _Traits>&
operator<<(double __f);
@ -77,12 +88,22 @@ namespace std
basic_ostream<_CharT, _Traits>&
operator<<(long double __f);
basic_ostream<_CharT, _Traits>&
operator<<(const void* __p);
basic_ostream<_CharT, _Traits>&
operator<<(basic_streambuf<_CharT, _Traits>* __sb);
%extend {
std::basic_ostream<_CharT, _Traits >&
operator<<(const std::basic_string<_CharT,_Traits, std::allocator<_CharT> >& s)
{
*self << s;
return *self;
}
}
// Unformatted output:
basic_ostream<_CharT, _Traits>&
put(char_type __c);
@ -103,18 +124,10 @@ namespace std
basic_ostream<_CharT, _Traits>&
seekp(off_type, ios_base::seekdir);
%extend {
std::basic_ostream<_CharT, _Traits>&
operator<<(const std::basic_string<_CharT>& s)
{
*self << s;
return *self;
}
}
};
// 27.6.1.1 Template class basic_istream
template<typename _CharT, typename _Traits>
template<typename _CharT, typename _Traits = char_traits<_CharT> >
class basic_istream : virtual public basic_ios<_CharT, _Traits>
{
public:
@ -247,7 +260,7 @@ namespace std
};
// 27.6.1.5 Template class basic_iostream
template<typename _CharT, typename _Traits>
template<typename _CharT, typename _Traits = char_traits<_CharT> >
class basic_iostream
: public basic_istream<_CharT, _Traits>,
public basic_ostream<_CharT, _Traits>
@ -284,15 +297,15 @@ namespace std
extern std::wostream wcerr;
extern std::wostream wclog;
template<typename _CharT, typename _Traits>
template<typename _CharT, typename _Traits = char_traits<_CharT> >
std::basic_ostream<_CharT, _Traits>&
endl(std::basic_ostream<_CharT, _Traits>&);
template<typename _CharT, typename _Traits>
template<typename _CharT, typename _Traits = char_traits<_CharT> >
std::basic_ostream<_CharT, _Traits>&
ends(std::basic_ostream<_CharT, _Traits>&);
template<typename _CharT, typename _Traits>
template<typename _CharT, typename _Traits = char_traits<_CharT> >
std::basic_ostream<_CharT, _Traits>&
flush(std::basic_ostream<_CharT, _Traits>&);
}

179
SWIG/Lib/std/std_sstream.i Normal file
View file

@ -0,0 +1,179 @@
%include <std_alloc.i>
%include <std_basic_string.i>
%include <std_string.i>
%include <std_ios.i>
%include <std_wstring.i>
%include <std_streambuf.i>
%include <std_iostream.i>
%{
#include <sstream>
%}
namespace std
{
template<typename _CharT, typename _Traits = char_traits<_CharT>,
typename _Alloc = allocator<_CharT> >
class basic_stringbuf : public basic_streambuf<_CharT, _Traits>
{
public:
// Types:
typedef _CharT char_type;
typedef _Traits traits_type;
// 251. basic_stringbuf missing allocator_type
typedef _Alloc allocator_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
public:
// Constructors:
explicit
basic_stringbuf(ios_base::openmode __mode = ios_base::in | ios_base::out);
explicit
basic_stringbuf(const basic_string<char_type, _Traits, _Alloc>& __str,
ios_base::openmode __mode = ios_base::in | ios_base::out);
// Get and set:
basic_string<char_type, _Traits, _Alloc>
str() const;
void
str(const basic_string<char_type, _Traits, _Alloc>& __s);
};
// 27.7.2 Template class basic_istringstream
template<typename _CharT, typename _Traits = char_traits<_CharT>,
typename _Alloc = allocator<_CharT> >
class basic_istringstream : public basic_istream<_CharT, _Traits>
{
public:
// Types:
typedef _CharT char_type;
typedef _Traits traits_type;
// 251. basic_stringbuf missing allocator_type
typedef _Alloc allocator_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
public:
// Constructors:
explicit
basic_istringstream(ios_base::openmode __mode = ios_base::in);
explicit
basic_istringstream(const basic_string<char_type, _Traits, _Alloc>& __str,
ios_base::openmode __mode = ios_base::in);
~basic_istringstream();
// Members:
basic_stringbuf<_CharT, _Traits, _Alloc>*
rdbuf() const;
basic_string<char_type, _Traits, _Alloc>
str() const;
void
str(const basic_string<char_type, _Traits, _Alloc>& __s);
};
// 27.7.3 Template class basic_ostringstream
template<typename _CharT, typename _Traits = char_traits<_CharT>,
typename _Alloc = allocator<_CharT> >
class basic_ostringstream : public basic_ostream<_CharT, _Traits>
{
public:
// Types:
typedef _CharT char_type;
typedef _Traits traits_type;
// 251. basic_stringbuf missing allocator_type
typedef _Alloc allocator_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
public:
// Constructors/destructor:
explicit
basic_ostringstream(ios_base::openmode __mode = ios_base::out);
explicit
basic_ostringstream(const basic_string<char_type, _Traits, _Alloc>& __str,
ios_base::openmode __mode = ios_base::out);
~basic_ostringstream();
// Members:
basic_stringbuf<_CharT, _Traits, _Alloc>*
rdbuf() const;
basic_string<char_type, _Traits, _Alloc>
str() const;
#if 0
void
str(const basic_string<char_type, _Traits, _Alloc>& __s);
#endif
};
// 27.7.4 Template class basic_stringstream
template<typename _CharT, typename _Traits = char_traits<_CharT>,
typename _Alloc = allocator<_CharT> >
class basic_stringstream : public basic_iostream<_CharT, _Traits>
{
public:
// Types:
typedef _CharT char_type;
typedef _Traits traits_type;
// 251. basic_stringbuf missing allocator_type
typedef _Alloc allocator_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
public:
// Constructors/destructors
explicit
basic_stringstream(ios_base::openmode __m = ios_base::out | ios_base::in);
explicit
basic_stringstream(const basic_string<char_type, _Traits, _Alloc>& __str,
ios_base::openmode __m = ios_base::out | ios_base::in);
~basic_stringstream();
// Members:
basic_stringbuf<_CharT, _Traits, _Alloc>*
rdbuf() const;
basic_string<char_type, _Traits, _Alloc>
str() const;
void
str(const basic_string<char_type, _Traits, _Alloc>& __s);
};
} // namespace std
namespace std {
%template(istringstream) basic_istringstream<char, char_traits<char>, allocator<char> >;
%template(ostringstream) basic_ostringstream<char, char_traits<char>, allocator<char> >;
%template(stringstream) basic_stringstream<char, char_traits<char>, allocator<char> >;
%template(wistringstream) basic_istringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
%template(wostringstream) basic_ostringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
%template(wstringstream) basic_stringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
}

View file

@ -4,6 +4,9 @@
namespace std
{
%std_comp_methods(basic_string<char>);
typedef basic_string<char> string;
%std_comp_methods(basic_string<char, std::char_traits<char>, std::allocator<char> >);
typedef basic_string<char, std::char_traits<char>, std::allocator<char> > string;
}
%template(string) std::basic_string<char, std::char_traits<char>, std::allocator<char> >;

View file

@ -9,6 +9,8 @@
namespace std
{
%std_comp_methods(basic_string<wchar_t>);
typedef basic_string<wchar_t> wstring;
%std_comp_methods(basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >);
typedef basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > wstring;
}
%template(wstring) std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >;