Hi all.
I have been struggling with a problem for a while now.

I have been looking through documentation, existing examples, surfing the web etc. but the answer escapes me on this one.

Now assume I have my own string class (its an example, I'm not avoiding std::string, its just that we have a special string class and this example illustrates what we need, but its not the actual implementation).
Ok assume I have MyString.h:


#include <string.h>
#include <iostream>

namespace N
{
† class MyString
† {
† public:
† † MyString() {}
† † MyString(const char *str) { m_string = str; }
† † MyString(const std::string& str) { m_string = str; }
† † MyString(const MyString& other) { m_string = other.m_string; }
† ††
† † ~MyString() {}
† † const char *c_str() const { return m_string.c_str(); }
† † char operator[] (size_t index) const { return m_string[index]; }
† protected:
† † double m_buf[128]; // just some extra data
† † std::string m_string;
† † double m_buf2[128];
† };

† class Stuff {
† public:
† † Stuff() { std::cerr << "Stuff::Stuff" << std::endl; }
† † ~Stuff() { std::cerr << "Stuff::~Stuff" << std::endl; }
† † void setName( const MyString& name) {m_name = name; †std::cerr << "setName: " << m_name.c_str() << std::endl; }
† † const MyString& getName( ) const { return m_name; }
† private:
† † MyString m_name;
† };
}
#endif†

It contains a class Mystring and Mystuff.
In c# I really want to avoid using MyString, I want to use System.String all over the place (to comply with C#).

† † † N.Stuff stuff = new agx.Stuff();
† † † stuff.setName("yoh");
† † † System.String ss = stuff.getName();
† † † Console.WriteLine("Name: {0}", ss);

My swigfile:

%module N

%include "std_string.i"
%include "typemaps.i"

%{
†#include "MyString.h"
%}

%include "MyString.h"

Now this obviously is not enough, but I have spent considerable time on typemap's with csin, csout etc, looking at std_string.i etc, but with no luck.
I thought about trying to tell SWIG that MyString and std::string is the same thing, but as you can see I have added m_buf, m_buf2 to this, illustrating that returning by reference, static cast etc does (of course) not work.

So anyone that can give me a hint on this?†


--
__________________________________________
Anders Backman, HPC2N
90187 UmeŚ University, Sweden
anders@cs.umu.se http://www.hpc2n.umu.se
Cell: +46-70-392 64 67