corrections for std::string.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4325 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
5b0895e0d8
commit
88b15ce253
3 changed files with 74 additions and 7 deletions
|
|
@ -20,14 +20,59 @@
|
|||
%}
|
||||
|
||||
namespace std {
|
||||
template <class charT> class basic_string {
|
||||
public:
|
||||
typedef charT *pointer;
|
||||
typedef charT &reference;
|
||||
typedef const charT &const_reference;
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
basic_string();
|
||||
basic_string( charT *str );
|
||||
size_t size();
|
||||
charT operator []( int pos ) const;
|
||||
charT *c_str() const;
|
||||
basic_string<charT> &operator = ( const basic_string &ws );
|
||||
basic_string<charT> &operator = ( const charT *str );
|
||||
basic_string<charT> &append( const basic_string<charT> &other );
|
||||
basic_string<charT> &append( const charT *str );
|
||||
void push_back( charT c );
|
||||
void clear();
|
||||
void reserve( size_type t );
|
||||
void resize( size_type n, charT c = charT() );
|
||||
int compare( const basic_string<charT> &other ) const;
|
||||
int compare( const charT *str ) const;
|
||||
basic_string<charT> &insert( size_type pos,
|
||||
const basic_string<charT> &str );
|
||||
size_type find( const basic_string<charT> &other, int pos = 0 ) const;
|
||||
size_type find( charT c, int pos = 0 ) const;
|
||||
%extend {
|
||||
bool operator == ( const basic_string<charT> &other ) const {
|
||||
return self->compare( other ) == 0;
|
||||
}
|
||||
bool operator != ( const basic_string<charT> &other ) const {
|
||||
return self->compare( other ) != 0;
|
||||
}
|
||||
bool operator < ( const basic_string<charT> &other ) const {
|
||||
return self->compare( other ) == -1;
|
||||
}
|
||||
bool operator > ( const basic_string<charT> &other ) const {
|
||||
return self->compare( other ) == 1;
|
||||
}
|
||||
bool operator <= ( const basic_string<charT> &other ) const {
|
||||
return self->compare( other ) != 1;
|
||||
}
|
||||
bool operator >= ( const basic_string<charT> &other ) const {
|
||||
return self->compare( other ) != -1;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class string;
|
||||
%template(string) basic_string<char>;
|
||||
%template(wstring) basic_string<wchar_t>;
|
||||
|
||||
/* Overloading check */
|
||||
|
||||
%typemap(typecheck) string = char *;
|
||||
%typemap(typecheck) const string & = char *;
|
||||
|
||||
#if 0
|
||||
%typemap(in) string {
|
||||
if (caml_ptr_check($input))
|
||||
$1 = std::string((char *)caml_ptr_val($input,0));
|
||||
|
|
@ -51,5 +96,9 @@ namespace std {
|
|||
%typemap(out) const string & {
|
||||
$result = caml_val_ptr((char *)$1->c_str(),0);
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef basic_string<char> string;
|
||||
typedef basic_string<wchar_t> wstring;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INTEGER) short, signed short, const short &, const signed short & {
|
||||
%typecheck(SWIG_TYPECHECK_INTEGER) short, signed short, const short &, const signed short &, wchar_t {
|
||||
if( !Is_block($input) ) $1 = 0;
|
||||
else {
|
||||
switch( Tag_val($input) ) {
|
||||
|
|
|
|||
|
|
@ -86,7 +86,22 @@
|
|||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
%typemap(ocaml,in) SWIGTYPE {
|
||||
$1 = *(($&1_ltype) caml_ptr_val($input,$descriptor)) ;
|
||||
}
|
||||
|
||||
%typemap(ocaml,out) SWIGTYPE {
|
||||
void *temp = new $ltype($1);
|
||||
value *fromval = caml_named_value("create_$ntype_from_ptr");
|
||||
*(($ltype *)temp) = $1;
|
||||
if( fromval ) {
|
||||
$result = callback(*fromval,caml_val_ptr((void *)temp,$descriptor));
|
||||
} else {
|
||||
$result = caml_val_ptr ((void *)temp,$descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
%typemap(ocaml,in) SWIGTYPE {
|
||||
$1 = *(($&1_ltype) caml_ptr_val($input,$descriptor)) ;
|
||||
|
|
@ -103,6 +118,8 @@
|
|||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Arrays */
|
||||
|
||||
/* Enums */
|
||||
|
|
@ -151,6 +168,7 @@ SIMPLE_MAP(char, caml_val_char, caml_long_val);
|
|||
SIMPLE_MAP(unsigned char, caml_val_uchar, caml_long_val);
|
||||
SIMPLE_MAP(int, caml_val_int, caml_long_val);
|
||||
SIMPLE_MAP(short, caml_val_short, caml_long_val);
|
||||
SIMPLE_MAP(wchar_t, caml_val_short, caml_long_val);
|
||||
SIMPLE_MAP(long, caml_val_long, caml_long_val);
|
||||
SIMPLE_MAP(ptrdiff_t, caml_val_int, caml_long_val);
|
||||
SIMPLE_MAP(unsigned int, caml_val_uint, caml_long_val);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue