File: Objects.gi

package info (click to toggle)
gap-polymaking 0.8.8-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 816 kB
  • sloc: xml: 682; javascript: 155; makefile: 105; perl: 24; sh: 2
file content (218 lines) | stat: -rw-r--r-- 6,187 bytes parent folder | download | duplicates (3)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#############################################################################
##
#W Objects.gi            polymaking Package      Marc Roeder
##
##  

##
##
#Y   Copyright (C) 2006 Marc Roeder 
#Y 
#Y This program is free software; you can redistribute it and/or 
#Y modify it under the terms of the GNU General Public License 
#Y as published by the Free Software Foundation; either version 2 
#Y of the License, or (at your option) any later version. 
#Y 
#Y This program is distributed in the hope that it will be useful, 
#Y but WITHOUT ANY WARRANTY; without even the implied warranty of 
#Y MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
#Y GNU General Public License for more details. 
#Y 
#Y You should have received a copy of the GNU General Public License 
#Y along with this program; if not, write to the Free Software 
#Y Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
##
PolymakeObjectFamily:=NewFamily("PolymakeObjectFamily",IsPolymakeObject);
PolymakeObject:=NewType(PolymakeObjectFamily,IsPolymakeObjectRep);


######################################################################
# The following methods are the only ones which manipulate the contents
# of a PolymakeObject. 
# There are no other functions containing things like <poly!.knownProperties>
#

######################################################################
# Printing Polymake Objects nicely:
#
InstallMethod(ViewObj,
        "for PolymakeObject",
        [IsPolymakeObject],
        function(poly)
    local compnames;
    compnames:=NamesOfComponents(poly);
    if "knownProperties" in compnames 
      and "DESCRIPTION" in NamesKnownPropertiesOfPolymakeObject(poly)
      then
        Print("<",PropertyOfPolymakeObject(poly,"DESCRIPTION"));
    else
        Print("<polymake object");
    fi;
    if not "knownProperties" in compnames
       then
        Print(". No properties known");
    fi;
    Print(">");
end);

InstallMethod(PrintObj,
        "for PolymakeObject",
        [IsPolymakeObject],
        function(poly)
    local compnames;
    compnames:=NamesOfComponents(poly);
    if "knownProperties" in compnames 
      and "DESCRIPTION" in NamesKnownPropertiesOfPolymakeObject(poly)
      then
        Print("<",PropertyOfPolymakeObject(poly,"DESCRIPTION"));
    else
        Print("<polymake object");
    fi;
    if not "knownProperties" in compnames
       then
        Print(". No properties known");
    else
        Print(". Properties known: ",NamesKnownPropertiesOfPolymakeObject(poly));
    fi;
    Print(">\n");
end);


######################################################################
#
# Extracting data from objects:
#


# the DIRECTORY:
InstallMethod(DirectoryOfPolymakeObject,
        "for PolymakeObject",
        [IsPolymakeObject],
        function(poly)
        return poly!.dir;
end);

# the FILENAME:
InstallMethod(FilenameOfPolymakeObject,
        "for PolymakeObject",
        [IsPolymakeObject],
        function(poly)
    return poly!.filename;
end);

#the FILENAME with full path:
InstallMethod(FullFilenameOfPolymakeObject,
        [IsPolymakeObject],
        function(poly)
    return Filename(DirectoryOfPolymakeObject(poly),FilenameOfPolymakeObject(poly));
end);

# the KNOWN PROPERTIES:
InstallMethod(KnownPropertiesOfPolymakeObject,
        "for PolymakeObject",
        [IsPolymakeObject],
        function(poly)
    if not "knownProperties" in NamesOfComponents(poly)
       then
        return fail;
    elif Size(RecNames(poly!.knownProperties))=0
      then
        return fail;
    else
        return poly!.knownProperties;
    fi;
end);

# just the names of the KNOWN PROPERTIES:
InstallMethod(NamesKnownPropertiesOfPolymakeObject,
        "for PolymakeObject",
        [IsPolymakeObject],
        function(poly)
    if not "knownProperties" in NamesOfComponents(poly)
       then
        return fail;
    elif Size(RecNames(poly!.knownProperties))=0
      then 
        return fail;
    else             
        return RecNames(poly!.knownProperties);
    fi;
end);

# individual properties from KNOWN PROPERTIES:
InstallMethod(PropertyOfPolymakeObject,
        [IsPolymakeObject,IsString],
        function(poly,name)
    local known;
    known:=NamesKnownPropertiesOfPolymakeObject(poly);
    if known=fail or not name in known
       then 
        return fail;
    else
        return poly!.knownProperties.(name);
    fi;
end);



######################################################################
# Changing the things we know about a object:
#


# Deleting files and clearing known data
#
InstallMethod(ClearPolymakeObject,
        [IsPolymakeObject],
        function(poly)
    CreateEmptyFile(FullFilenameOfPolymakeObject(poly));
    Unbind(poly!.knownProperties);
end);

# clear known data. Clear file and then set application, version,type 
# information
InstallMethod(ClearPolymakeObject,
        [IsPolymakeObject,IsDenseList],
        function(poly,appvertyp)
    local   appendstring;
    if not CheckAppVerTypList(appvertyp)
       then
        Error("application, version, type not well-formed");
    fi;
    CreateEmptyFile(FullFilenameOfPolymakeObject(poly));
    Unbind(poly!.knownProperties);
    appendstring:=Concatenation(["_application ",appvertyp[1],"\n",
                          "_version ",appvertyp[2],"\n",
                          "_type ",appvertyp[3],"\n"]
                          );
    AppendToPolymakeObject(poly,appendstring);
end);

# Deleting a something known:
#
InstallMethod(UnbindKnownPropertyOfPolymakeObject,
        [IsPolymakeObject,IsString],
        function(poly,name)
    local knownProperties;
    knownProperties:=KnownPropertiesOfPolymakeObject(poly);
    if knownProperties=fail or not name in knownProperties
       then
        return fail;
    else
        Unbind(poly!.knownProperties.(name));
    fi;
end);


# Write a property:
#
InstallMethod(WriteKnownPropertyToPolymakeObject,
        [IsPolymakeObject,IsString,IsObject],
        function(poly,name,data)
    if not "knownProperties" in NamesOfComponents(poly)
       then
        poly!.knownProperties:=rec();
    fi;
    poly!.knownProperties.(name):=data;
end);