1
1
#include "polymakefile.h"
7
PolymakeProperty::PolymakeProperty(const string &name_, const string &value_):
8
bool PolymakeFile::xmlForced=false;
10
static void eatComment2(int &c, stringstream &s)
16
while(c!='\n' && !s.eof());
20
static void eatComment(stringstream &s)
23
while(c==' '||c=='\t')c=s.get();
28
PolymakeProperty::PolymakeProperty(const string &name_, const string &value_, bool embedded_):
50
const char *PolymakeFile::mapToPolymakeNames(const char *s)
53
if(strcmp(s,"CONES_ORBITS")==0)return "CONES_REPS";
54
if(strcmp(s,"MAXIMAL_CONES_ORBITS")==0)return "MAXIMAL_CONES_REPS";
28
60
void PolymakeFile::open(const char *fileName_)
30
63
fileName=string(fileName_);
32
65
FILE *f=fopen(fileName.c_str(),"r");
66
if(!f)fprintf(Stderr,"Could not open file:\"%s\"\n",fileName_);
62
void PolymakeFile::create(const char *fileName_, const char *application_, const char *type_)
96
void PolymakeFile::create(const char *fileName_, const char *application_, const char *type_, bool isXml_)
64
98
fileName=string(fileName_);
65
99
application=string(application_);
66
100
type=string(type_);
102
if(xmlForced){isXml=true;}
70
107
void PolymakeFile::close()
72
FILE *f=fopen(fileName.c_str(),"w");
109
FILE *f=fopen(fileName.c_str(),"w");
75
fprintf(f,"_application %s\n",application.c_str());
76
fprintf(f,"_version 2.2\n");
77
fprintf(f,"_type %s\n",type.c_str());
79
for(list<PolymakeProperty>::const_iterator i=properties.begin();i!=properties.end();i++)
81
fprintf(f,"\n%s\n",i->name.c_str());
82
fprintf(f,"%s",i->value.c_str());
113
fprintf(f,"<properties>\n");
115
for(list<PolymakeProperty>::const_iterator i=properties.begin();i!=properties.end();i++)
119
fprintf(f,"<property name=\"%s\" value=\"%s\" />\n",mapToPolymakeNames(i->name.c_str()),i->value.c_str());
123
fprintf(f,"<property name=\"%s\">\n",mapToPolymakeNames(i->name.c_str()));
124
fprintf(f,"%s",i->value.c_str());
125
fprintf(f,"</property>\n");
128
fprintf(f,"</properties>\n");
132
fprintf(f,"_application %s\n",application.c_str());
133
fprintf(f,"_version 2.2\n");
134
fprintf(f,"_type %s\n",type.c_str());
136
for(list<PolymakeProperty>::const_iterator i=properties.begin();i!=properties.end();i++)
138
fprintf(f,"\n%s\n",i->name.c_str());
139
fprintf(f,"%s",i->value.c_str());
89
146
void PolymakeFile::writeStream(ostream &file)
91
file << "_application " << application << endl;
92
file << "_version 2.2\n";
93
file << "_type " << type << endl;
95
for(list<PolymakeProperty>::const_iterator i=properties.begin();i!=properties.end();i++)
97
file << endl << i->name.c_str() << endl;
150
file << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
151
file << "<object name=\"1\" type=\""<<application<<"::"<<type<<"<Rational>\" version=\"2.9.9\" xmlns=\"http://www.math.tu-berlin.de/polymake/#3\">\n";
153
for(list<PolymakeProperty>::const_iterator i=properties.begin();i!=properties.end();i++)
157
file << "<property name=\""<<mapToPolymakeNames(i->name.c_str())<< "\" value=\""<<i->value.c_str()<<"\" />\n";
161
file << "<property name=\"" << mapToPolymakeNames(i->name.c_str()) << "\">\n";
162
file << i->value.c_str();
163
file << "</property>\n";
166
file << "</object>\n";
170
file << "_application " << application << endl;
171
file << "_version 2.2\n";
172
file << "_type " << type << endl;
174
for(list<PolymakeProperty>::const_iterator i=properties.begin();i!=properties.end();i++)
176
file << endl << i->name.c_str() << endl;
115
void PolymakeFile::writeProperty(const char *p, const string &data)
195
void PolymakeFile::writeProperty(const char *p, const string &data, bool embedded)
117
197
if(hasProperty(p))
121
properties.push_back(PolymakeProperty(string(p),data));
201
properties.push_back(PolymakeProperty(string(p),data,embedded));
125
bool PolymakeFile::hasProperty(const char *p)
205
bool PolymakeFile::hasProperty(const char *p, bool doAssert)
208
if(findProperty(p)==properties.end())
210
fprintf(stderr,"Property: \"%s\" not found in file.\n",p);
127
214
return findProperty(p)!=properties.end();
131
218
int PolymakeFile::readCardinalProperty(const char *p)
133
assert(hasProperty(p));
220
assert(hasProperty(p,true));
134
222
list<PolymakeProperty>::iterator prop=findProperty(p);
135
223
stringstream s(prop->value);
182
void PolymakeFile::writeMatrixProperty(const char *p, const IntegerMatrix &m, bool indexed)
186
for(int i=0;i<m.getHeight();i++)
188
for(int j=0;j<m.getWidth();j++)
193
if(indexed)t<<"\t# "<<i;
292
void PolymakeFile::writeMatrixProperty(const char *p, const IntegerMatrix &m, bool indexed, const vector<string> *comments)
296
if(comments)assert(comments->size()>=m.getHeight());
300
for(int i=0;i<m.getHeight();i++)
303
for(int j=0;j<m.getWidth();j++)
314
for(int i=0;i<m.getHeight();i++)
316
for(int j=0;j<m.getWidth();j++)
321
if(indexed)t<<"\t# "<<i;
322
if(comments)t<<"\t# "<<(*comments)[i];
326
writeProperty(p,t.str());
329
IntegerMatrix PolymakeFile::readArrayArrayIntProperty(const char *p, int width)
331
assert(0);//Not implemented yet.
335
void PolymakeFile::writeArrayArrayIntProperty(const char *p, const IntegerMatrix &m)
342
for(int i=0;i<m.getHeight();i++)
345
for(int j=0;j<m.getWidth();j++)
356
for(int i=0;i<m.getHeight();i++)
358
for(int j=0;j<m.getWidth();j++)
196
366
writeProperty(p,t.str());
215
385
vector<list<int> > PolymakeFile::readMatrixIncidenceProperty(const char *p)
217
387
vector<list<int> > ret;
218
assert(hasProperty(p));
388
assert(hasProperty(p,true));
219
389
list<PolymakeProperty>::iterator prop=findProperty(p);
220
390
stringstream s(prop->value);
222
392
while((s.peek()!=-1)&&(s.peek()!='\n')&&(s.peek()!=0))
224
fprintf(Stderr,"!\n");
394
// fprintf(Stderr,"!\n");
226
fprintf(Stderr,"%i",c);
396
//fprintf(Stderr,"%i",c);
228
398
ret.push_back(readIntList(s));
402
while(c==' ' || c=='\t')c=s.get();
238
void PolymakeFile::writeIncidenceMatrixProperty(const char *p, const vector<list<int> > &m)
410
void PolymakeFile::writeIncidenceMatrixProperty(const char *p, const vector<list<int> > &m, int baseSetSize)
241
for(int i=0;i<m.size();i++)
246
for(list<int>::const_iterator j=temp.begin();j!=temp.end();j++)
248
if(j!=temp.begin())t<<' ';
416
t<<"<m cols=\""<<baseSetSize<<"\">";
417
for(int i=0;i<m.size();i++)
422
for(list<int>::const_iterator j=temp.begin();j!=temp.end();j++)
424
if(j!=temp.begin())t<<' ';
433
for(int i=0;i<m.size();i++)
438
for(list<int>::const_iterator j=temp.begin();j!=temp.end();j++)
440
if(j!=temp.begin())t<<' ';
253
446
writeProperty(p,t.str());