Added support for dynamically allocated arrays.
[repair.git] / Repair / RepairInterpreter / DefaultGuidance.cc
1 // for CIV
2
3 #include <stdlib.h>
4 #include "DefaultGuidance.h"
5 #include "model.h"
6 #include "dmodel.h"
7 #include "tmodel.h"
8 #include "element.h"
9 #include "common.h"
10   /* This class tells the analysis stuff */
11   /* For each set:
12      1. Source for atoms if the set is too small - can be another set or function call (assumed to be no set)
13      2. Source for atoms if relation requires atom of this set - can be another set or function call (assumed to be no set)
14      3. Removal from set - where to insert objects from this set
15      4. Insertion into set - which subset to put objects in  */
16
17 DefGuidance::DefGuidance(model *m) {
18   globalmodel=m;
19 }
20
21 Source DefGuidance::sourceforsetsize(char *set) {
22   if (equivalentstrings(set,"TERRAINTYPES"))
23     return Source(copystr("water"));
24   if (equivalentstrings(set,"STILE"))
25     return Source(copystr("STILE"));
26   return Source(&allocatebytes);
27 }
28
29 Source DefGuidance::sourceforrelation(char *set) {
30   if (equivalentstrings(set,"TERRAINTYPES"))
31     return Source(copystr("water"));
32   if (equivalentstrings(set,"STILE"))
33     return Source(copystr("STILE"));
34   DomainRelation *dr=globalmodel->getdomainrelation();
35   DomainSet *ds=dr->getset(set);
36   if (equivalentstrings(ds->getelementtype(),"int"))
37     return Source(copystr("int"));
38   return Source(&allocatebytes);
39 }
40
41 char * DefGuidance::removefromset(char * set) {
42   DomainRelation *dr=globalmodel->getdomainrelation();
43   DomainSet *ds=dr->getset(set);
44   DomainSet *ss=dr->getsuperset(ds);
45   while(ss!=NULL&&ss->gettype()==DOMAINSET_PARTITION) {
46     for(int i=0;i<ss->getnumsubsets();i++) {
47       char *name=ss->getsubset(i);
48       if (!equivalentstrings(ds->getname(),name)&&
49           !equivalentstrings(ds->getname(),name)) {
50         /* Do search */
51         ss=dr->getset(name);
52         while(ss->gettype()==DOMAINSET_PARTITION) {
53           char *name=ss->getsubset(0);
54           ss=dr->getset(name);
55         }
56         return ss->getname();
57       }
58     }
59     ds=ss;
60     ss=dr->getsuperset(ss);
61   }
62   if (ss!=NULL)
63     return ss->getname();
64   else
65     return NULL;
66 }
67
68 char * DefGuidance::insertiontoset(char *set) {
69   DomainRelation *dr=globalmodel->getdomainrelation();
70   DomainSet *ds=dr->getset(set);
71   while (ds->gettype()==DOMAINSET_PARTITION) {
72     ds=dr->getset(ds->getsubset(0));
73     /* have to look for subset; */
74   }
75   return ds->getname();
76 }
77
78 Element * allocatebytes(structure * st, model *m) {
79   int size=st->getsize(m->getbitreader(),m,m->gethashtable());
80   Element * e=new Element(new char[size],st);
81   return e;
82 }