[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.5

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

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