/* <type name="gpointer" type="gpointer" managed-name="Gpointer" /> */ /* transfer-ownership:none */ static extern IntPtr g_param_spec_get_qdata( /* <type name="ParamSpec" type="GParamSpec*" managed-name="ParamSpec" /> */ /* transfer-ownership:none */ IntPtr pspec, /* <type name="GLib.Quark" type="GQuark" managed-name="GLib.Quark" /> */ /* transfer-ownership:none */ Quark quark);
/// <summary> /// Searches for the enum type corresponding to the given GError domain. /// </summary> /// <returns>EnumInfo representing metadata about domain's enum type, or <c>null</c>.</returns> /// <param name="domain">A GError domain.</param> public static EnumInfo FindByErrorDomain(Quark domain) { IntPtr raw_ret = g_irepository_find_by_error_domain(IntPtr.Zero, domain); EnumInfo ret = BaseInfo.MarshalPtr <EnumInfo> (raw_ret); return(ret); }
/// <summary> /// Gets and sets arbitrary user data associated with this instance. /// </summary> /// <param name="quark"> /// a <see cref="Quark"/>, naming the user data /// </param> public object this[Quark quark] { get { AssertNotDisposed(); var ret = g_param_spec_get_qdata(handle, quark); if (ret == IntPtr.Zero) { return(null); } var gcHandle = (GCHandle)ret; var data = gcHandle.Target; return(data); } set { AssertNotDisposed(); if (value == null) { g_param_spec_set_qdata(handle, quark, IntPtr.Zero); } else { var data_ = (IntPtr)GCHandle.Alloc(value); g_param_spec_set_qdata_full(handle, quark, data_, freeQDataDelegate); } } }
public void quark() { var bytes = Encoders.Hex.DecodeData("01000000000000000000000000000000000000000000000000000000000000000000000027cc0d8f6a20e41f445b1045d1c73ba4b068ee60b5fd4aa34027cbbe5c2e161e1546db5af0ff0f1e18cb3f01"); var hashBytes = new Quark().ComputeBytes(bytes).ToArray(); var hash = Encoders.Hex.EncodeData(hashBytes.Reverse().ToArray()); Assert.Equal("00000f4fb42644a07735beea3647155995ab01cf49d05fdc082c08eb673433f9", hash); }
public void TestImplicitOperator() { uint expected = 1; Quark quark = expected; uint actual = quark; Assert.That(actual, Is.EqualTo(expected)); Utility.AssertNoGLibLog(); }
/// <summary> /// Does nothing if err is NULL; if err is non-NULL, then *err must be NULL. /// A new GError is created and assigned to *err. /// </summary> /// <param name="error">a return location for a GError.</param> /// <param name="domain">error domain.</param> /// <param name="code">error code.</param> /// <param name="message">error message.</param> public static void SetError(IntPtr error, Quark domain, int code, string message) { if (message == null) { throw new ArgumentNullException(nameof(message)); } var messagePtr = StringToUtf8Ptr(message); g_set_error_literal(error, domain, code, messagePtr); Free(messagePtr); }
/// <summary> /// Gets the error domain of an Enum. /// </summary> /// <returns>The error domain.</returns> /// <param name="value">Value.</param> /// <exception cref="ArgumentException"> /// Thrown if type of <paramref name="value"/> is not decorated with /// <see cref="GErrorDomainAttribute"/>. /// </exception> public static Quark GetGErrorDomain(this Enum value) { var type = value.GetType(); var attr = type.GetCustomAttribute <GErrorDomainAttribute> (); if (attr == null) { throw new ArgumentException("Enum type must have ErrorDomainAttribute", nameof(value)); } var quark = Quark.FromString(attr.ErrorDomain); return(quark); }
/* <type name="none" type="void" managed-name="None" /> */ /* transfer-ownership:none */ static extern void g_param_spec_set_qdata_full( /* <type name="ParamSpec" type="GParamSpec*" managed-name="ParamSpec" /> */ /* transfer-ownership:none */ IntPtr pspec, /* <type name="GLib.Quark" type="GQuark" managed-name="GLib.Quark" /> */ /* transfer-ownership:none */ Quark quark, /* <type name="gpointer" type="gpointer" managed-name="Gpointer" /> */ /* transfer-ownership:none */ IntPtr data, /* <type name="GLib.DestroyNotify" type="GDestroyNotify" managed-name="GLib.DestroyNotify" /> */ /* transfer-ownership:none scope:async */ UnmanagedDestroyNotify destroy);
// Function for setting the charge of a quark public virtual void SetParticleCharge(Quark quark) { switch (quark) { case Quark.Up: Charge = 6; break; case Quark.Down: Charge = -3; break; } }
public void TestFromString() { Quark actual; // null always returns 0 actual = Quark.FromString(null); Assert.That(actual, Is.EqualTo(default(Quark))); // this creates a new quark if it does not exist actual = Quark.FromString(testQuarkPrefix + "test-from-string"); Assert.That(actual, Is.Not.EqualTo(default(Quark))); Utility.AssertNoGLibLog(); }
private string DisplayQuarksTable() { StringBuilder str = new StringBuilder(); str.Append("QUARKS"); str.Append("<TABLE BORDER=1 BGCOLOR=#CFCFCF STYLE='COLOR=#000000'>"); str.Append("<TR ALIGN=CENTER BGCOLOR=#AAAAAA STYLE='COLOR=#FFFFFF'>"); str.Append("<TD>SYMBOL</TD>"); str.Append("<TD>FLAVOR</TD>"); str.Append("<TD>SPIN</TD>"); str.Append("<TD>CHARGE</TD>"); str.Append("<TD>T<SUB>Z</SUB></TD>"); str.Append("<TD>Y<SUB>W</SUB></TD>"); str.Append("<TD>I<SUB>Z</SUB></TD>"); str.Append("<TD>Y</TD>"); str.Append("<TD>B</TD>"); str.Append("<TD>C</TD>"); str.Append("<TD>S</TD>"); str.Append("<TD>T</TD>"); str.Append("<TR>"); foreach (Particle particle in particles) { if (particle is Quark) { Quark q = (Quark)particle; str.Append("<TR ALIGN=CENTER BGCOLOR=#EAEAEA>"); str.Append("<TD>" + q.Symbol + "</TD>"); str.Append("<TD>" + q.GetType().Name.Replace("Quark", "") + "</TD>"); str.Append("<TD>" + q.Spin + "</TD>"); str.Append("<TD>" + q.ElectricCharge + "</TD>"); str.Append("<TD>" + q.WeakIsospin + "</TD>"); str.Append("<TD>" + q.WeakHypercharge + "</TD>"); str.Append("<TD>" + q.IsospinZ + "</TD>"); str.Append("<TD>" + q.Hypercharge + "</TD>"); str.Append("<TD>" + q.Bottomness + "</TD>"); str.Append("<TD>" + q.Charmness + "</TD>"); str.Append("<TD>" + q.Strangeness + "</TD>"); str.Append("<TD>" + q.Topness + "</TD>"); str.Append("<TR>"); } } str.Append("</TABLE>"); return(str.ToString()); }
public void TestToString() { string actual; // null always returns 0 actual = default(Quark).ToString(); Assert.That(actual, Is.Null); // undefined quark creates new var quarkString = testQuarkPrefix + "test-to-string"; Assume.That(Quark.TryString(quarkString), Is.EqualTo(default(Quark))); var quark = Quark.FromString(quarkString); Assume.That(quark, Is.Not.EqualTo(default(Quark))); actual = quark.ToString(); Assert.That(actual, Is.EqualTo(quarkString)); Utility.AssertNoGLibLog(); }
public static void Register() { Suite suite = new Suite(); suite.Name = "quark"; suite.SetSetup(delegate() { Quark.Init(); }); suite.SetTeardown(delegate(){ Quark.Free(); }); suite.AddTest("Allocate", test_alloc); suite.AddTest("No-Duplicates", test_dedup); UnitTest_Main.AddSuite(suite); }
public void TestTryString() { Quark actual; var quarkString = testQuarkPrefix + "test-try-string"; // null always returns 0 actual = Quark.TryString(null); Assert.That(actual, Is.EqualTo(default(Quark))); // undefined quark returns 0 actual = Quark.TryString(quarkString); Assert.That(actual, Is.EqualTo(default(Quark))); // defined quark returns value var quark = Quark.FromString(quarkString); actual = Quark.TryString(quarkString); Assert.That(actual, Is.EqualTo(quark)); Utility.AssertNoGLibLog(); }
public static void test_dedup() { Quark q1 = Quark.Add("1-foo"); Quark q2 = Quark.Add("1-foo"); Quark q3 = Quark.Add("1-bar"); if (q1 == null) { Fail("Failed to initialize quark"); } if (q2 == null) { Fail("Failed to initialize quark"); } if (q3 == null) { Fail("Failed to initialize quark"); } if (q1 != q2) { Fail("Allocated an extra quark"); } if (q1.ToString() != q2.ToString()) { Fail("Quark strings do not match"); } if (q1 == q3) { Fail("Incorrectly matched Quarks"); } if (q1.ToString() == q3.ToString()) { Fail("Quarks strings match when they shouldn't"); } Ok(); }
public static void test_alloc() { Quark q1 = Quark.Add("0-foo"); Quark q2 = Quark.Add("0-bar"); Quark q3 = Quark.Add("0-baz"); if (q1 == null) { Fail("Failed to allocate Quark"); } if (q2 == null) { Fail("Failed to allocate Quark"); } if (q3 == null) { Fail("Failed to allocate Quark"); } if (q1.ToString() != "0-foo") { Fail("Failed to allocate Quark"); } if (q2.ToString() != "0-bar") { Fail("Failed to allocate Quark"); } if (q3.ToString() != "0-baz") { Fail("Failed to allocate Quark"); } Ok(); }
/* <type name="gulong" type="gulong" managed-name="Gulong" /> */ /* transfer-ownership:none */ static extern nulong g_signal_handler_find( /* <type name="Object" type="gpointer" managed-name="Object" /> */ /* transfer-ownership:none */ IntPtr instance, /* <type name="SignalMatchType" type="GSignalMatchType" managed-name="SignalMatchType" /> */ /* transfer-ownership:none */ SignalMatchType mask, /* <type name="guint" type="guint" managed-name="Guint" /> */ /* transfer-ownership:none */ uint signalId, /* <type name="GLib.Quark" type="GQuark" managed-name="GLib.Quark" /> */ /* transfer-ownership:none */ Quark detail, /* <type name="Closure" type="GClosure*" managed-name="Closure" /> */ /* transfer-ownership:none nullable:1 allow-none:1 */ IntPtr closure, /* <type name="gpointer" type="gpointer" managed-name="Gpointer" /> */ /* transfer-ownership:none */ IntPtr func, /* <type name="gpointer" type="gpointer" managed-name="Gpointer" /> */ /* transfer-ownership:none */ IntPtr data);
public Hyperon(Quark q1, Quark q2, StrangeQuark s) : base(q1, q2, s) { }
// https://github.com/dogecash/dogecas/blob/master/src/primitives/block.cpp#L19 private static byte[] CalculateHash(byte[] data, int offset, int count) { var h = new Quark().ComputeBytes(data.Skip(offset).Take(count).ToArray()); return(h); }
public void Interact(Quark q) => (Color, q.Color) = (q.Color, Color);
static extern void g_param_spec_set_qdata( IntPtr pspec, Quark quark, IntPtr data);
/* * Allow one item to "absorb" another, assuming they are similar. * * The blending of the "note" field assumes that either (1) one has an * inscription and the other does not, or (2) neither has an inscription. * In both these cases, we can simply use the existing note, unless the * blending object has a note, in which case we use that note. * * The blending of the "discount" field assumes that either (1) one is a * special inscription and one is nothing, or (2) one is a discount and * one is a smaller discount, or (3) one is a discount and one is nothing, * or (4) both are nothing. In all of these cases, we can simply use the * "maximum" of the two "discount" fields. * * These assumptions are enforced by the "object_similar()" code. */ public void absorb(Object j_ptr) { int total = number + j_ptr.number; /* Add together the item counts */ number = (byte)((total < Misc.MAX_STACK_SIZE) ? total : (Misc.MAX_STACK_SIZE - 1)); /* Blend all knowledge */ ident |= (short)(j_ptr.ident & ~IDENT_EMPTY); known_flags.union(j_ptr.known_flags); /* Merge inscriptions */ if (j_ptr.note != null) note = j_ptr.note; /* Combine timeouts for rod stacking */ if (tval == TVal.TV_ROD) timeout += j_ptr.timeout; /* Combine pvals for wands and staves */ if (tval == TVal.TV_WAND || tval == TVal.TV_STAFF || tval == TVal.TV_GOLD) { int tot = pval[Misc.DEFAULT_PVAL] + j_ptr.pval[Misc.DEFAULT_PVAL]; pval[Misc.DEFAULT_PVAL] = (short)(tot >= Misc.MAX_PVAL ? Misc.MAX_PVAL : tot); } /* Combine origin data as best we can */ if (origin != j_ptr.origin || origin_depth != j_ptr.origin_depth || origin_xtra != j_ptr.origin_xtra) { int act = 2; if (origin_xtra != 0 && j_ptr.origin_xtra != 0) { Monster_Race r_ptr = Misc.r_info[origin_xtra]; Monster_Race s_ptr = Misc.r_info[j_ptr.origin_xtra]; bool r_uniq = r_ptr.flags.has(Monster_Flag.UNIQUE.value) ? true : false; bool s_uniq = s_ptr.flags.has(Monster_Flag.UNIQUE.value) ? true : false; if (r_uniq && !s_uniq) act = 0; else if (s_uniq && !r_uniq) act = 1; else act = 2; } switch (act) { /* Overwrite with j_ptr */ case 1: { origin = j_ptr.origin; origin_depth = j_ptr.origin_depth; origin_xtra = j_ptr.origin_xtra; origin = Origin.MIXED; break; } /* Set as "mixed" */ case 2: { origin = Origin.MIXED; break; } } } }
static extern IntPtr g_irepository_find_by_error_domain(IntPtr raw, Quark domain);
/// <summary> /// Does nothing if err is NULL; if err is non-NULL, then *err must be NULL. /// A new GError is created and assigned to *err. /// </summary> /// <param name="error">a return location for a GError.</param> /// <param name="domain">error domain.</param> /// <param name="code">error code.</param> /// <param name="format">error message format string.</param> /// <param name="args">error message format args.</param> public static void SetError(IntPtr error, Quark domain, int code, string format, params object[] args) { SetError(error, domain, code, string.Format(format, args)); }
static extern void g_set_error_literal(IntPtr err, Quark domain, int code, IntPtr message);