/* * TclLong.java * * Copyright (c) 1997 Sun Microsystems, Inc. * * See the file "license.terms" for information on usage and * redistribution of this file, and for a DISCLAIMER OF ALL * WARRANTIES. * * Included in SQLite3 port to C# for use in testharness only; 2008 Noah B Hart * * RCS @(#) $Id: TclLong.java,v 1.5 2000/10/29 06:00:42 mdejong Exp $ * */ using System; namespace tcl.lang { /// This class implements the long object type in Tcl. public class TclLong : InternalRep { /// longernal representation of a long value. private long value; /// Construct a TclLong representation with the given long value. private TclLong( long i ) { value = i; } /// Construct a TclLong representation with the initial value taken /// from the given string. /// /// /// current interpreter. /// /// string rep of the long. /// /// TclException if the string is not a well-formed Tcl long /// value. /// private TclLong( Interp interp, string str ) { value = Util.getLong( interp, str ); } /// Returns a dupilcate of the current object. /// the TclObject that contains this InternalRep. /// public InternalRep duplicate() { return new TclLong( value ); } /// Implement this no-op for the InternalRep longerface. public void dispose() { } /// Called to query the string representation of the Tcl object. This /// method is called only by TclObject.toString() when /// TclObject.stringRep is null. /// /// /// the string representation of the Tcl object. /// public override string ToString() { return value.ToString(); } /// Tcl_NewlongObj -> TclLong.newInstance /// /// Creates a new instance of a TclObject with a TclLong longernal /// representation. /// /// /// initial value of the long object. /// /// the TclObject with the given long value. /// public static TclObject newInstance( long i ) { return new TclObject( new TclLong( i ) ); } /// SetlongFromAny -> TclLong.setlongFromAny /// /// Called to convert the other object's longernal rep to this type. /// /// /// current interpreter. /// /// true if this methid is called by getForIndex. /// /// the TclObject to convert to use the /// representation provided by this class. /// private static void setlongFromAny( Interp interp, TclObject tobj ) { InternalRep rep = tobj.InternalRep; if ( rep is TclLong ) { // Do nothing. } else if ( rep is TclBoolean ) { bool b = TclBoolean.get( interp, tobj ); if ( b ) { tobj.InternalRep = new TclLong( 1 ); } else { tobj.InternalRep = new TclLong( 0 ); } } else { // (ToDo) other short-cuts tobj.InternalRep = new TclLong( interp, tobj.ToString() ); } } /// Tcl_GetlongFromObj -> TclLong.get /// /// Returns the long value of the object. /// /// /// current interpreter. /// /// the object to operate on. /// /// the long value of the object. /// public static long get( Interp interp, TclObject tobj ) { setlongFromAny( interp, tobj ); TclLong tlong = (TclLong)tobj.InternalRep; return tlong.value; } /// Changes the long value of the object. /// /// /// current interpreter. /// /// the object to operate on. /// @paran i the new long value. /// 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 ); } } } }