wasCSharpSQLite – Blame information for rev 4

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /*
2 * TclLong.java
3 *
4 * Copyright (c) 1997 Sun Microsystems, Inc.
5 *
6 * See the file "license.terms" for information on usage and
7 * redistribution of this file, and for a DISCLAIMER OF ALL
8 * WARRANTIES.
9 *
10 * Included in SQLite3 port to C# for use in testharness only; 2008 Noah B Hart
11 *
12 * RCS @(#) $Id: TclLong.java,v 1.5 2000/10/29 06:00:42 mdejong Exp $
13 *
14 */
15 using System;
16 namespace tcl.lang
17 {
18  
19 /// <summary> This class implements the long object type in Tcl.</summary>
20  
21 public class TclLong : InternalRep
22 {
23 /// <summary> longernal representation of a long value.</summary>
24 private long value;
25  
26 /// <summary> Construct a TclLong representation with the given long value.</summary>
27 private TclLong( long i )
28 {
29 value = i;
30 }
31  
32 /// <summary> Construct a TclLong representation with the initial value taken
33 /// from the given string.
34 ///
35 /// </summary>
36 /// <param name="interp">current interpreter.
37 /// </param>
38 /// <param name="str">string rep of the long.
39 /// </param>
40 /// <exception cref=""> TclException if the string is not a well-formed Tcl long
41 /// value.
42 /// </exception>
43 private TclLong( Interp interp, string str )
44 {
45 value = Util.getLong( interp, str );
46 }
47  
48 /// <summary> Returns a dupilcate of the current object.</summary>
49 /// <param name="obj">the TclObject that contains this InternalRep.
50 /// </param>
51 public InternalRep duplicate()
52 {
53 return new TclLong( value );
54 }
55  
56 /// <summary> Implement this no-op for the InternalRep longerface.</summary>
57  
58 public void dispose()
59 {
60 }
61  
62 /// <summary> Called to query the string representation of the Tcl object. This
63 /// method is called only by TclObject.toString() when
64 /// TclObject.stringRep is null.
65 ///
66 /// </summary>
67 /// <returns> the string representation of the Tcl object.
68 /// </returns>
69 public override string ToString()
70 {
71 return value.ToString();
72 }
73  
74 /// <summary> Tcl_NewlongObj -> TclLong.newInstance
75 ///
76 /// Creates a new instance of a TclObject with a TclLong longernal
77 /// representation.
78 ///
79 /// </summary>
80 /// <param name="b">initial value of the long object.
81 /// </param>
82 /// <returns> the TclObject with the given long value.
83 /// </returns>
84  
85 public static TclObject newInstance( long i )
86 {
87 return new TclObject( new TclLong( i ) );
88 }
89  
90 /// <summary> SetlongFromAny -> TclLong.setlongFromAny
91 ///
92 /// Called to convert the other object's longernal rep to this type.
93 ///
94 /// </summary>
95 /// <param name="interp">current interpreter.
96 /// </param>
97 /// <param name="forIndex">true if this methid is called by getForIndex.
98 /// </param>
99 /// <param name="tobj">the TclObject to convert to use the
100 /// representation provided by this class.
101 /// </param>
102  
103 private static void setlongFromAny( Interp interp, TclObject tobj )
104 {
105 InternalRep rep = tobj.InternalRep;
106  
107 if ( rep is TclLong )
108 {
109 // Do nothing.
110 }
111 else if ( rep is TclBoolean )
112 {
113 bool b = TclBoolean.get( interp, tobj );
114 if ( b )
115 {
116 tobj.InternalRep = new TclLong( 1 );
117 }
118 else
119 {
120 tobj.InternalRep = new TclLong( 0 );
121 }
122 }
123 else
124 {
125 // (ToDo) other short-cuts
126 tobj.InternalRep = new TclLong( interp, tobj.ToString() );
127 }
128 }
129  
130 /// <summary> Tcl_GetlongFromObj -> TclLong.get
131 ///
132 /// Returns the long value of the object.
133 ///
134 /// </summary>
135 /// <param name="interp">current interpreter.
136 /// </param>
137 /// <param name="tobj">the object to operate on.
138 /// </param>
139 /// <returns> the long value of the object.
140 /// </returns>
141  
142 public static long get( Interp interp, TclObject tobj )
143 {
144 setlongFromAny( interp, tobj );
145 TclLong tlong = (TclLong)tobj.InternalRep;
146 return tlong.value;
147 }
148  
149 /// <summary> Changes the long value of the object.
150 ///
151 /// </summary>
152 /// <param name="interp">current interpreter.
153 /// </param>
154 /// <param name="tobj">the object to operate on.
155 /// @paran i the new long value.
156 /// </param>
157 public static void set( TclObject tobj, long i )
158 {
159 tobj.invalidateStringRep();
160 InternalRep rep = tobj.InternalRep;
161 TclLong tlong;
162  
163 if ( rep is TclLong )
164 {
165 tlong = (TclLong)rep;
166 tlong.value = i;
167 }
168 else
169 {
170 tobj.InternalRep = new TclLong( i );
171 }
172 }
173 }
174 }