[Ocaml] Apply patch #3151788 from Joel Reymont. Brings Ocaml support a up to date (ver 3.11 and 3.12), including std::string.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12460 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
7d700cc999
commit
1fab53b204
9 changed files with 240 additions and 245 deletions
|
|
@ -11,141 +11,91 @@
|
|||
// However, I think I'll wait until someone asks for it...
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
%include <exception.i>
|
||||
|
||||
%{
|
||||
#include <string>
|
||||
#include <vector>
|
||||
using std::string;
|
||||
using std::vector;
|
||||
%}
|
||||
|
||||
|
||||
%include <exception.i>
|
||||
%include <std_vector.i>
|
||||
|
||||
%naturalvar std::string;
|
||||
%naturalvar std::wstring;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
%template(string) basic_string<char>;
|
||||
%template(wstring) basic_string<wchar_t>;
|
||||
typedef basic_string<char> string;
|
||||
typedef basic_string<wchar_t> wstring;
|
||||
%naturalvar string;
|
||||
%naturalvar wstring;
|
||||
|
||||
class string;
|
||||
class wstring;
|
||||
|
||||
/* Overloading check */
|
||||
%typemap(in) string {
|
||||
/* %typemap(in) string */
|
||||
if (caml_ptr_check($input))
|
||||
$1.assign((char *)caml_ptr_val($input,0), caml_string_len($input));
|
||||
else
|
||||
SWIG_exception(SWIG_TypeError, "string expected");
|
||||
}
|
||||
|
||||
/* Overloading check */
|
||||
%typemap(in) string {
|
||||
if (caml_ptr_check($input))
|
||||
$1.assign((char *)caml_ptr_val($input,0),
|
||||
caml_string_len($input));
|
||||
else
|
||||
SWIG_exception(SWIG_TypeError, "string expected");
|
||||
}
|
||||
%typemap(in) const string & (std::string temp) {
|
||||
/* %typemap(in) const string & */
|
||||
if (caml_ptr_check($input)) {
|
||||
temp.assign((char *)caml_ptr_val($input,0), caml_string_len($input));
|
||||
$1 = &temp;
|
||||
} else {
|
||||
SWIG_exception(SWIG_TypeError, "string expected");
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(in) const string & (std::string temp) {
|
||||
if (caml_ptr_check($input)) {
|
||||
temp.assign((char *)caml_ptr_val($input,0),
|
||||
caml_string_len($input));
|
||||
$1 = &temp;
|
||||
} else {
|
||||
SWIG_exception(SWIG_TypeError, "string expected");
|
||||
}
|
||||
}
|
||||
%typemap(in) string & (std::string temp) {
|
||||
/* %typemap(in) string & */
|
||||
if (caml_ptr_check($input)) {
|
||||
temp.assign((char *)caml_ptr_val($input,0), caml_string_len($input));
|
||||
$1 = &temp;
|
||||
} else {
|
||||
SWIG_exception(SWIG_TypeError, "string expected");
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(in) string & (std::string temp) {
|
||||
if (caml_ptr_check($input)) {
|
||||
temp.assign((char *)caml_ptr_val($input,0),
|
||||
caml_string_len($input));
|
||||
$1 = &temp;
|
||||
} else {
|
||||
SWIG_exception(SWIG_TypeError, "string expected");
|
||||
}
|
||||
}
|
||||
%typemap(in) string * (std::string *temp) {
|
||||
/* %typemap(in) string * */
|
||||
if (caml_ptr_check($input)) {
|
||||
temp = new std::string((char *)caml_ptr_val($input,0), caml_string_len($input));
|
||||
$1 = temp;
|
||||
} else {
|
||||
SWIG_exception(SWIG_TypeError, "string expected");
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(in) string * (std::string *temp) {
|
||||
if (caml_ptr_check($input)) {
|
||||
temp = new std::string((char *)caml_ptr_val($input,0),
|
||||
caml_string_len($input));
|
||||
$1 = temp;
|
||||
} else {
|
||||
SWIG_exception(SWIG_TypeError, "string expected");
|
||||
}
|
||||
}
|
||||
%typemap(free) string * (std::string *temp) {
|
||||
delete temp;
|
||||
}
|
||||
|
||||
%typemap(free) string * (std::string *temp) {
|
||||
delete temp;
|
||||
}
|
||||
%typemap(argout) string & {
|
||||
/* %typemap(argout) string & */
|
||||
swig_result = caml_list_append(swig_result,caml_val_string_len((*$1).c_str(), (*$1).size()));
|
||||
}
|
||||
|
||||
%typemap(argout) string & {
|
||||
caml_list_append(swig_result,caml_val_string_len((*$1).c_str(),
|
||||
(*$1).size()));
|
||||
}
|
||||
%typemap(directorout) string {
|
||||
/* %typemap(directorout) string */
|
||||
$result.assign((char *)caml_ptr_val($input,0), caml_string_len($input));
|
||||
}
|
||||
|
||||
%typemap(directorout) string {
|
||||
$result.assign((char *)caml_ptr_val($input,0),
|
||||
caml_string_len($input));
|
||||
}
|
||||
%typemap(out) string {
|
||||
/* %typemap(out) string */
|
||||
$result = caml_val_string_len($1.c_str(),$1.size());
|
||||
}
|
||||
|
||||
%typemap(out) string {
|
||||
$result = caml_val_string_len($1.c_str(),$1.size());
|
||||
}
|
||||
|
||||
%typemap(out) string * {
|
||||
%typemap(out) string * {
|
||||
/* %typemap(out) string * */
|
||||
$result = caml_val_string_len((*$1).c_str(),(*$1).size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_CHARPTR_ARRAY
|
||||
char **c_charptr_array( const std::vector <string > &str_v );
|
||||
char **c_charptr_array( const std::vector <std::string > &str_v );
|
||||
|
||||
%{
|
||||
SWIGEXT char **c_charptr_array( const std::vector <string > &str_v ) {
|
||||
SWIGEXT char **c_charptr_array( const std::vector <std::string > &str_v ) {
|
||||
char **out = new char *[str_v.size() + 1];
|
||||
out[str_v.size()] = 0;
|
||||
for( int i = 0; i < str_v.size(); i++ ) {
|
||||
|
|
@ -157,7 +107,7 @@ char **c_charptr_array( const std::vector <string > &str_v );
|
|||
#endif
|
||||
|
||||
#ifdef ENABLE_STRING_VECTOR
|
||||
%template (StringVector) std::vector<string >;
|
||||
%template (StringVector) std::vector<std::string >;
|
||||
|
||||
%insert(ml) %{
|
||||
(* Some STL convenience items *)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue