-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdata_structures.py
47 lines (40 loc) · 1.03 KB
/
data_structures.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
Abstract representation of objects and relations.
"""
class AObject(object):
"""
An object, aka model or table, with a list of fields
"""
def __init__(self, name="", color=None, shape=None):
self.name = name
self.fields = []
self.color = color or (1, 1, 1)
self.shape = shape or "Rectangle"
def add_field(self, name="", type="", field=None):
"""
supply either name and type, OR field
@param field: AField
@return: the AField that was added
"""
if field:
f = field
else:
f = AField(name, type)
self.fields.append(f)
return f
class AField(object):
"""
A relation to another object
"""
def __init__(self, name="", type="", dest=None):
"""
@param dest: AObject
"""
self.name = name
self.type = type
self.dest = dest
def set_destination(self, dest):
"""
@param dest: AObject
"""
self.dest = dest