Example #1
0
        /// <summary> SetIntFromAny -> TclInteger.setIntegerFromAny
        ///
        /// Called to convert the other object's internal rep to this type.
        ///
        /// </summary>
        /// <param name="interp">current interpreter.
        /// </param>
        /// <param name="forIndex">true if this methid is called by getForIndex.
        /// </param>
        /// <param name="tobj">the TclObject to convert to use the
        /// representation provided by this class.
        /// </param>

        private static void  setIntegerFromAny(Interp interp, TclObject tobj)
        {
            InternalRep rep = tobj.InternalRep;

            if (rep is TclInteger)
            {
                // Do nothing.
            }
            else if (rep is TclBoolean)
            {
                bool b = TclBoolean.get(interp, tobj);
                if (b)
                {
                    tobj.InternalRep = new TclInteger(1);
                }
                else
                {
                    tobj.InternalRep = new TclInteger(0);
                }
            }
            else
            {
                // (ToDo) other short-cuts
                tobj.InternalRep = new TclInteger(interp, tobj.ToString());
            }
        }
Example #2
0
        /// <summary> Called to convert the other object's internal rep to a ByteArray.
        ///
        /// </summary>
        /// <param name="interp">current interpreter.
        /// </param>
        /// <param name="tobj">the TclObject to convert to use the ByteArray internal rep.
        /// </param>
        /// <exception cref=""> TclException if the object doesn't contain a valid ByteArray.
        /// </exception>
        internal static void setByteArrayFromAny(Interp interp, TclObject tobj)
        {
            InternalRep rep = tobj.InternalRep;

            if (!(rep is TclByteArray))
            {
                char[] c = tobj.ToString().ToCharArray();
                tobj.InternalRep = new TclByteArray(c);
            }
        }
Example #3
0
 /// <summary> Creates a TclObject with the given InternalRep and stringRep.
 /// This constructor is used by the TclString class only. No other place
 /// should call this constructor.
 ///
 /// </summary>
 /// <param name="rep">the initial InternalRep for this object.
 /// </param>
 /// <param name="s">the initial string rep for this object.
 /// </param>
 protected internal TclObject(TclString rep, string s)
 {
     if (rep == null)
     {
         throw new TclRuntimeError("null InternalRep");
     }
     internalRep = rep;
     stringRep   = s;
     refCount    = 0;
 }
Example #4
0
 /// <summary> Creates a TclObject with the given InternalRep. This method should be
 /// called only by an InternalRep implementation.
 ///
 /// </summary>
 /// <param name="rep">the initial InternalRep for this object.
 /// </param>
 public TclObject(InternalRep rep)
 {
     if (rep == null)
     {
         throw new TclRuntimeError("null InternalRep");
     }
     internalRep = rep;
     stringRep   = null;
     refCount    = 0;
 }
Example #5
0
 /// <summary> Creates a TclObject with the given InternalRep. This method should be
 /// called only by an InternalRep implementation.
 ///
 /// </summary>
 /// <param name="rep">the initial InternalRep for this object.
 /// </param>
 public TclObject(InternalRep rep)
 {
     if (rep == null)
     {
         throw new TclRuntimeError("null InternalRep");
     }
     internalRep = rep;
     stringRep   = null;
     refCount    = 0;
     typePtr     = rep.GetType().Name.Replace("Tcl", "");
 }
Example #6
0
        /// <summary> Called to convert the other object's internal rep to list.
        ///
        /// </summary>
        /// <param name="interp">current interpreter.
        /// </param>
        /// <param name="tobj">the TclObject to convert to use the List internal rep.
        /// </param>
        /// <exception cref=""> TclException if the object doesn't contain a valid list.
        /// </exception>
        internal static void setListFromAny(Interp interp, TclObject tobj)
        {
            InternalRep rep = tobj.InternalRep;

            if (!(rep is TclList))
            {
                TclList tlist = new TclList();

                splitList(interp, tlist.vector, tobj.ToString());
                tobj.InternalRep = tlist;
            }
        }
Example #7
0
        /// <summary> _release
        ///
        /// Private implementation of preserve() method.
        /// This method will be invoked from Native code
        /// to change the TclObject's ref count without
        /// effecting the ref count of a CObject.
        /// </summary>
        private void _release()
        {
            refCount--;
            if (refCount <= 0)
            {
                internalRep.dispose();

                // Setting these to null will ensure that any attempt to use
                // this object will result in a Java NullPointerException.

                internalRep = null;
                stringRep   = null;
            }
        }
Example #8
0
        /// <summary> Changes the long value of the object.
        ///
        /// </summary>
        /// <param name="interp">current interpreter.
        /// </param>
        /// <param name="tobj">the object to operate on.
        /// @paran i the new long value.
        /// </param>
        public static void set(TclObject tobj, long i)
        {
            tobj.invalidateStringRep();
            InternalRep rep = tobj.InternalRep;
            TclLong     tlong;

            if (rep is TclLong)
            {
                tlong       = (TclLong)rep;
                tlong.value = i;
            }
            else
            {
                tobj.InternalRep = new TclLong(i);
            }
        }
Example #9
0
        /// <summary> Changes the object value of the object.
        ///
        /// </summary>
        /// <param name="interp">current interpreter.
        /// </param>
        /// <param name="tobj">the object to operate on.
        /// @paran i the new object value.
        /// </param>
        public static void set(TclObject tobj, object o)
        {
            tobj.invalidateStringRep();
            InternalRep rep = tobj.InternalRep;
            TclObj      tint;

            if (rep is TclObj)
            {
                tint       = (TclObj)rep;
                tint.value = o;
            }
            else
            {
                tobj.InternalRep = new TclObj(o);
            }
        }
Example #10
0
        public static void  set(TclObject tobj, double d)
        // The new value for the object.
        {
            tobj.invalidateStringRep();
            InternalRep rep = tobj.InternalRep;

            if (rep is TclDouble)
            {
                TclDouble tdouble = (TclDouble)rep;
                tdouble.value = d;
            }
            else
            {
                tobj.InternalRep = new TclDouble(d);
            }
        }
Example #11
0
        /// <summary> Changes the integer value of the object.
        ///
        /// </summary>
        /// <param name="interp">current interpreter.
        /// </param>
        /// <param name="tobj">the object to operate on.
        /// @paran i the new integer value.
        /// </param>
        public static void  set(TclObject tobj, int i)
        {
            tobj.invalidateStringRep();
            InternalRep rep = tobj.InternalRep;
            TclInteger  tint;

            if (rep is TclInteger)
            {
                tint       = (TclInteger)rep;
                tint.value = i;
            }
            else
            {
                tobj.InternalRep = new TclInteger(i);
            }
        }
Example #12
0
        public static double get(Interp interp, TclObject tobj)
        {
            InternalRep rep = tobj.InternalRep;
            TclDouble   tdouble;

            if (!(rep is TclDouble))
            {
                setDoubleFromAny(interp, tobj);
                tdouble = (TclDouble)(tobj.InternalRep);
            }
            else
            {
                tdouble = (TclDouble)rep;
            }

            return(tdouble.value);
        }
Example #13
0
        private static void  setDoubleFromAny(Interp interp, TclObject tobj)
        {
            InternalRep rep = tobj.InternalRep;

            if (rep is TclDouble)
            {
                /*
                 * Do nothing.
                 */
            }
            else if (rep is TclBoolean)
            {
                /*
                 * Short-cut.
                 */

                bool b = TclBoolean.get(interp, tobj);
                if (b)
                {
                    tobj.InternalRep = new TclDouble(1.0);
                }
                else
                {
                    tobj.InternalRep = new TclDouble(0.0);
                }
            }
            else if (rep is TclInteger)
            {
                /*
                 * Short-cut.
                 */

                int i = TclInteger.get(interp, tobj);
                tobj.InternalRep = new TclDouble(i);
            }
            else
            {
                tobj.InternalRep = new TclDouble(interp, tobj.ToString());
            }
        }
Example #14
0
        /// <summary> Called to convert the other object's internal rep to boolean.
        ///
        /// </summary>
        /// <param name="interp">current interpreter.
        /// </param>
        /// <param name="tobj">the TclObject to convert to use the
        /// representation provided by this class.
        /// </param>
        private static void  setBooleanFromAny(Interp interp, TclObject tobj)
        {
            InternalRep rep = tobj.InternalRep;

            if (rep is TclBoolean)
            {
                /*
                 * Do nothing.
                 */
            }
            else if (rep is TclInteger)
            {
                int i = TclInteger.get(interp, tobj);
                tobj.InternalRep = new TclBoolean(i != 0);
            }
            else
            {
                /*
                 * (ToDo) other short-cuts
                 */
                tobj.InternalRep = new TclBoolean(interp, tobj.ToString());
            }
        }
Example #15
0
        /// <summary> Tcl_GetIndexFromObj -> get
        ///
        /// Gets the index into the table of the object.  Generate an error
        /// it it doesn't occur.  This also converts the object to an index
        /// which should catch the lookup for speed improvement.
        ///
        /// </summary>
        /// <param name="interp">the interperter or null
        /// </param>
        /// <param name="tobj">the object to operate on.
        /// @paran table the list of commands
        /// @paran msg used as part of any error messages
        /// @paran flags may be TCL.EXACT.
        /// </param>

        public static int get(Interp interp, TclObject tobj, string[] table, string msg, int flags)
        {
            InternalRep rep = tobj.InternalRep;

            if (rep is TclIndex)
            {
                if (((TclIndex)rep).table == table)
                {
                    return(((TclIndex)rep).index);
                }
            }

            string str       = tobj.ToString();
            int    strLen    = str.Length;
            int    tableLen  = table.Length;
            int    index     = -1;
            int    numAbbrev = 0;

            {
                if (strLen > 0)
                {
                    for (int i = 0; i < tableLen; i++)
                    {
                        string option = table[i];

                        if (((flags & TCL.EXACT) == TCL.EXACT) && (option.Length != strLen))
                        {
                            continue;
                        }
                        if (option.Equals(str))
                        {
                            // Found an exact match already. Return it.

                            index = i;
                            goto checking_brk;
                        }
                        if (option.StartsWith(str))
                        {
                            numAbbrev++;
                            index = i;
                        }
                    }
                }
                if (numAbbrev != 1)
                {
                    System.Text.StringBuilder sbuf = new System.Text.StringBuilder();
                    if (numAbbrev > 1)
                    {
                        sbuf.Append("ambiguous ");
                    }
                    else
                    {
                        sbuf.Append("bad ");
                    }
                    sbuf.Append(msg);
                    sbuf.Append(" \"");
                    sbuf.Append(str);
                    sbuf.Append("\"");
                    sbuf.Append(": must be ");
                    sbuf.Append(table[0]);
                    for (int i = 1; i < tableLen; i++)
                    {
                        if (i == (tableLen - 1))
                        {
                            sbuf.Append((i > 1)?", or ":" or ");
                        }
                        else
                        {
                            sbuf.Append(", ");
                        }
                        sbuf.Append(table[i]);
                    }
                    throw new TclException(interp, sbuf.ToString());
                }
            }
            checking_brk :;
            // Create a new index object.
            tobj.InternalRep = new TclIndex(index, table);
            return(index);
        }
Example #16
0
		/// <summary> _release
		/// 
		/// Private implementation of preserve() method.
		/// This method will be invoked from Native code
		/// to change the TclObject's ref count without
		/// effecting the ref count of a CObject.
		/// </summary>
		private void  _release()
		{
			refCount--;
			if (refCount <= 0)
			{
				internalRep.dispose();
				
				// Setting these to null will ensure that any attempt to use
				// this object will result in a Java NullPointerException.
				
				internalRep = null;
				stringRep = null;
			}
		}
Example #17
0
		/// <summary> Creates a TclObject with the given InternalRep and stringRep.
		/// This constructor is used by the TclString class only. No other place
		/// should call this constructor.
		/// 
		/// </summary>
		/// <param name="rep">the initial InternalRep for this object.
		/// </param>
		/// <param name="s">the initial string rep for this object.
		/// </param>
		protected internal TclObject(TclString rep, string s)
		{
			if (rep == null)
			{
				throw new TclRuntimeError("null InternalRep");
			}
			internalRep = rep;
			stringRep = s;
			refCount = 0;
		}
Example #18
0
		/// <summary> Creates a TclObject with the given InternalRep. This method should be
		/// called only by an InternalRep implementation.
		/// 
		/// </summary>
		/// <param name="rep">the initial InternalRep for this object.
		/// </param>
		public TclObject(InternalRep rep)
		{
			if (rep == null)
			{
				throw new TclRuntimeError("null InternalRep");
			}
			internalRep = rep;
			stringRep = null;
			refCount = 0;
      typePtr = rep.GetType().Name.Replace("Tcl", "");
		}
Example #19
0
 /// <summary> Creates a TclObject with the given InternalRep. This method should be
 /// called only by an InternalRep implementation.
 /// 
 /// </summary>
 /// <param name="rep">the initial InternalRep for this object.
 /// </param>
 public TclObject( InternalRep rep )
 {
   if ( rep == null )
   {
     throw new TclRuntimeError( "null InternalRep" );
   }
   internalRep = rep;
   stringRep = null;
   refCount = 0;
 }