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