OSgLWriter.cpp
Go to the documentation of this file.
1 /* $Id: OSgLWriter.cpp 3729 2010-10-18 12:25:22Z Gassmann $ */
16 #include "OSgLWriter.h"
17 #include "OSStringUtil.h"
18 #include "OSGeneral.h"
19 #include "OSParameters.h"
20 #include "OSBase64.h"
21 #include "OSMathUtil.h"
22 #include "CoinFinite.hpp"
23 
24 #include <sstream>
25 
26 using std::endl;
27 using std::ostringstream;
28 
29 
36 std::string writeGeneralFileHeader(GeneralFileHeader *v, bool addWhiteSpace)
37 {
38  ostringstream outStr;
39 
40  if (v->name != "")
41  {
42  outStr << "<name>" << v->name << "</name>" ;
43  if(addWhiteSpace == true) outStr << endl;
44  }
45 
46  if (v->source != "")
47  {
48  outStr << "<source>" << v->source << "</source>" ;
49  if(addWhiteSpace == true) outStr << endl;
50  }
51 
52  if (v->description != "")
53  {
54  outStr << "<description>" << v->description << "</description>" ;
55  if(addWhiteSpace == true) outStr << endl;
56  }
57 
58  if (v->fileCreator != "")
59  {
60  outStr << "<fileCreator>" << v->fileCreator << "</fileCreator>" ;
61  if(addWhiteSpace == true) outStr << endl;
62  }
63 
64  if (v->licence != "")
65  {
66  outStr << "<licence>" << v->licence << "</licence>" ;
67  if(addWhiteSpace == true) outStr << endl;
68  }
69  return outStr.str();
70 }// end writeGeneralFileHeader
71 
72 
81 std::string writeOtherOptionOrResultEnumeration(OtherOptionOrResultEnumeration *e, bool addWhiteSpace, bool writeBase64)
82 {
83  ostringstream outStr;
84 
85  outStr << "<enumeration ";
86  outStr << "numberOfEl=\"" << e->numberOfEl << "\" ";
87  if (e->value != "") outStr << "value=\"" << e->value << "\" ";
88  if (e->description != "") outStr << "description=\"" << e->description << "\" ";
89  outStr << ">";
90  outStr << writeIntVectorData(e, addWhiteSpace, writeBase64);
91  outStr << "</enumeration>";
92  return outStr.str();
93 }// end writeOtherOptionOrResultEnumeration
94 
95 
104 std::string writeIntVectorData(IntVector *v, bool addWhiteSpace, bool writeBase64)
105 {
106  ostringstream outStr;
107  int mult, incr;
108 
109  if (v->numberOfEl > 0)
110  {
111  if(writeBase64 == false)
112  {
113  for(int i = 0; i < v->numberOfEl;)
114  {
115  getMultIncr(&(v->el[i]), &mult, &incr, (v->numberOfEl) - i, 0);
116  if (mult == 1)
117  outStr << "<el>" ;
118  else if (incr == 0)
119  outStr << "<el mult=\"" << mult << "\">";
120  else
121  outStr << "<el mult=\"" << mult << "\" incr=\"" << incr << "\">";
122  outStr << v->el[i];
123  outStr << "</el>" ;
124  if(addWhiteSpace == true) outStr << endl;
125  i += mult;
126  }
127  }
128  else
129  {
130  outStr << "<base64BinaryData sizeOf=\"" << sizeof(int) << "\">" ;
131  outStr << Base64::encodeb64( (char*)v->el, (v->numberOfEl)*sizeof(int) );
132  outStr << "</base64BinaryData>" ;
133  if(addWhiteSpace == true) outStr << endl;
134  }
135  }
136  return outStr.str();
137 }// end writeIntVectorData
138 
139 
148 std::string writeDblVectorData(DoubleVector *v, bool addWhiteSpace, bool writeBase64)
149 {
150  ostringstream outStr;
151  int mult;
152 
153  if (v->numberOfEl > 0)
154  {
155  if(writeBase64 == false)
156  {
157  for(int i = 0; i < v->numberOfEl;)
158  {
159  mult = getMult(&(v->el[i]), (v->numberOfEl) - i);
160  if (mult == 1)
161  outStr << "<el>" ;
162  else
163  outStr << "<el mult=\"" << mult << "\">";
164  outStr << os_dtoa_format(v->el[i] );
165  outStr << "</el>" ;
166  if(addWhiteSpace == true) outStr << endl;
167  i += mult;
168  }
169  }
170  else
171  {
172  outStr << "<base64BinaryData sizeOf=\"" << sizeof(double) << "\">" ;
173  outStr << Base64::encodeb64( (char*)v->el, (v->numberOfEl)*sizeof(double) );
174  outStr << "</base64BinaryData>" ;
175  if(addWhiteSpace == true) outStr << endl;
176  }
177  }
178  return outStr.str();
179 }// end writeDblVectorData
180 
181 
190 std::string writeBasisStatus(BasisStatus *bs, bool addWhiteSpace, bool writeBase64)
191 {
192  ostringstream outStr;
193 
194  if (bs->basic != NULL)
195  {
196  outStr << "<basic numberOfEl=\"" << bs->basic->numberOfEl << "\">";
197  if(addWhiteSpace == true) outStr << endl;
198  outStr << writeIntVectorData(bs->basic, addWhiteSpace, writeBase64);
199  outStr << "</basic>";
200  if(addWhiteSpace == true) outStr << endl;
201  }
202 
203  if (bs->atLower != NULL)
204  {
205  outStr << "<atLower numberOfEl=\"" << bs->atLower->numberOfEl << "\">";
206  if(addWhiteSpace == true) outStr << endl;
207  outStr << writeIntVectorData(bs->atLower, addWhiteSpace, writeBase64);
208  outStr << "</atLower>";
209  if(addWhiteSpace == true) outStr << endl;
210  }
211 
212  if (bs->atUpper != NULL)
213  {
214  outStr << "<atUpper numberOfEl=\"" << bs->atUpper->numberOfEl << "\">";
215  if(addWhiteSpace == true) outStr << endl;
216  outStr << writeIntVectorData(bs->atUpper, addWhiteSpace, writeBase64);
217  outStr << "</atUpper>";
218  if(addWhiteSpace == true) outStr << endl;
219  }
220 
221  if (bs->atEquality != NULL)
222  {
223  outStr << "<atEquality numberOfEl=\"" << bs->atEquality->numberOfEl << "\">";
224  if(addWhiteSpace == true) outStr << endl;
225  outStr << writeIntVectorData(bs->atEquality, addWhiteSpace, writeBase64);
226  outStr << "</atEquality>";
227  if(addWhiteSpace == true) outStr << endl;
228  }
229 
230  if (bs->isFree != NULL)
231  {
232  outStr << "<isFree numberOfEl=\"" << bs->isFree->numberOfEl << "\">";
233  if(addWhiteSpace == true) outStr << endl;
234  outStr << writeIntVectorData(bs->isFree, addWhiteSpace, writeBase64);
235  outStr << "</isFree>";
236  if(addWhiteSpace == true) outStr << endl;
237  }
238 
239  if (bs->superbasic != NULL)
240  {
241  outStr << "<superbasic numberOfEl=\"" << bs->superbasic->numberOfEl << "\">";
242  if(addWhiteSpace == true) outStr << endl;
243  outStr << writeIntVectorData(bs->superbasic, addWhiteSpace, writeBase64);
244  outStr << "</superbasic>";
245  if(addWhiteSpace == true) outStr << endl;
246  }
247 
248  if (bs->unknown != NULL)
249  {
250  outStr << "<unknown numberOfEl=\"" << bs->unknown->numberOfEl << "\">";
251  if(addWhiteSpace == true) outStr << endl;
252  outStr << writeIntVectorData(bs->unknown, addWhiteSpace, writeBase64);
253  outStr << "</unknown>";
254  if(addWhiteSpace == true) outStr << endl;
255  }
256 
257  return outStr.str();
258 }// end writeBasisStatus
IntVector * atUpper
Definition: OSGeneral.h:650
IntVector * superbasic
Definition: OSGeneral.h:653
IntVector * basic
Definition: OSGeneral.h:648
int numberOfEl
Definition: OSGeneral.h:483
std::string description
further information about the file or the problem contained within it
Definition: OSGeneral.h:50
std::string fileCreator
name(s) of author(s) who created this file
Definition: OSGeneral.h:55
std::string writeIntVectorData(IntVector *v, bool addWhiteSpace, bool writeBase64)
Take an IntVector object and write a string that validates against the OSgL schema.
Definition: OSgLWriter.cpp:104
static std::string encodeb64(char *bytes, int size)
encode the data in base 64
Definition: OSBase64.cpp:33
IntVector * isFree
Definition: OSGeneral.h:652
std::string name
used to give a name to the file or the problem contained within it
Definition: OSGeneral.h:39
IntVector * atLower
Definition: OSGeneral.h:649
IntVector * atEquality
Definition: OSGeneral.h:651
a data structure that holds general information about files that conform to one of the OSxL schemas ...
Definition: OSGeneral.h:32
int numberOfEl
Definition: OSGeneral.h:620
std::string writeOtherOptionOrResultEnumeration(OtherOptionOrResultEnumeration *e, bool addWhiteSpace, bool writeBase64)
Take an OtherOptionOrResultEnumeration object and write a string that validates against the OSgL sche...
Definition: OSgLWriter.cpp:81
void fint fint fint real fint real real real real real real real real real * e
a double vector data structure
Definition: OSGeneral.h:609
IntVector * unknown
Definition: OSGeneral.h:654
std::string writeBasisStatus(BasisStatus *bs, bool addWhiteSpace, bool writeBase64)
Take a BasisStatus object and write a string that validates against the OSgL schema.
Definition: OSgLWriter.cpp:190
int getMult(int *i, int size)
getMult
Definition: OSMathUtil.h:246
void getMultIncr(int *i, int *mult, int *incr, int size, int defaultIncr)
getMultIncr
Definition: OSMathUtil.h:168
static int
Definition: OSdtoa.cpp:2173
std::string writeDblVectorData(DoubleVector *v, bool addWhiteSpace, bool writeBase64)
Take a DoubleVector object and write a string that validates against the OSgL schema.
Definition: OSgLWriter.cpp:148
an integer Vector data structure
Definition: OSGeneral.h:469
static Bigint * mult(Bigint *a, Bigint *b)
Definition: OSdtoa.cpp:857
std::string source
used when the file or problem appeared in the literature (could be in BiBTeX format or similar) ...
Definition: OSGeneral.h:45
std::string os_dtoa_format(double x)
Definition: OSMathUtil.cpp:154
double * el
Definition: OSGeneral.h:621
std::string writeGeneralFileHeader(GeneralFileHeader *v, bool addWhiteSpace)
Take a GeneralFileHeader object and write a string that validates against the OSgL schema...
Definition: OSgLWriter.cpp:36
int * el
Definition: OSGeneral.h:484
a data structure to represent an LP basis on both input and output
Definition: OSGeneral.h:645
std::string licence
licensing information if applicable
Definition: OSGeneral.h:60