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

Language C# Lines 121
MD5 Hash 381ef708c6bfd5682f20c2dc4d0e047b Estimated Cost $1,359 (why?)
Repository git://github.com/gebi/jungerl.git View Raw File View Project SPDX
  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
/*``The contents of this file are subject to the Erlang Public License,
* Version 1.1, (the "License"); you may not use this file except in
* compliance with the License. You should have received a copy of the
* Erlang Public License along with this software. If not, it can be
* retrieved via the world wide web at http://www.erlang.org/.
* 
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
* 
* The Initial Developer of the Original Code is Ericsson Utvecklings AB.
* Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
* AB. All Rights Reserved.''
* 
 * Converted from Java to C# by Vlad Dumitrescu (vlad_Dumitrescu@hotmail.com)
*/
namespace Otp.Erlang
{
	using System;
	
	/*
	* Base class of the Erlang data type classes. This class is used to
	* represent an arbitrary Erlang term.
	**/
	[Serializable]
    public abstract class Object : Amir_Harel.Cloning.BaseObject
	{
        public static Erlang.Object Format(
            string fmt, params object[] args)
        {
            int pos = 0, argc = 0;
            return Formatter.create(fmt.ToCharArray(), ref pos, ref argc, args);
        }

        public T Cast<T>() where T: Erlang.Object
        {
            if (!(this is T))
                throw new CastException();
            return (T)(this);
        }

		/*
		* Convert the object according to the rules of the Erlang external
		* format. This is mainly used for sending Erlang terms in messages,
		* however it can also be used for storing terms to disk.
		*
		* @param buf an output stream to which the encoded term should be
		* written.
		**/
		public abstract void  encode(OtpOutputStream buf);
		
		/*
		* Read binary data in the Erlang external format, and produce a
		* corresponding Erlang data type object. This method is normally
		* used when Erlang terms are received in messages, however it
		* can also be used for reading terms from disk.
		*
		* @param buf an input stream containing one or more encoded Erlang
		* terms.
		*
		* @return an object representing one of the Erlang data
		* types.
		*
		* @exception DecodeException if the stream does not
		* contain a valid representation of an Erlang term.
		**/
		public static Object decode(OtpInputStream buf)
		{
			return buf.read_any();
		}
		
        public virtual bool subst(ref Erlang.Object term, Erlang.VarBind binding)
        {
            return false;
        }

        public virtual bool match(Erlang.Object pattern, Erlang.VarBind binding)
        {
            return (pattern is Erlang.Var) ? pattern.match(this, binding) : this.Equals(pattern);
        }

		/*
		* Determine if two Erlang objects are equal. In general, Erlang
		* objects are equal if the components they consist of are equal.
		*
		* @param o the object to compare to.
		*
		* @return true if the objects are identical.
		**/
		//public abstract bool Equals(System.Object o);

		public virtual System.Object clone()
		{
			try
			{
				return base.Clone();
			}
			catch (System.Exception e)
			{
				/*cannot happen */
				throw new System.ApplicationException(e.ToString());
			}
		}

        public long     longValue()     { return this.Cast<Long>().longValue(); }
        public int      intValue()      { return this.Cast<Long>().intValue(); }
        public short    shortValue()    { return this.Cast<Long>().shortValue(); }
        public double   doubleValue()   { return this.Cast<Double>().doubleValue(); }
        public string   atomValue()     { return this.Cast<Atom>().atomValue(); }
        public string   stringValue()   { return this.Cast<String>().stringValue(); }
        public char     charValue()     { return this.Cast<Char>().charValue(); }
        public bool     boolValue()     { return this.Cast<Boolean>().booleanValue(); }
        public byte[]   binaryValue()   { return this.Cast<Binary>().binaryValue(); }
        public Pid      pidValue()      { return this.Cast<Pid>().pidValue(); }
        public Port     portValue()     { return this.Cast<Port>().portValue(); }
        public Ref      refValue()      { return this.Cast<Ref>().refValue(); }
        public Tuple    tupleValue()    { return this.Cast<Tuple>().tupleValue(); }
        public List     listValue()     { return this.Cast<List>().listValue(); }
	}
}
Back to Top