wasCSharpSQLite – Blame information for rev

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