PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/otp.net/Otp/Erlang/Object.cs

https://github.com/gebi/jungerl
C# | 121 lines | 58 code | 9 blank | 54 comment | 1 complexity | 381ef708c6bfd5682f20c2dc4d0e047b MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, AGPL-1.0
  1. /*``The contents of this file are subject to the Erlang Public License,
  2. * Version 1.1, (the "License"); you may not use this file except in
  3. * compliance with the License. You should have received a copy of the
  4. * Erlang Public License along with this software. If not, it can be
  5. * retrieved via the world wide web at http://www.erlang.org/.
  6. *
  7. * Software distributed under the License is distributed on an "AS IS"
  8. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  9. * the License for the specific language governing rights and limitations
  10. * under the License.
  11. *
  12. * The Initial Developer of the Original Code is Ericsson Utvecklings AB.
  13. * Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
  14. * AB. All Rights Reserved.''
  15. *
  16. * Converted from Java to C# by Vlad Dumitrescu (vlad_Dumitrescu@hotmail.com)
  17. */
  18. namespace Otp.Erlang
  19. {
  20. using System;
  21. /*
  22. * Base class of the Erlang data type classes. This class is used to
  23. * represent an arbitrary Erlang term.
  24. **/
  25. [Serializable]
  26. public abstract class Object : Amir_Harel.Cloning.BaseObject
  27. {
  28. public static Erlang.Object Format(
  29. string fmt, params object[] args)
  30. {
  31. int pos = 0, argc = 0;
  32. return Formatter.create(fmt.ToCharArray(), ref pos, ref argc, args);
  33. }
  34. public T Cast<T>() where T: Erlang.Object
  35. {
  36. if (!(this is T))
  37. throw new CastException();
  38. return (T)(this);
  39. }
  40. /*
  41. * Convert the object according to the rules of the Erlang external
  42. * format. This is mainly used for sending Erlang terms in messages,
  43. * however it can also be used for storing terms to disk.
  44. *
  45. * @param buf an output stream to which the encoded term should be
  46. * written.
  47. **/
  48. public abstract void encode(OtpOutputStream buf);
  49. /*
  50. * Read binary data in the Erlang external format, and produce a
  51. * corresponding Erlang data type object. This method is normally
  52. * used when Erlang terms are received in messages, however it
  53. * can also be used for reading terms from disk.
  54. *
  55. * @param buf an input stream containing one or more encoded Erlang
  56. * terms.
  57. *
  58. * @return an object representing one of the Erlang data
  59. * types.
  60. *
  61. * @exception DecodeException if the stream does not
  62. * contain a valid representation of an Erlang term.
  63. **/
  64. public static Object decode(OtpInputStream buf)
  65. {
  66. return buf.read_any();
  67. }
  68. public virtual bool subst(ref Erlang.Object term, Erlang.VarBind binding)
  69. {
  70. return false;
  71. }
  72. public virtual bool match(Erlang.Object pattern, Erlang.VarBind binding)
  73. {
  74. return (pattern is Erlang.Var) ? pattern.match(this, binding) : this.Equals(pattern);
  75. }
  76. /*
  77. * Determine if two Erlang objects are equal. In general, Erlang
  78. * objects are equal if the components they consist of are equal.
  79. *
  80. * @param o the object to compare to.
  81. *
  82. * @return true if the objects are identical.
  83. **/
  84. //public abstract bool Equals(System.Object o);
  85. public virtual System.Object clone()
  86. {
  87. try
  88. {
  89. return base.Clone();
  90. }
  91. catch (System.Exception e)
  92. {
  93. /*cannot happen */
  94. throw new System.ApplicationException(e.ToString());
  95. }
  96. }
  97. public long longValue() { return this.Cast<Long>().longValue(); }
  98. public int intValue() { return this.Cast<Long>().intValue(); }
  99. public short shortValue() { return this.Cast<Long>().shortValue(); }
  100. public double doubleValue() { return this.Cast<Double>().doubleValue(); }
  101. public string atomValue() { return this.Cast<Atom>().atomValue(); }
  102. public string stringValue() { return this.Cast<String>().stringValue(); }
  103. public char charValue() { return this.Cast<Char>().charValue(); }
  104. public bool boolValue() { return this.Cast<Boolean>().booleanValue(); }
  105. public byte[] binaryValue() { return this.Cast<Binary>().binaryValue(); }
  106. public Pid pidValue() { return this.Cast<Pid>().pidValue(); }
  107. public Port portValue() { return this.Cast<Port>().portValue(); }
  108. public Ref refValue() { return this.Cast<Ref>().refValue(); }
  109. public Tuple tupleValue() { return this.Cast<Tuple>().tupleValue(); }
  110. public List listValue() { return this.Cast<List>().listValue(); }
  111. }
  112. }