[BACK]Return to cmolen.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / ox_toolkit

Annotation of OpenXM/src/ox_toolkit/cmolen.c, Revision 1.3

1.1       ohara       1: /* -*- mode: C; coding: euc-japan -*- */
1.3     ! ohara       2: /* $OpenXM: OpenXM/src/ox_toolkit/cmolen.c,v 1.2 2003/03/23 20:17:34 ohara Exp $ */
1.1       ohara       3:
                      4: /* This module is needed by bconv.c */
                      5:
                      6: /*
                      7: The cmolen_cmo() function returns the length of the binary encoded
                      8: object for a given cmo.
                      9: cmolen_cmo_XXX() functions return the length of the binary encoded cmo
                     10: except its tag.
                     11: */
                     12:
                     13: #include "ox_toolkit.h"
                     14:
                     15: static int          cmolen_cmo_int32(cmo_int32* c);
                     16: static int          cmolen_cmo_list(cmo_list* c);
                     17: static int          cmolen_cmo_mathcap(cmo_mathcap* c);
                     18: static int          cmolen_cmo_null(cmo_null* c);
                     19: static int          cmolen_cmo_string(cmo_string* c);
                     20: static int          cmolen_cmo_zz(cmo_zz* c);
                     21: static int          cmolen_cmo_monomial32(cmo_monomial32* c);
                     22:
                     23: __inline__
                     24: static int cmolen_cmo_null(cmo_null* c)
                     25: {
                     26:     return 0;
                     27: }
                     28:
                     29: static int cmolen_cmo_int32(cmo_int32* c)
                     30: {
                     31:     return sizeof(int);
                     32: }
                     33:
                     34: static int cmolen_cmo_string(cmo_string* c)
                     35: {
                     36:     return sizeof(int)+strlen(c->s);
                     37: }
                     38:
                     39: static int cmolen_cmo_mathcap(cmo_mathcap* c)
                     40: {
                     41:     return cmolen_cmo(c->ob);
                     42: }
                     43:
                     44: static int cmolen_cmo_list(cmo_list* c)
                     45: {
                     46:     int size = sizeof(int);
                     47:     cell* cp;
                     48:     for(cp = list_first(c); !list_endof(c, cp); cp = list_next(cp)) {
                     49:         size += cmolen_cmo(cp->cmo);
                     50:     }
                     51:     return size;
                     52: }
                     53:
                     54: static int cmolen_cmo_monomial32(cmo_monomial32* c)
                     55: {
                     56:     int len = (c->length + 1)*sizeof(int);
                     57:     return len + cmolen_cmo(c->coef);
                     58: }
                     59:
                     60: static int cmolen_cmo_zz(cmo_zz* c)
                     61: {
                     62:     int len = abs(c->mpz->_mp_size);
                     63:     return sizeof(int) + len*sizeof(int);
                     64: }
                     65:
                     66: static int cmolen_cmo_distributed_polynomial(cmo_distributed_polynomial* c)
                     67: {
                     68:     return cmolen_cmo_list((cmo_list *)c) + cmolen_cmo(c->ringdef);
                     69: }
                     70:
                     71: /* a function calculating the length of the byte stream of a given CMO.  */
                     72: int cmolen_cmo(cmo* c)
                     73: {
                     74:     int size = sizeof(int);
                     75:
                     76:     switch(c->tag) {
                     77:     case CMO_NULL:
                     78:     case CMO_ZERO:
                     79:     case CMO_DMS_GENERIC:
                     80:         size += cmolen_cmo_null(c);
                     81:         break;
                     82:     case CMO_INT32:
                     83:         size += cmolen_cmo_int32((cmo_int32 *)c);
                     84:         break;
                     85:     case CMO_STRING:
                     86:         size += cmolen_cmo_string((cmo_string *)c);
                     87:         break;
                     88:     case CMO_MATHCAP:
                     89:     case CMO_RING_BY_NAME:
                     90:     case CMO_INDETERMINATE:
                     91:     case CMO_ERROR2:
                     92:         size += cmolen_cmo_mathcap((cmo_mathcap *)c);
                     93:         break;
                     94:     case CMO_LIST:
                     95:         size += cmolen_cmo_list((cmo_list *)c);
                     96:         break;
                     97:     case CMO_MONOMIAL32:
                     98:         size += cmolen_cmo_monomial32((cmo_monomial32 *)c);
                     99:         break;
                    100:     case CMO_ZZ:
                    101:         size += cmolen_cmo_zz((cmo_zz *)c);
                    102:         break;
                    103:     case CMO_DISTRIBUTED_POLYNOMIAL:
                    104:         size += cmolen_cmo_distributed_polynomial((cmo_distributed_polynomial *)c);
                    105:         break;
                    106:     default:
                    107:     }
                    108:     return size;
                    109: }
                    110:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>