From 964f56d0d9ba1b4c81e37d12d760da0f0fc5cd61 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 12 Sep 2003 21:13:48 +0000 Subject: [PATCH] Support for std::string and const std::string & git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5105 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Lib/csharp/std_string.i | 60 ++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 SWIG/Lib/csharp/std_string.i diff --git a/SWIG/Lib/csharp/std_string.i b/SWIG/Lib/csharp/std_string.i new file mode 100644 index 000000000..310c01788 --- /dev/null +++ b/SWIG/Lib/csharp/std_string.i @@ -0,0 +1,60 @@ +// +// SWIG typemaps for std::string +// William Fulton +// +// C# implementation +// +/* ------------------------------------------------------------------------ + Typemaps for std::string and const std::string& + These are mapped to a C# String and are passed around by value. + + To use non-const std::string references use the following %apply. Note + that they are passed by value. + %apply const std::string & {std::string &}; + ------------------------------------------------------------------------ */ + +%{ +#include +%} + +namespace std { + +class string; + +// string +%typemap(ctype) string "char *" +%typemap(imtype) string "string" +%typemap(cstype) string "string" + +%typemap(in) string +%{ if (!$input) SWIG_CSharpThrowException(SWIG_CSharpNullReferenceException, "null string"); + $1 = std::string($input); %} +%typemap(out) string %{ $result = SWIG_csharp_string_callback($1.c_str()); %} + +%typemap(csin) string "$csinput" +%typemap(csout) string { + return $imcall; + } + +%typemap(typecheck) string = char *; + +// const string & +%typemap(ctype) const string & "char *" +%typemap(imtype) const string & "string" +%typemap(cstype) const string & "string" + +%typemap(in) const string & +%{ if (!$input) SWIG_CSharpThrowException(SWIG_CSharpNullReferenceException, "null string"); + $1 = new std::string($input); %} +%typemap(out) const string & %{ $result = SWIG_csharp_string_callback($1->c_str()); %} +%typemap(freearg) const string & %{ delete $1; %} + +%typemap(csin) const string & "$csinput" +%typemap(csout) const string & { + return $imcall; + } + +%typemap(typecheck) const string & = char *; + +} +