Annotation of OpenXM/src/OpenMath/ORG/openxm/tam/CMO.java, Revision 1.3
1.1 tam 1: /**
1.3 ! ohara 2: * $OpenXM: OpenXM/src/OpenMath/ORG/openxm/tam/CMO.java,v 1.2 2000/09/13 06:32:42 tam Exp $
1.1 tam 3: */
4: package ORG.openxm.tam;
5:
6: import java.io.*;
7:
8: /**
9: * OpenXM $B%a%C%;!<%8$N(B CMO $B%*%V%8%'%/%H$rI=$9Cj>]%/%i%9(B.
10: */
11: abstract public class CMO extends OXbody{
12: final public static int LARGEID = 0x7f000000;
13: final public static int ERROR = ( LARGEID +1 );
14: final public static int ERROR2 = ( LARGEID +2 );
15: final public static int NULL = 1;
16: final public static int INT32 = 2;
17: final public static int DATUM = 3;
18: final public static int STRING = 4;
19: final public static int MATHCAP = 5;
20: final public static int LIST = 17;
21:
22: final public static int MONOMIAL32 = 19;
23: final public static int ZZ = 20;
24: final public static int QQ = 21;
25: final public static int ZERO = 22;
26: final public static int DMS = 23;
27: final public static int DMS_GENERIC = 24;
28: final public static int DMS_OF_N_VARIABLES = 25;
29: final public static int RING_BY_NAME = 26;
30:
31: final public static int RECURSIVE_POLYNOMIAL = 27;
32: final public static int DISTRIBUTED_POLYNOMIAL = 31;
33: final public static int POLYNOMIAL_IN_ONE_VARIABLE = 33;
34:
35: final public static int RATIONAL = 34;
36:
37: final public static int CMO_64BIT_MACHINE_DOUBLE = 40;
38: final public static int ARRAY_OF_64BIT_MACHINE_DOUBLE = 41;
39: final public static int CMO_128BIT_MACHINE_DOUBLE = 42;
40: final public static int ARRAY_OF_128BIT_MACHINE_DOUBLE = 43;
41:
42: final public static int BIGFLOAT = 50;
43: final public static int IEEE_DOUBLE_FLOAT = 51;
44:
45: final public static int INDETERMINATE = 60;
46: final public static int TREE = 61;
47: final public static int LAMBDA = 62;
48:
49: final public static int PRIVATE = 0x7fff0000;
50:
51: abstract protected int DISCRIMINATOR();
52:
53: public int getDISCRIMINATOR(){
54: return this.DISCRIMINATOR();
55: }
1.3 ! ohara 56:
! 57: public static boolean allowQ_tag (int[] datacap, int tag) {
! 58: for(int i=0; i<datacap.length; i++) {
! 59: if (datacap[i] == tag) {
! 60: return true;
! 61: }
! 62: }
! 63: return false;
! 64: }
! 65:
! 66: public boolean allowQ (int[] datacap) {
! 67: return allowQ_tag(datacap, DISCRIMINATOR());
! 68: }
1.1 tam 69:
1.2 tam 70: abstract protected void sendByObject(OpenXMstream stream)
1.1 tam 71: throws IOException,MathcapViolation;
72:
1.2 tam 73: final public void write(OpenXMstream os)
1.1 tam 74: throws IOException,MathcapViolation{
75: CMO[] mathcap = os.getMathcap(OXmessage.OX_DATA);
76:
77: if(mathcap != null){ // check mathcap
78: CMO[] datacap = ((CMO_LIST)mathcap[1]).getElements();
79: int i=0;
80:
81: for(;i<datacap.length;i++){
82: if(((CMO_INT32)datacap[i]).intValue() == this.DISCRIMINATOR()){
83: break;
84: }
85: }
86: if(i>=datacap.length){
87: throw new MathcapViolation(this.toCMOexpression());
88: }
89: }
90: os.writeInt(this.DISCRIMINATOR());
91: this.sendByObject(os);
92: }
93:
1.2 tam 94: static protected CMO receive(OpenXMstream is) throws IOException{
1.1 tam 95: int a = is.readInt();
96:
97: switch(a){
98: case CMO.ERROR2:
99: return CMO_ERROR2.receive(is);
100:
101: case CMO.NULL:
102: return CMO_NULL.receive(is);
103:
104: case CMO.INT32:
105: return CMO_INT32.receive(is);
106:
107: case CMO.DATUM:
108: return CMO_DATUM.receive(is);
109:
110: case CMO.STRING:
111: return CMO_STRING.receive(is);
112:
113: case CMO.MATHCAP:
114: return CMO_MATHCAP.receive(is);
115:
116: case CMO.LIST:
117: return CMO_LIST.receive(is);
118:
119: case CMO.MONOMIAL32:
120: return CMO_MONOMIAL32.receive(is);
121:
122: case CMO.ZZ:
123: return CMO_ZZ.receive(is);
124:
125: case CMO.QQ:
126: return CMO_QQ.receive(is);
127:
128: case CMO.ZERO:
129: return CMO_ZERO.receive(is);
130:
131: case CMO.DMS:
132: return CMO_DMS.receive(is);
133:
134: case CMO.DMS_GENERIC:
135: return CMO_DMS_GENERIC.receive(is);
136:
137: case CMO.RECURSIVE_POLYNOMIAL:
138: return CMO_RECURSIVE_POLYNOMIAL.receive(is);
139:
140: case CMO.DISTRIBUTED_POLYNOMIAL:
141: return CMO_DISTRIBUTED_POLYNOMIAL.receive(is);
142:
143: case CMO.POLYNOMIAL_IN_ONE_VARIABLE:
144: return CMO_POLYNOMIAL_IN_ONE_VARIABLE.receive(is);
145:
146: case CMO.RATIONAL:
147: return CMO_RATIONAL.receive(is);
148:
149: case CMO.BIGFLOAT:
150: return CMO_BIGFLOAT.receive(is);
151:
152: case CMO.INDETERMINATE:
153: return CMO_INDETERMINATE.receive(is);
154:
155: case CMO.TREE:
156: return CMO_TREE.receive(is);
157:
158: default:
159: System.err.println("unknown CMO type("+ a +")");
160: }
161: return null;
162: }
163:
164: abstract protected String toCMOexpressionByObject();
165:
166: /**
167: * $B%*%V%8%'%/%H$r(B CMO expression $B$KJQ49$7$^$9(B.
168: */
169: final public String toCMOexpression(){
170: return "("+ this.toCMOexpressionByObject() +")";
171: }
172:
173: /**
174: * $B%*%V%8%'%/%H$r(B OX expression $B$KJQ49$7$^$9(B.
175: * $B8=:_$O(B CMO expression $B$X$HJQ49$7$^$9(B.
176: */
177: final public String toOXexpression(){
178: return toCMOexpression();
179: }
180:
181: final public String toString(){
182: return this.toCMOexpression();
183: }
184: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>