/* $OpenXM: OpenXM/src/kan96xx/Kan/kclass.c,v 1.2 2000/01/16 07:55:39 takayama Exp $ */ /* kclass.c, 1997, 3/1 This module handles class data base. This is a top level and provides an interface for sm1 for Sclass objects. Main processing is done in Kclass/* See, Kclass/sample.h, Kclass/sample.c ; grep the keyword CLASSNAME_sampleClass */ #include #include "datatype.h" #include "stackm.h" #include "extern.h" #include "gradedset.h" #include "extern2.h" #include "kclass.h" #define CLASSTABLE_SIZE 4096 struct object * ClassDictionaries[CLASSTABLE_SIZE]; char *ClassNames[CLASSTABLE_SIZE]; int ClassTypes[CLASSTABLE_SIZE]; initClassDataBase() { int i; for (i=0; i errorPacket is not supported."); if (getoaSize(ob1) != 3) errorKan1("%s\n","kclass.c : KclassDataConversion , only [integer, integer, string] --> errorPacket is supported."); if (getoa(ob1,0).tag != Sinteger) errorKan1("%s\n","kclass.c : KclassDataConversion , only [integer, integer, string] --> errorPacket is supported."); if (getoa(ob1,1).tag != Sinteger) errorKan1("%s\n","kclass.c : KclassDataConversion , only [integer, integer, string] --> errorPacket is supported."); if (getoa(ob1,2).tag != Sdollar) errorKan1("%s\n","kclass.c : KclassDataConversion , only [integer, integer, string] --> errorPacket is supported."); rob = KnewErrorPacketObj(ob1); }else if (strcmp(ccc,"indeterminate") == 0) { if (ob1.tag != Sdollar) errorKan1("%s\n","kclass.c : KclassDataConversion , !String --> indeterminate is not supported."); rob = KpoIndeterminate(ob1); }else if (strcmp(ccc,"mathcap") == 0) { /* You should check ob1 contains mathcap data or not. I've not yet written them. */ rob = KpoMathCap(&ob1); }else if (strcmp(ccc,"tree") == 0) { if (ob1.tag != Sarray) errorKan1("%s\n","kclass.c : KclassDataConversion , !array --> indeterminate is not supported."); rob = KpoTree(ob1); }else if (strcmp(ccc,"recursivePolynomial") == 0) { if (ob1.tag != Spoly) errorKan1("%s\n","kclass.c : KclassDataConversion , !poly --> recursivePoly is not supported."); rob = polyToRecursivePoly(ob1); }else{ errorKan1("%s\n","KclassDataConversion: this type of data conversion from primitive object to class object is not supported."); } break; case 2: if (getoaSize(ob2) != 2) errorKan1("%s\n","kclass.c : KclassDataConversion() the second argument should be [(class) (class-name)]"); ff0 = getoa(ob2,0); ff1 = getoa(ob2,1); if (ff0.tag != Sdollar || ff1.tag != Sdollar) errorKan1("%s\n","kclass.c : KclassDataConversion() the second argument should be [(class) (class-name)]"); if (strcmp("class",KopString(ff0)) != 0) errorKan1("%s\n","kclass.c : KclassDataConversion() the second argument should be [(class) (class-name)] (class)!!!"); ccc = KopString(ff1); /* target data type. */ switch(ectag(ob1)) { case CLASSNAME_sampleClass: if (strcmp(ccc,"sampleClass") == 0) { rob = KpoSampleClass(&ob1); }else{ errorKan1("%s\n","KclassDataCOnversion: this type of data conversion from class object to class object is not supported."); } break; default: errorKan1("%s\n","KclassDataConversion: this type of data conversion from class object to class object is not supported."); } break; case 3: key = KopString(ob2); /* target data type */ if (key[0] == 't' || key[0] =='e') { if (strcmp(key,"type?")==0) { rob = KpoInteger(ob1.tag); return(rob); }else if (strcmp(key,"type??")==0) { if (ob1.tag != Sclass) { rob = KpoInteger(ob1.tag); }else { rob = KpoInteger(ectag(ob1)); } return(rob); }else if (strcmp(key,"error")==0) { rob = KnewErrorPacketObj(ob1); return(rob); } } /* Class object to primtive Object */ switch(ectag(ob1)) { case CLASSNAME_sampleClass: if (strcmp(key,"array") == 0) { rob = *(KopSampleClass(ob1)); }else{ errorKan1("%s\n","KclassDataCOnversion: this type of data conversion from class object to primitive object is not supported."); } break; case CLASSNAME_mathcap: if (strcmp(key,"array") == 0) { rob = newObjectArray(2); ob3 = KpoString("mathcap-object"); putoa(rob,0,ob3); putoa(rob,1,*(KopMathCap(ob1))); }else{ errorKan1("%s\n","KclassDataConversion: this type of data conversion from class object mathcap to primitive object is not supported."); } break; case CLASSNAME_indeterminate: if (strcmp(key,"string") == 0) { rob = KopIndeterminate(ob1); }else { errorKan1("%s\n","KclassDataConversion: interminate-->?? is not supported.."); } break; case CLASSNAME_tree: if (strcmp(key,"array") == 0) { rob = KopTree(ob1); }else { errorKan1("%s\n","KclassDataConversion: tree-->?? is not supported.."); } break; case CLASSNAME_recursivePolynomial: if (strcmp(key,"string") == 0) { errorKan1("%s\n","Translation of recursive polynomial to a string should be implemented."); }else if (strcmp(key,"poly") == 0) { rob = recursivePolyToPoly(ob1); }else if (strcmp(key,"array") == 0) { rob = KopRecursivePolynomial(ob1); }else { errorKan1("%s\n","KclassDataConversion: recursivePoly-->?? is not supported.."); } break; default: errorKan1("%s\n","KclassDataConversion: this type of data conversion from class object to primitive object is not supported."); } break; } return(rob); } /* Arithmetic operations for class objects. */ struct object Kclass_ooAdd(struct object ob1, struct object ob2) { /* It is called from ooAdd(). */ /* ob1 or ob2 must have the class tag. */ struct object rob = NullObject; /* Default action */ rob = addTree(ob2,ob1); return(rob); }