enforce all constraints under given schema on entity
| 741 | |
| 742 | // enforce all constraints under given schema on entity |
| 743 | bool Schema_EnforceConstraints |
| 744 | ( |
| 745 | const Schema *s, // schema |
| 746 | const GraphEntity *e, // entity to enforce |
| 747 | char **err_msg // report error message |
| 748 | ) { |
| 749 | // validations |
| 750 | ASSERT(s != NULL); |
| 751 | ASSERT(e != NULL); |
| 752 | |
| 753 | // see if entity holds under all schema's constraints |
| 754 | uint n = array_len(s->constraints); |
| 755 | for(uint i = 0; i < n; i++) { |
| 756 | Constraint c = s->constraints[i]; |
| 757 | if(Constraint_GetStatus(c) != CT_FAILED && |
| 758 | !Constraint_EnforceEntity(c, e, err_msg)) { |
| 759 | // entity failed to pass constraint |
| 760 | return false; |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | // entity passed all constraint |
| 765 | return true; |
| 766 | } |
| 767 | |
| 768 | void Schema_Free |
| 769 | ( |
no test coverage detected