casa
$Rev:20696$
|
00001 #ifndef SDMDataObjectParser_CLASS 00002 #define SDMDataObjectParser_CLASS 00003 00004 #include <iostream> 00005 #include <string> 00006 #include <vector> 00007 #include <libxml/parser.h> 00008 #include <libxml/tree.h> 00009 00010 00011 00012 #ifdef REG_BASIC 00013 #undef REG_BASIC 00014 #endif 00015 00016 #ifdef REG_EXTENDED 00017 #undef REG_EXTENDED 00018 #endif 00019 00020 #ifdef REG_ICASE 00021 #undef REG_ICASE 00022 #endif 00023 00024 #ifdef REG_NOSUB 00025 #undef REG_NOSUB 00026 #endif 00027 00028 #ifdef REG_NEWLINE 00029 #undef REG_NEWLINE 00030 #endif 00031 00032 #ifdef REG_NOTBOL 00033 #undef REG_NOTBOL 00034 #endif 00035 00036 #ifdef REG_NOTEOL 00037 #undef REG_NOTEOL 00038 #endif 00039 00040 #ifdef REG_STARTEND 00041 #undef REG_STARTEND 00042 #endif 00043 00044 #include <boost/regex.hpp> 00045 using namespace boost; 00046 00047 #include "SDMDataObject.h" 00048 00049 00050 #ifndef WITHOUT_ACS 00051 #include "almaEnumerations_IFC.h" 00052 #endif 00053 #include "CAtmPhaseCorrection.h" 00054 using namespace AtmPhaseCorrectionMod; 00055 00056 #include "CPrimitiveDataType.h" 00057 using namespace PrimitiveDataTypeMod; 00058 00059 #include "CCorrelatorType.h" 00060 using namespace CorrelatorTypeMod; 00061 00062 using namespace std; 00063 00064 namespace asdmbinaries { 00065 00070 class SDMDataObjectParserException { 00071 00072 public: 00076 SDMDataObjectParserException(); 00077 00082 SDMDataObjectParserException(string m); 00083 00087 virtual ~SDMDataObjectParserException(); 00088 00093 string getMessage() const; 00094 00095 protected: 00096 string message; 00097 00098 }; 00099 00100 inline SDMDataObjectParserException::SDMDataObjectParserException() : message ("SDMDataObjectParserException") {} 00101 inline SDMDataObjectParserException::SDMDataObjectParserException(string m) : message(m) {} 00102 inline SDMDataObjectParserException::~SDMDataObjectParserException() {} 00103 inline string SDMDataObjectParserException::getMessage() const { 00104 return "SDMDataObjectParserException : " + message; 00105 } 00106 00107 00108 // class HeaderParser 00109 class HeaderParser { 00110 friend class SDMDataObjectParser; 00111 friend class SDMDataObject; 00112 00113 public: 00114 HeaderParser(); 00115 virtual ~HeaderParser(); 00116 00117 void parseFile(const string& filename, SDMDataObject& sdmDataObject); 00118 void parseMemory(const string& buffer, SDMDataObject& sdmDataObject); 00119 00120 void reset(); 00121 00122 00123 00124 private: 00125 void parseSDMDataHeader(xmlNode* a_node, SDMDataObject& sdmDataObject); 00126 00127 // void parseProjectPath(xmlNode* a_node, SDMDataObject& sdmDataObject); 00128 long long parseStartTime(xmlNode* a_node); 00129 string parseDataOID(xmlNode* a_node); 00130 int parseDimensionality(xmlNode* a_node); 00131 int parseNumTime(xmlNode* a_node); 00132 void parseExecBlock(xmlNode* a_node, SDMDataObject& sdmDataObject); 00133 int parseExecBlockNum(xmlNode* a_node); 00134 int parseScanNum(xmlNode* a_node); 00135 int parseSubscanNum(xmlNode* a_node); 00136 00137 int parseNumAntenna(xmlNode* a_node); 00138 00139 void parseCorrelationMode(xmlNode* a_node, SDMDataObject& sdmDataObject); 00140 void parseSpectralResolution(xmlNode* a_node, SDMDataObject& sdmDataObject); 00141 void parseProcessorType(xmlNode* a_node, SDMDataObject& sdmDataObject); 00142 void parseDataStruct (xmlNode* a_node, SDMDataObject& sdmDataObject); 00143 00144 SDMDataObject::Baseband parseBaseband(xmlNode* a_node, SDMDataObject& sdmDataObject); 00145 00146 void parseSpectralWindow(xmlNode* a_node, SDMDataObject& sdmDataObject, vector<SDMDataObject::SpectralWindow>& spectralWindow); 00147 00148 SDMDataObject::BinaryPart parseBinaryPart(xmlNode* a_node, const string& attachmentName); 00149 SDMDataObject::AutoDataBinaryPart parseAutoDataBinaryPart(xmlNode* a_node, const string& attachmentName); 00150 SDMDataObject::ZeroLagsBinaryPart parseZeroLagsBinaryPart(xmlNode* a_node, const string& attachmentName); 00151 00152 // SDMDataObject::TypedBinaryPart parseTypedBinaryPart(xmlNode* a_node, const string& attachmentName); 00153 00154 xmlDoc *doc; 00155 00156 static const regex PROJECTPATH3; 00157 const static string SDMDATAHEADER; 00158 const static string SCHEMAVERSION; 00159 const static string BYTEORDER; 00160 const static string PROJECTPATH; 00161 const static string STARTTIME; 00162 const static string DATAOID; 00163 const static string XLINKHREF; 00164 const static string XLINKTITLE; 00165 00166 const static string DIMENSIONALITY; 00167 const static string NUMTIME; 00168 00169 const static string EXECBLOCK; 00170 const static string EXECBLOCKNUM; 00171 const static string SCANNUM; 00172 const static string SUBSCANNUM; 00173 00174 const static string NUMANTENNA; 00175 00176 const static string CORRELATIONMODE; 00177 const static string SPECTRALRESOLUTION; 00178 const static string PROCESSORTYPE; 00179 const static string DATASTRUCT; 00180 const static string APC; 00181 const static string REF; 00182 00183 const static string BASEBAND; 00184 const static string NAME; 00185 00186 const static string SPECTRALWINDOW; 00187 const static string SW; 00188 const static string SWBB; 00189 const static string CROSSPOLPRODUCTS; 00190 const static string SDPOLPRODUCTS; 00191 const static string SCALEFACTOR; 00192 const static string NUMSPECTRALPOINT; 00193 const static string NUMBIN; 00194 const static string SIDEBAND; 00195 const static string IMAGE; 00196 00197 const static string FLAGS; 00198 const static string ACTUALTIMES; 00199 const static string ACTUALDURATIONS; 00200 const static string ZEROLAGS; 00201 const static string CORRELATORTYPE; 00202 const static string CROSSDATA; 00203 const static string AUTODATA; 00204 const static string NORMALIZED; 00205 00206 const static string SIZE; 00207 const static string AXES; 00208 const static string TYPE; 00209 }; // class HeaderParser 00210 00211 // class CorrSubsetHeaderParser 00212 class CorrSubsetHeaderParser { 00213 friend class SDMDataSubset; 00214 00215 public: 00216 CorrSubsetHeaderParser(); 00217 virtual ~CorrSubsetHeaderParser(); 00218 void parseFile(const string& filename, SDMDataSubset& sdmCorrDataSubset); 00219 void parseMemory(const string& buffer, SDMDataSubset& sdmCorrDataSubset); 00220 void parseCrossDataType(xmlNode* a_node, SDMDataSubset& sdmCorrDataSubset); 00221 void reset(); 00222 00223 private: 00224 // Regular expressions used to decipher the content of projectPath attribute. 00225 static const regex PROJECTPATH4; 00226 static const regex PROJECTPATH5; 00227 00228 void parseSDMDataSubsetHeader(xmlNode* a_node, SDMDataSubset& sdmCorrDataSubset); 00229 // void parseProjectPath(xmlNode* a_node, SDMDataSubset& sdmCorrDataSubset); 00230 void parseSchedulePeriodTime(xmlNode* a_node, SDMDataSubset& sdmCorrDataSubset); 00231 long long parseTime(xmlNode* a_node); 00232 long long parseInterval(xmlNode* a_node); 00233 void parseAbortObservation(xmlNode* a_node, SDMDataSubset& sdmCorrDataSubset); 00234 00235 xmlDoc* doc; 00236 00237 const static string SDMDATASUBSETHEADER; 00238 const static string PROJECTPATH; 00239 const static string SCHEDULEPERIODTIME; 00240 const static string TIME; 00241 const static string INTERVAL; 00242 const static string DATASTRUCT; 00243 const static string REF; 00244 const static string ABORTOBSERVATION; 00245 const static string ABORTTIME; 00246 const static string ABORTREASON; 00247 const static string XLINKHREF; 00248 const static string DATAREF; 00249 const static string FLAGSREF; 00250 const static string ACTUALTIMESREF; 00251 const static string ACTUALDURATIONSREF; 00252 const static string ZEROLAGSREF; 00253 const static string CROSSDATAREF; 00254 const static string TYPE; 00255 const static string AUTODATAREF; 00256 }; // class CorrSubsetHeaderParser 00257 00258 00259 // class TPSubsetHeaderParser 00260 class TPSubsetHeaderParser { 00261 friend class SDMDataSubset; 00262 public: 00263 TPSubsetHeaderParser(); 00264 virtual ~TPSubsetHeaderParser(); 00265 void parseFile(const string& filename,SDMDataSubset& sdmTPDataSubset ); 00266 void parseMemory(const string& buffer,SDMDataSubset& sdmTPDataSubset ); 00267 void reset(); 00268 00269 private: 00270 // Regular expressions used to decipher the content of projectPath attribute. 00271 static const regex PROJECTPATH3; 00272 00273 void parseSDMDataSubsetHeader(xmlNode* a_node,SDMDataSubset& sdmTPDataSubset); 00274 // void parseProjectPath(xmlNode* a_node, SDMDataSubset& sdmTPDataSubset); 00275 void parseSchedulePeriodTime(xmlNode* a_node, SDMDataSubset& sdmCorrDataSubset); 00276 long long parseTime(xmlNode* a_node); 00277 long long parseInterval(xmlNode* a_node); 00278 string parseDataStructureDesc(xmlNode* a_node); 00279 void parseBinaryData(xmlNode* a_node, SDMDataSubset& sdmTPDataSubset); 00280 00281 xmlDoc* doc; 00282 00283 const static string SDMDATASUBSETHEADER; 00284 const static string PROJECTPATH; 00285 const static string SCHEDULEPERIODTIME; 00286 const static string TIME; 00287 const static string INTERVAL; 00288 const static string DATASTRUCT; 00289 const static string REF; 00290 const static string DATAREF; 00291 const static string XLINKHREF; 00292 const static string FLAGSREF; 00293 const static string ACTUALTIMESREF; 00294 const static string ACTUALDURATIONSREF; 00295 const static string AUTODATAREF; 00296 }; // class TPSubsetHeaderParser 00297 00298 00299 class SDMDataObjectParser { 00300 friend class SDMDataObject; 00301 friend class SDMDataSubset; 00302 friend class HeaderParser; 00303 00304 public: 00305 SDMDataObjectParser(); 00306 virtual ~SDMDataObjectParser(); 00307 void parseFileHeader(const string& filename, SDMDataObject& sdmDataObject); 00308 void parseMemoryHeader(const string& buffer, SDMDataObject& sdmDataObject); 00309 00310 void parseFileCorrSubsetHeader(const string& filename, SDMDataSubset& sdmCorrSubset); 00311 void parseMemoryCorrSubsetHeader(const string& buffer, SDMDataSubset& sdmCorrSubset); 00312 00313 void parseFileTPSubsetHeader(const string& filename, SDMDataSubset& sdmCorrDataSubset); 00314 void parseMemoryTPSubsetHeader(const string& filename, SDMDataSubset& sdmCorrDataSubset); 00315 00316 static void isElement(xmlNode* a_node, const string& elementName); 00317 static bool testElement(xmlNode* a_node, const string& elementName); 00318 static void inElements(xmlNode* a_node, const vector<string>& elementNames); 00319 00320 static xmlAttr* hasAttr(xmlNode* a_node, const string& attrName); 00321 00322 static void tokenize(const string& str, 00323 vector<string>& tokens, 00324 const string& delimiters = " "); 00325 00326 static void tokenize(const string& str, 00327 set<string>& tokens, 00328 const string& delimiters = " "); 00329 static string substring(const string &s, int a, int b); 00330 static string trim(const string &s); 00331 00332 static string parseString(xmlNode* a_node); 00333 static long long parseLongLong(xmlNode* a_node); 00334 static int parseInt(xmlNode* a_node); 00335 static bool parseBool(xmlNode* a_node); 00336 static float parseFloat(xmlNode* a_node); 00337 static int parseIntAttr(xmlNode* a_node, const string& attrName); 00338 static bool parseBoolAttr(xmlNode* a_node, const string& attrName); 00339 static float parseFloatAttr(xmlNode* a_node, const string& attrName); 00340 static string parseStringAttr(xmlNode* a_node, const string& attrName); 00341 static const ByteOrder* parseByteOrderAttr(xmlNode* a_node, const string& attrName); 00342 00343 template<class Enum, class EnumHelper> static Enum parseStringAttr(xmlNode* a_node, const string& attrName) { 00344 xmlAttr* attr = 0; 00345 00346 if ((attr = hasAttr(a_node, attrName))) { 00347 string s = string((const char*)attr->children->content); 00348 try { 00349 Enum result = EnumHelper::literal(SDMDataObjectParser::trim(s)); 00350 return result; 00351 } 00352 catch(string m) { 00353 throw SDMDataObjectParserException(m); 00354 } 00355 } 00356 else 00357 throw SDMDataObjectParserException("could not find attribute '" + attrName + "' in " + string((const char*)a_node->name)); 00358 } 00359 00360 template<class Enum, class EnumHelper> static Enum parseLiteral(xmlNode* a_node) { 00361 if ((a_node != NULL) && (a_node->next == NULL)) { 00362 try { 00363 Enum result = EnumHelper::literal(SDMDataObjectParser::trim(string((const char*) a_node->content))); 00364 return result; 00365 } 00366 catch (string m) { 00367 throw SDMDataObjectParserException(m); 00368 } 00369 } 00370 else 00371 throw SDMDataObjectParserException("The content of an element could not parsed into a literal"); 00372 } 00373 00374 00375 static vector<string> parseStringsAttr(xmlNode* a_node, const string& attrName); 00376 static set<string> parseStringSetAttr(xmlNode* a_node, const string& attrName); 00377 00378 template<class Enum, class EnumHelper> static vector<Enum> parseStringsAttr(xmlNode* a_node, const string& attrName) { 00379 xmlAttr* attr = 0; 00380 00381 if ((attr = hasAttr(a_node, attrName))) { 00382 vector<string> v_s; 00383 tokenize((const char*)attr->children->content, v_s); 00384 00385 vector<Enum> result; 00386 unsigned int i = 0; 00387 try { 00388 for (i = 0; i < v_s.size(); i++) 00389 result.push_back(EnumHelper::literal(v_s.at(i))); 00390 return result; 00391 } 00392 catch (string m) { 00393 throw SDMDataObjectParserException(m); 00394 } 00395 } 00396 else 00397 throw SDMDataObjectParserException("could not find attribute '" + attrName + "' in " + string((const char*)a_node->name)); 00398 } 00399 00400 static vector<unsigned int> parseProjectPath(xmlNode* a_node, unsigned int len); 00401 00402 static vector<unsigned int> parseProjectPath(xmlNode* a_node); 00403 00404 private: 00405 00406 static const regex PROJECTPATH3; 00407 static const regex PROJECTPATH4; 00408 static const regex PROJECTPATH5; 00409 static const regex PROJECTPATH4OR5; 00410 00411 HeaderParser headerParser; 00412 CorrSubsetHeaderParser corrSubsetHeaderParser; 00413 TPSubsetHeaderParser tpSubsetHeaderParser; 00414 00415 }; // class SDMDataObjectParser 00416 00417 00418 } // namespace asdmbinaries 00419 #endif // HeaderParser_CLASS