wasCSharpSQLite – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /*
2 * TclInteger.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: TclInteger.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 integer object type in Tcl.</summary>
20  
21 public class TclInteger : InternalRep
22 {
23 /// <summary> Internal representation of a integer value.</summary>
24 private int value;
25  
26 /// <summary> Construct a TclInteger representation with the given integer value.</summary>
27 private TclInteger( int i )
28 {
29 value = i;
30  
31 }
32  
33 /// <summary> Construct a TclInteger representation with the initial value taken
34 /// from the given string.
35 ///
36 /// </summary>
37 /// <param name="interp">current interpreter.
38 /// </param>
39 /// <param name="str">string rep of the integer.
40 /// </param>
41 /// <exception cref=""> TclException if the string is not a well-formed Tcl integer
42 /// value.
43 /// </exception>
44 private TclInteger( Interp interp, string str )
45 {
46 value = Util.getInt( interp, str );
47 }
48  
49 /// <summary> Returns a dupilcate of the current object.</summary>
50 /// <param name="obj">the TclObject that contains this internalRep.
51 /// </param>
52 public InternalRep duplicate()
53 {
54 return new TclInteger( value );
55 }
56  
57 /// <summary> Implement this no-op for the InternalRep interface.</summary>
58  
59 public void dispose()
60 {
61 }
62  
63 /// <summary> Called to query the string representation of the Tcl object. This
64 /// method is called only by TclObject.toString() when
65 /// TclObject.stringRep is null.
66 ///
67 /// </summary>
68 /// <returns> the string representation of the Tcl object.
69 /// </returns>
70 public override string ToString()
71 {
72 return value.ToString();
73 }
74  
75 /// <summary> TCL.Tcl_NewIntObj -> TclInteger.newInstance
76 ///
77 /// Creates a new instance of a TclObject with a TclInteger internal
78 /// representation.
79 ///
80 /// </summary>
81 /// <param name="b">initial value of the integer object.
82 /// </param>
83 /// <returns> the TclObject with the given integer value.
84 /// </returns>
85  
86 public static TclObject newInstance( int i )
87 {
88 return new TclObject( new TclInteger( i ) );
89 }
90  
91 /// <summary> SetIntFromAny -> TclInteger.setIntegerFromAny
92 ///
93 /// Called to convert the other object's internal rep to this type.
94 ///
95 /// </summary>
96 /// <param name="interp">current interpreter.
97 /// </param>
98 /// <param name="forIndex">true if this methid is called by getForIndex.
99 /// </param>
100 /// <param name="tobj">the TclObject to convert to use the
101 /// representation provided by this class.
102 /// </param>
103  
104 private static void setIntegerFromAny( Interp interp, TclObject tobj )
105 {
106 InternalRep rep = tobj.InternalRep;
107  
108 if ( rep is TclInteger )
109 {
110 // Do nothing.
111 }
112 else if ( rep is TclBoolean )
113 {
114 bool b = TclBoolean.get( interp, tobj );
115 if ( b )
116 {
117 tobj.InternalRep = new TclInteger( 1 );
118 }
119 else
120 {
121 tobj.InternalRep = new TclInteger( 0 );
122 }
123 }
124 else
125 {
126 // (ToDo) other short-cuts
127 tobj.InternalRep = new TclInteger( interp, tobj.ToString() );
128 }
129 }
130  
131 /// <summary> TCL.Tcl_GetIntFromObj -> TclInteger.get
132 ///
133 /// Returns the integer value of the object.
134 ///
135 /// </summary>
136 /// <param name="interp">current interpreter.
137 /// </param>
138 /// <param name="tobj">the object to operate on.
139 /// </param>
140 /// <returns> the integer value of the object.
141 /// </returns>
142  
143 public static int get( Interp interp, TclObject tobj )
144 {
145 setIntegerFromAny( interp, tobj );
146 TclInteger tint = (TclInteger)tobj.InternalRep;
147 return tint.value;
148 }
149  
150 /// <summary> Changes the integer value of the object.
151 ///
152 /// </summary>
153 /// <param name="interp">current interpreter.
154 /// </param>
155 /// <param name="tobj">the object to operate on.
156 /// @paran i the new integer value.
157 /// </param>
158 public static void set( TclObject tobj, int i )
159 {
160 tobj.invalidateStringRep();
161 InternalRep rep = tobj.InternalRep;
162 TclInteger tint;
163  
164 if ( rep is TclInteger )
165 {
166 tint = (TclInteger)rep;
167 tint.value = i;
168 }
169 else
170 {
171 tobj.InternalRep = new TclInteger( i );
172 }
173 }
174 }
175 }