~ubuntu-branches/ubuntu/intrepid/tomboy/intrepid

« back to all changes in this revision

Viewing changes to Tomboy/dbus-sharp/Double.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2008-05-20 11:05:10 UTC
  • mfrom: (1.1.38 upstream) (2.1.56 hardy)
  • Revision ID: james.westby@ubuntu.com-20080520110510-y075w3uklbdb0ei3
Tags: 0.10.2-1
New upstream bugfix release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
using System;
2
 
using System.Runtime.InteropServices;
3
 
using System.Reflection.Emit;
4
 
 
5
 
using DBus;
6
 
 
7
 
namespace DBus.DBusType
8
 
{
9
 
  /// <summary>
10
 
  /// IEEE 754 double
11
 
  /// </summary>
12
 
  public class Double : IDBusType
13
 
  {
14
 
    public const char Code = 'd';
15
 
    private System.Double val;
16
 
    
17
 
    private Double()
18
 
    {
19
 
    }
20
 
    
21
 
    public Double(System.Double val, Service service) 
22
 
    {
23
 
      this.val = val;
24
 
    }
25
 
 
26
 
    public Double(IntPtr iter, Service service)
27
 
    {
28
 
      dbus_message_iter_get_basic (iter, out this.val);
29
 
    }
30
 
    
31
 
    public void Append(IntPtr iter)
32
 
    {
33
 
      if (!dbus_message_iter_append_basic (iter, (int) Code, ref val))
34
 
        throw new ApplicationException("Failed to append DOUBLE argument:" + val);
35
 
    }
36
 
 
37
 
    public static bool Suits(System.Type type) 
38
 
    {
39
 
      switch (type.ToString()) {
40
 
      case "System.Double":
41
 
      case "System.Double&":
42
 
        return true;
43
 
      }
44
 
      
45
 
      return false;
46
 
    }
47
 
 
48
 
    public static void EmitMarshalIn(ILGenerator generator, Type type)
49
 
    {
50
 
      if (type.IsByRef) {
51
 
        generator.Emit(OpCodes.Ldind_R8);
52
 
      }
53
 
    }
54
 
 
55
 
    public static void EmitMarshalOut(ILGenerator generator, Type type, bool isReturn) 
56
 
    {
57
 
      generator.Emit(OpCodes.Unbox, type);
58
 
      generator.Emit(OpCodes.Ldind_R8);
59
 
      if (!isReturn) {
60
 
        generator.Emit(OpCodes.Stind_R8);
61
 
      }
62
 
    }
63
 
    
64
 
    public object Get() 
65
 
    {
66
 
      return this.val;
67
 
    }
68
 
 
69
 
    public object Get(System.Type type)
70
 
    {
71
 
      switch (type.ToString()) {
72
 
      case "System.Double":
73
 
      case "System.Double&":
74
 
        return this.val;
75
 
      default:
76
 
        throw new ArgumentException("Cannot cast DBus.Type.Double to type '" + type.ToString() + "'");
77
 
      }
78
 
    }
79
 
 
80
 
    [DllImport("dbus-1")]
81
 
    private extern static void dbus_message_iter_get_basic (IntPtr iter, out double value);
82
 
 
83
 
    [DllImport("dbus-1")]
84
 
    private extern static bool dbus_message_iter_append_basic (IntPtr iter, int type, ref double value);
85
 
  }
86
 
}