1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
|
// Copyright (c) 2011 Novell, Inc.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the Lesser GNU General
// Public License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
using System;
using System.Runtime.InteropServices;
namespace GLib {
public class VariantType : IDisposable {
public static VariantType Boolean = new VariantType ("b");
public static VariantType Byte = new VariantType ("y");
public static VariantType Int16 = new VariantType ("n");
public static VariantType UInt16 = new VariantType ("q");
public static VariantType Int32 = new VariantType ("i");
public static VariantType Uint32 = new VariantType ("u");
public static VariantType Int64 = new VariantType ("x");
public static VariantType UInt64 = new VariantType ("t");
public static VariantType Double = new VariantType ("d");
public static VariantType String = new VariantType ("s");
public static VariantType Path = new VariantType ("o");
public static VariantType Signature = new VariantType ("g");
public static VariantType Variant = new VariantType ("v");
public static VariantType HandleType = new VariantType ("h");
public static VariantType Unit = new VariantType ("()");
public static VariantType Any = new VariantType ("*");
public static VariantType Basic = new VariantType ("?");
public static VariantType Maybe = new VariantType ("m*");
public static VariantType Array = new VariantType ("a*");
public static VariantType Tuple = new VariantType ("r");
public static VariantType DictEntry = new VariantType ("{?*}");
public static VariantType Dictionary = new VariantType ("a{?*}");
public static VariantType StringArray = new VariantType ("as");
public static VariantType ByteString = new VariantType ("ay");
public static VariantType ByteStringArray = new VariantType ("aay");
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern bool g_variant_type_string_is_valid (IntPtr type_string);
public static bool StringIsValid (string type_string)
{
IntPtr native = Marshaller.StringToPtrGStrdup (type_string);
bool ret = g_variant_type_string_is_valid (native);
Marshaller.Free (native);
return ret;
}
private VariantType () {}
IntPtr handle;
public IntPtr Handle {
get { return handle; }
}
// Docs say that GVariant is threadsafe.
~VariantType ()
{
Dispose (false);
}
public void Dispose ()
{
Dispose (true);
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern void g_variant_type_free (IntPtr handle);
void Dispose (bool disposing)
{
if (handle == IntPtr.Zero)
return;
g_variant_type_free (handle);
handle = IntPtr.Zero;
if (disposing)
GC.SuppressFinalize (this);
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_variant_type_copy (IntPtr handle);
public VariantType (IntPtr handle)
{
this.handle = g_variant_type_copy (handle);
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_variant_type_new (IntPtr type_name);
public VariantType (string type_string)
{
IntPtr native = Marshaller.StringToPtrGStrdup (type_string);
handle = g_variant_type_new (native);
Marshaller.Free (native);
}
public VariantType Copy ()
{
return new VariantType (Handle);
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern bool g_variant_type_equals (IntPtr a, IntPtr b);
public override bool Equals (object o)
{
return (o is VariantType) && g_variant_type_equals (Handle, (o as VariantType).Handle);
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern int g_variant_type_hash (IntPtr a);
public override int GetHashCode ()
{
return g_variant_type_hash (Handle);
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_variant_type_peek_string (IntPtr a);
public override string ToString ()
{
return Marshaller.Utf8PtrToString (g_variant_type_peek_string (Handle));
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern bool g_variant_type_is_array (IntPtr type);
public bool IsArray {
get { return g_variant_type_is_array (Handle); }
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern bool g_variant_type_is_basic (IntPtr type);
public bool IsBasic {
get { return g_variant_type_is_basic (Handle); }
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern bool g_variant_type_is_container (IntPtr type);
public bool IsContainer {
get { return g_variant_type_is_container (Handle); }
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern bool g_variant_type_is_definite (IntPtr type);
public bool IsDefinite {
get { return g_variant_type_is_definite (Handle); }
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern bool g_variant_type_is_dict_entry (IntPtr type);
public bool IsDictionaryEntry {
get { return g_variant_type_is_dict_entry (Handle); }
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern bool g_variant_type_is_maybe (IntPtr type);
public bool IsMaybe {
get { return g_variant_type_is_maybe (Handle); }
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern bool g_variant_type_is_tuple (IntPtr type);
public bool IsTuple {
get { return g_variant_type_is_tuple (Handle); }
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern bool g_variant_type_is_variant (IntPtr type);
public bool IsVariant {
get { return g_variant_type_is_variant (Handle); }
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern bool g_variant_type_is_subtype_of (IntPtr type, IntPtr supertype);
public bool IsSubtypeOf (VariantType supertype)
{
return g_variant_type_is_subtype_of (Handle, supertype == null ? IntPtr.Zero : supertype.Handle);
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_variant_type_element (IntPtr type);
public VariantType Element ()
{
return new VariantType (g_variant_type_element (Handle));
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_variant_type_first (IntPtr type);
public VariantType First ()
{
return new VariantType (g_variant_type_first (Handle));
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_variant_type_next (IntPtr type);
public VariantType Next ()
{
return new VariantType (g_variant_type_next (Handle));
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_variant_type_n_items (IntPtr type);
public long NItems ()
{
return g_variant_type_n_items (Handle).ToInt64 ();
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_variant_type_key (IntPtr type);
public VariantType Key ()
{
return new VariantType (g_variant_type_key (Handle));
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_variant_type_value (IntPtr type);
public VariantType Value ()
{
return new VariantType (g_variant_type_value (Handle));
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_variant_type_new_array (IntPtr element);
public static VariantType NewArray (VariantType element)
{
VariantType result = new VariantType ();
result.handle = g_variant_type_new_array (element == null ? IntPtr.Zero : element.Handle);
return result;
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_variant_type_new_dict_entry (IntPtr key, IntPtr value);
public static VariantType NewDictionaryEntry (VariantType key, VariantType value)
{
VariantType result = new VariantType ();
result.handle = g_variant_type_new_dict_entry (key == null ? IntPtr.Zero : key.Handle, value == null ? IntPtr.Zero : value.Handle);
return result;
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_variant_type_new_maybe (IntPtr element);
public static VariantType NewMaybe (VariantType element)
{
VariantType result = new VariantType ();
result.handle = g_variant_type_new_maybe (element == null ? IntPtr.Zero : element.Handle);
return result;
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_variant_type_new_tuple (IntPtr[] items, int n_items);
public static VariantType NewTuple (VariantType[] items)
{
VariantType result = new VariantType ();
IntPtr[] native = new IntPtr [items.Length];
for (int i = 0; i < items.Length; i++)
native [i] = items [i].Handle;
result.handle = g_variant_type_new_tuple (native, native.Length);
return result;
}
}
}
|