/* * $Id: model.c,v 1.1.1.1 2004/08/25 19:21:30 jan Exp $ * * Copyright (c) 2002 Jan Algermissen * See the file "COPYING" for copying permission. * */ #include "tmmodel.h" /* #include "tmutil.h" */ #include "tmtrace.h" #include "tmassert.h" #include TMProperty tm_model_get_property(TMModel self,const char *name) { TMList lp; const char *p; TM_ENTER; assert(self); assert(name); TMTRACE(TM_X_TRACE,"name: %s\n" _ name); if( (p=strrchr(name,'/')) != NULL) { p++; if(strlen(self->name) != (p-name)) return NULL; if(strncmp(self->name,name,(p-name)) != 0) return NULL; name = p; } TMTRACE(TM_X_TRACE,"looking for %s\n" _ name); for(lp = self->properties; lp; lp=lp->next) { TMProperty p = (TMProperty)lp->content; if(strcmp(p->name,name) == 0) return p; } return NULL; } void tm_model_delete(TMPool pool,TMModel *pself) { TMModel self; TMList lp; assert(pself && *pself); self = *pself; TMTRACE(TM_X_TRACE,"cleaning up model %s\n" _ self->name); TMTRACE(TM_X_TRACE,"cleaning up required-list (models are freed independently)\n"); for(lp = self->require;lp;lp=lp->next) { TM_FREE(pool,lp->content); } tm_list_delete(pool,&self->require); TMTRACE(TM_X_TRACE,"cleaning up properties\n"); for(lp = self->properties;lp;lp=lp->next) { TMProperty prop = (TMProperty)lp->content; TMTRACE(TM_X_TRACE,"cleaning up %s\n" _ prop->fullname ); assert(prop->name); TM_FREE(pool,prop->name); if(prop->description) TM_FREE(pool,prop->description); assert(prop->fullname); TM_FREE(pool,prop->fullname); if(prop->combination_code) TM_FREE(pool,prop->combination_code); if(prop->equality_code) TM_FREE(pool,prop->equality_code); TM_FREE(pool,prop); } tm_list_delete(pool,&self->properties); TMTRACE(TM_X_TRACE,"cleaning up assertion types\n"); for(lp = self->atypes;lp;lp=lp->next) { TMList kp; TMAssertionType at = (TMAssertionType)lp->content; TMTRACE(TM_X_TRACE,"cleaning up AT\n"); for(kp = at->roles;kp;kp=kp->next) { TMRoleType rt = (TMRoleType)kp->content; TMTRACE(TM_X_TRACE,"cleaning up role\n"); if(rt->description) TM_FREE(pool,rt->description); TM_FREE(pool,rt->subject); /* allways alloced in tmadl_parse */ TM_FREE(pool,rt); } tm_list_delete(pool, &(at->roles)); if(at->description) TM_FREE(pool,at->description); assert(at->subject); TM_FREE(pool,at->subject); /* allways alloced in tmadl_parse */ TM_FREE(pool,at); } tm_list_delete(pool,&self->atypes); TMTRACE(TM_X_TRACE,"cleaning up additional subjects"); TMTRACE(TM_X_TRACE,"cleaning up name\n"); assert(self->name); TM_FREE(pool,self->name); TMTRACE(TM_X_TRACE,"cleaning up desc\n"); if(self->description) TM_FREE(pool,self->description); TM_FREE(pool,self); } void tm_model_delete_values(TMPool pool,TMModel *pself) { TMModel self; TMList lp; assert(pself && *pself); self = *pself; TMTRACE(TM_X_TRACE,"cleaning up values in model %s\n" _ self->name); for(lp = self->atypes;lp;lp=lp->next) { TMList kp; int i; TMAssertionType at = (TMAssertionType)lp->content; for(kp = at->roles;kp;kp=kp->next) { TMRoleType rt = (TMRoleType)kp->content; for(i=0;isubject->N;i++) { assert(rt->subject->props[i].prop); tm_value_delete(pool,rt->subject->props[i].prop->value_type, &(rt->subject->props[i].value) ); } } assert(at->subject); for(i=0;isubject->N;i++) { assert(at->subject->props[i].prop); tm_value_delete(pool,at->subject->props[i].prop->value_type, &(at->subject->props[i].value)); } } }