00001
00016 #include "OSgLWriter.h"
00017 #include "OSStringUtil.h"
00018 #include "OSGeneral.h"
00019 #include "OSParameters.h"
00020 #include "OSBase64.h"
00021 #include "OSMathUtil.h"
00022 #include "CoinFinite.hpp"
00023
00024 #include <sstream>
00025
00026 using std::endl;
00027 using std::ostringstream;
00028
00029
00036 std::string writeGeneralFileHeader(GeneralFileHeader *v, bool addWhiteSpace)
00037 {
00038 ostringstream outStr;
00039
00040 if (v->name != "")
00041 {
00042 outStr << "<name>" << v->name << "</name>" ;
00043 if(addWhiteSpace == true) outStr << endl;
00044 }
00045
00046 if (v->source != "")
00047 {
00048 outStr << "<source>" << v->source << "</source>" ;
00049 if(addWhiteSpace == true) outStr << endl;
00050 }
00051
00052 if (v->description != "")
00053 {
00054 outStr << "<description>" << v->description << "</description>" ;
00055 if(addWhiteSpace == true) outStr << endl;
00056 }
00057
00058 if (v->fileCreator != "")
00059 {
00060 outStr << "<fileCreator>" << v->fileCreator << "</fileCreator>" ;
00061 if(addWhiteSpace == true) outStr << endl;
00062 }
00063
00064 if (v->licence != "")
00065 {
00066 outStr << "<licence>" << v->licence << "</licence>" ;
00067 if(addWhiteSpace == true) outStr << endl;
00068 }
00069 return outStr.str();
00070 }
00071
00072
00081 std::string writeOtherOptionOrResultEnumeration(OtherOptionOrResultEnumeration *e, bool addWhiteSpace, bool writeBase64)
00082 {
00083 ostringstream outStr;
00084
00085 outStr << "<enumeration ";
00086 outStr << "numberOfEl=\"" << e->numberOfEl << "\" ";
00087 if (e->value != "") outStr << "value=\"" << e->value << "\" ";
00088 if (e->description != "") outStr << "description=\"" << e->description << "\" ";
00089 outStr << ">";
00090 outStr << writeIntVectorData(e, addWhiteSpace, writeBase64);
00091 outStr << "</enumeration>";
00092 return outStr.str();
00093 }
00094
00095
00104 std::string writeIntVectorData(IntVector *v, bool addWhiteSpace, bool writeBase64)
00105 {
00106 ostringstream outStr;
00107 int mult, incr;
00108
00109 if (v->numberOfEl > 0)
00110 {
00111 if(writeBase64 == false)
00112 {
00113 for(int i = 0; i < v->numberOfEl;)
00114 {
00115 getMultIncr(&(v->el[i]), &mult, &incr, (v->numberOfEl) - i, 0);
00116 if (mult == 1)
00117 outStr << "<el>" ;
00118 else if (incr == 0)
00119 outStr << "<el mult=\"" << mult << "\">";
00120 else
00121 outStr << "<el mult=\"" << mult << "\" incr=\"" << incr << "\">";
00122 outStr << v->el[i];
00123 outStr << "</el>" ;
00124 if(addWhiteSpace == true) outStr << endl;
00125 i += mult;
00126 }
00127 }
00128 else
00129 {
00130 outStr << "<base64BinaryData sizeOf=\"" << sizeof(int) << "\">" ;
00131 outStr << Base64::encodeb64( (char*)v->el, (v->numberOfEl)*sizeof(int) );
00132 outStr << "</base64BinaryData>" ;
00133 if(addWhiteSpace == true) outStr << endl;
00134 }
00135 }
00136 return outStr.str();
00137 }
00138
00139
00148 std::string writeDblVectorData(DoubleVector *v, bool addWhiteSpace, bool writeBase64)
00149 {
00150 ostringstream outStr;
00151 int mult;
00152
00153 if (v->numberOfEl > 0)
00154 {
00155 if(writeBase64 == false)
00156 {
00157 for(int i = 0; i < v->numberOfEl;)
00158 {
00159 mult = getMult(&(v->el[i]), (v->numberOfEl) - i);
00160 if (mult == 1)
00161 outStr << "<el>" ;
00162 else
00163 outStr << "<el mult=\"" << mult << "\">";
00164 outStr << os_dtoa_format(v->el[i] );
00165 outStr << "</el>" ;
00166 if(addWhiteSpace == true) outStr << endl;
00167 i += mult;
00168 }
00169 }
00170 else
00171 {
00172 outStr << "<base64BinaryData sizeOf=\"" << sizeof(double) << "\">" ;
00173 outStr << Base64::encodeb64( (char*)v->el, (v->numberOfEl)*sizeof(double) );
00174 outStr << "</base64BinaryData>" ;
00175 if(addWhiteSpace == true) outStr << endl;
00176 }
00177 }
00178 return outStr.str();
00179 }
00180
00181
00190 std::string writeBasisStatus(BasisStatus *bs, bool addWhiteSpace, bool writeBase64)
00191 {
00192 ostringstream outStr;
00193
00194 if (bs->basic != NULL)
00195 {
00196 outStr << "<basic numberOfEl=\"" << bs->basic->numberOfEl << "\">";
00197 if(addWhiteSpace == true) outStr << endl;
00198 outStr << writeIntVectorData(bs->basic, addWhiteSpace, writeBase64);
00199 outStr << "</basic>";
00200 if(addWhiteSpace == true) outStr << endl;
00201 }
00202
00203 if (bs->atLower != NULL)
00204 {
00205 outStr << "<atLower numberOfEl=\"" << bs->atLower->numberOfEl << "\">";
00206 if(addWhiteSpace == true) outStr << endl;
00207 outStr << writeIntVectorData(bs->atLower, addWhiteSpace, writeBase64);
00208 outStr << "</atLower>";
00209 if(addWhiteSpace == true) outStr << endl;
00210 }
00211
00212 if (bs->atUpper != NULL)
00213 {
00214 outStr << "<atUpper numberOfEl=\"" << bs->atUpper->numberOfEl << "\">";
00215 if(addWhiteSpace == true) outStr << endl;
00216 outStr << writeIntVectorData(bs->atUpper, addWhiteSpace, writeBase64);
00217 outStr << "</atUpper>";
00218 if(addWhiteSpace == true) outStr << endl;
00219 }
00220
00221 if (bs->atEquality != NULL)
00222 {
00223 outStr << "<atEquality numberOfEl=\"" << bs->atEquality->numberOfEl << "\">";
00224 if(addWhiteSpace == true) outStr << endl;
00225 outStr << writeIntVectorData(bs->atEquality, addWhiteSpace, writeBase64);
00226 outStr << "</atEquality>";
00227 if(addWhiteSpace == true) outStr << endl;
00228 }
00229
00230 if (bs->isFree != NULL)
00231 {
00232 outStr << "<isFree numberOfEl=\"" << bs->isFree->numberOfEl << "\">";
00233 if(addWhiteSpace == true) outStr << endl;
00234 outStr << writeIntVectorData(bs->isFree, addWhiteSpace, writeBase64);
00235 outStr << "</isFree>";
00236 if(addWhiteSpace == true) outStr << endl;
00237 }
00238
00239 if (bs->superbasic != NULL)
00240 {
00241 outStr << "<superbasic numberOfEl=\"" << bs->superbasic->numberOfEl << "\">";
00242 if(addWhiteSpace == true) outStr << endl;
00243 outStr << writeIntVectorData(bs->superbasic, addWhiteSpace, writeBase64);
00244 outStr << "</superbasic>";
00245 if(addWhiteSpace == true) outStr << endl;
00246 }
00247
00248 if (bs->unknown != NULL)
00249 {
00250 outStr << "<unknown numberOfEl=\"" << bs->unknown->numberOfEl << "\">";
00251 if(addWhiteSpace == true) outStr << endl;
00252 outStr << writeIntVectorData(bs->unknown, addWhiteSpace, writeBase64);
00253 outStr << "</unknown>";
00254 if(addWhiteSpace == true) outStr << endl;
00255 }
00256
00257 return outStr.str();
00258 }