Tools and libraries to glue C/C++ APIs to high-level languages
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

69 lines
2.4 KiB

using System;
using System.Text;
using System.Runtime.InteropServices;
using Mono.VisualC.Interop;
namespace Qt.Core {
//TODO: Will this leak?
[StructLayout (LayoutKind.Sequential)]
public unsafe struct QString {
#region Sync with qstring.h
public interface IQString : ICppClass {
void QString(ref QString @this,
[MangleAs (typeof (QChar), Modifiers=CppModifiers.PointerToConst)]
IntPtr unicode, int size);
}
[StructLayout (LayoutKind.Sequential)]
private struct QChar {}
[StructLayout (LayoutKind.Sequential)]
public struct Data {
public int @ref;
public int alloc, size;
public IntPtr data;
public ushort clean;
public ushort simpletext;
public ushort righttoleft;
public ushort asciiCache;
public ushort capacity;
public ushort reserved;
public IntPtr array;
}
public Data* d;
#endregion
private static IQString impl = Qt.Libs.QtCore.GetClass<IQString> ("QString");
public QString (string str)
{
IntPtr strPtr = Marshal.StringToHGlobalUni (str);
impl.QString (ref this, strPtr, str.Length);
Marshal.FreeHGlobal (strPtr);
// TODO: I deref this on construction to let Qt free it when it's done with it.
// My assumption is that this struct will only be used to interop with Qt and
// no managed class is going to hold on to it.
this.DeRef ();
}
public static implicit operator QString (string str)
{
return new QString (str);
}
public QString AddRef ()
{
d->@ref++;
return this;
}
public QString DeRef ()
{
d->@ref--;
return this;
}
}
}