Moved makelib
[repair.git] / Repair / RepairInterpreter / dmodel.h
1 // defines the sets and the relations used
2
3 #ifndef DMODEL_H
4 #define DMODEL_H
5
6 #include "common.h"
7 #include "classlist.h"
8
9 #define DOMAINSET_SUBSET 1
10 #define DOMAINSET_PARTITION 2
11 #define DOMAINSET_TYPED 0x100
12
13 // represents a set
14 class DomainSet {
15  public:
16   DomainSet(char *name);
17   void settype(char *type);
18   void setsubsets(char **subsets, int numsubsets);
19   void setpartition(char **subsets, int numsubsets);
20   void print();
21   char *getname();
22   WorkSet *getset();
23   int getnumsubsets();
24   char *getsubset(int i);
25   int gettype();
26   char * getelementtype();
27   void reset();
28  private:
29   WorkSet *set;   // the set itself
30   char *type;     // the type of the elements in the set 
31   char *setname;  // the name of the set
32   int flag; 
33   char ** subsets;// the subsets
34   int numsubsets; 
35 };
36
37
38
39
40 #define DRELATION_SINGDOMAIN 0x1
41 #define DRELATION_MANYDOMAIN 0x2
42 #define DRELATION_SINGRANGE 0x10
43 #define DRELATION_MANYRANGE 0x20
44
45 // represents a relation
46 class DRelation {
47  public:
48   DRelation(char *name, char *d, char *r, int t, bool);
49   void print();
50   char *getname();
51   WorkRelation *getrelation();
52   char *getdomain();
53   char *getrange();
54   WorkSet *gettokenrange();
55   void settokenrange(WorkSet *ws);
56   bool isstatic();
57   void reset();
58  private:
59   bool staticrel;
60   char *name;
61   char *domain;
62   char *range;
63   WorkSet *tokenrange; // the actual range, if the range is of type token
64   int type;
65   WorkRelation *relation;
66 };
67
68
69
70 // manages the entire collection of sets and relations
71 class DomainRelation {
72  public:
73   DomainRelation(DomainSet **s, int ns, DRelation **r,int nr);
74   void print();
75   DomainSet * getset(char * setname);
76   DRelation * getrelation(char * relationname);
77   ~DomainRelation();
78   WorkSet * conflictdelsets(char *setname, char *boundset);
79   WorkSet * conflictaddsets(char *setname, char *boundset, model *m);
80   WorkSet * removeconflictdelsets(char *setname);
81   WorkSet * removeconflictaddsets(char *setname, model *m);
82   DomainSet * getsuperset(DomainSet *);
83   DomainSet * getsource(DomainSet *);
84   /* Tells what set we might get objects from for a given set */
85   void delfromsetmovetoset(Element *e,DomainSet *deletefromset,model *m);
86   void abstaddtoset(Element *e,DomainSet *addtoset,model *m);
87   void addtoset(Element *e,DomainSet *addtoset,model *m);
88   bool issupersetof(DomainSet *sub,DomainSet *super);
89   int getnumrelation();
90   DRelation * getrelation(int i);
91   bool fixstuff();
92   void reset();
93
94  private:
95   bool checkrelations(DRelation *dr);
96   bool checksubset(DomainSet *ds);
97   void addallsubsets(DomainSet *ds, WorkSet *ws);
98   void removefromthisset(Element *ele, DomainSet *ds,model *m);
99   Hashtable *settable, *relationtable;
100   DomainSet ** sets;
101   int numsets;
102   DRelation **relations;
103   int numrelations;
104 };
105 #endif