Logo Search packages:      
Sourcecode: tablix2 version File versions  Download package

ext* ext_new ( ext **  ex,
int  contype,
int  vartype 
)

Allocate a new extension struct in a linked list.

Linked list is first searched for an identical extension struct. If such a structure is found, only a pointer to it is returned and the linked is is not changed. If no such structure exists, a new structure is allocated and inserted at the beginning of the linked list.

Parameters:
ex Pointer to the linked list.
contype Constant resource type id.
vartype Variable resource type id.
Returns:
Pointer to the new extension struct or NULL on error.

Definition at line 1043 of file data.c.

References ext_t::con_typeid, ext_t::connum, dat_typenum, ext_t::next, resourcetype_t::resnum, ext_t::tupleid, ext_t::var_typeid, and ext_t::varnum.

Referenced by fitness_request_ext().

{
      ext *cur;
      int n,m;

      assert(ex!=NULL);
      assert(contype<dat_typenum);
      assert(vartype<dat_typenum);
      assert(vartype!=contype);

      cur=*ex;

      while(cur!=NULL) {
            if(cur->con_typeid==contype&&cur->var_typeid==vartype) {
                  return(cur);
            }
            cur=cur->next;
      }

      cur=malloc(sizeof(*cur));
      if(cur==NULL) return(NULL);

      cur->con_typeid=contype;
      cur->var_typeid=vartype;

      cur->connum=dat_restype[contype].resnum;
      cur->varnum=dat_restype[vartype].resnum;

      cur->tupleid=malloc(sizeof(*cur->tupleid)*cur->varnum);
      if(cur->tupleid==NULL) {
            free(cur);
            return(NULL);
      }

      for(n=0;n<cur->varnum;n++) {
            cur->tupleid[n]=malloc(sizeof(*cur->tupleid[n])*cur->connum);
            if(cur->tupleid[n]==NULL) {
                  for(m=0;m<n;m++) free(cur->tupleid[m]);
                  free(cur->tupleid);
                  free(cur);
                  return(NULL);
            }
            for(m=0;m<cur->connum;m++) cur->tupleid[n][m]=-1;
      }

      cur->next=*ex;
      *ex=cur;

      return(cur);
}


Generated by  Doxygen 1.6.0   Back to index