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