Open PaperOpt
OpenPaperOpt/XMLParser.h
Go to the documentation of this file.
00001 
00005 #ifndef XMLPARSER_H
00006 #define XMLPARSER_H
00007 
00008 // INCLUDES
00009 #include <exception>
00010 #include <string>
00011 #include <stack>
00012 #include <vector>
00013 #include <map>
00014 #include <fstream>
00015 #include <sstream>
00016 #include <complex>
00017 
00018 #include "Array2D.h"
00019 #include "irrXML.h"
00020 #include "Fluorescence.h"
00021 #include "Distribution.h"
00022 #include "DistributionTable.h"
00023 #include "DistributionElliptic.h"
00024 #include "DistributionConstant.h"
00025 #include "DistributionComponents.h"
00026 #include "ScatteringParameters.h"
00027 #ifdef ENABLEHDF
00028 #include "hdf5.h"
00029 #include "h5cpp.h"
00030 #endif
00031 
00032 using namespace irr;
00033 using namespace io;
00034 using namespace std;
00035 using namespace Distributions;
00036 
00037 
00038 //Global variables defined in Input.cpp
00039 extern std::string gBinaryDirectory;
00040 extern bool gIsBigendian;
00041 
00042 namespace IO{
00043         //Forward declarations.
00044         class File;
00045         class BinaryFile;
00046         class TextFile;
00047 
00048 #ifdef ENABLEHDF
00049         class HDFFile;
00050 #endif
00051 
00064         class XMLParser
00065         {
00066 
00067         public:
00072                 XMLParser();
00073 
00077                 ~XMLParser();
00078 
00085                 void init(string xmlFile);
00086 
00092                 bool readNextTag();
00093 
00101                 string getNextText(void);
00102 
00103 
00109                 string getElementName();
00110 
00116                 void pushEndTag(string s){mTagStack.push(s);};
00117 
00121                 void popEndTag(){mTagStack.pop();};
00122 
00134                 string getAttribute(string s);
00135 
00144                 float getAttributeAsFloat(string s);
00145 
00152                 int getAttributeAsInt(string s);
00153 
00160                 bool isCurElement(char* elm);
00161 
00167                 Array2D<float>* parseFloatArray();
00168 
00176                 Array2D<float>* parseHeightMap(float& sizeX, float& sizeY);
00177 
00184                 Array2D< V2<float> >* parseV2FloatArray();
00185 
00186 
00193                 Array2D< V3<float> >* parseV3FloatArray();
00194 
00195 
00201                 int parseFloatList(vector<float> &list);
00202 
00208                 float parseFloat();
00209 
00215                 int parseInt();
00216 
00222                 bool parseBool();
00223 
00224 
00230                 string parseString();
00231 
00237                 Distribution* parseDistribution();
00238 
00244                 DistributionTable* parseTableDistribution();
00245 
00251                 DistributionElliptic* parseEllipticDistribution();
00252 
00258                 DistributionConstant* parseConstantDistribution();
00259 
00264                 DistributionComponents* parseComponentsDistribution();
00265 
00270                 ScatteringParameters* parseScatteringProperties(vector<float>& rLambda);
00271 
00278                 Fluorescence* parseFluorescence(vector<float>& rLambda);
00279 
00280 
00287                 reflectanceParameters* parseReflectance(vector<float>& rLambda);
00288 
00289 
00295                 XMLParser::BinaryFile* parseBinaryFile();
00296 
00302                 XMLParser::TextFile* parseTextFile();   
00303 
00304 #ifdef ENABLEHDF
00305 
00310                 XMLParser::HDFFile* parseHDFFile();
00311 #endif
00312                 
00313         private:
00314                 IrrXMLReader* mIrrXMLReader;
00315                 bool mInitialized;
00316                 stack<string> mTagStack;
00317         };
00318 
00319 
00320 
00324         class File{
00325         public:
00326                 File(void);
00327                 virtual double readDouble() = 0;
00328                 virtual float readFloat() = 0;
00329                 virtual int readInt() = 0;
00330                 virtual bool eof() = 0;
00331         };
00332 
00339         class BinaryFile: public File{
00340         public:
00341 
00351                 BinaryFile(const string& rFilename, int offset, bool isBigEndian);                              
00352                 ~BinaryFile();
00353                 double readDouble(void);
00354                 float readFloat(void);
00355                 int readInt (void);
00356                 bool eof();
00357         private:
00358                 double (*readDoublePtr) (fstream& _mfile);
00359                 float (*readFloatPtr)(fstream& _mfile);
00360                 int (*readIntPtr) (fstream& _mfile);
00361                 static double readDoubleNoSwap(fstream& _mfile);
00362                 static float readFloatNoSwap(fstream& _mfile);
00363                 static int readIntNoSwap(fstream& _mfile);
00364                 static double readDoubleSwap(fstream& _mfile);
00365                 static float readFloatSwap(fstream& _mfile);
00366                 static int readIntSwap(fstream& _mfile);
00367                 bool mIsBigEndian;
00368                 int mOffset;
00369                 fstream mFile;
00370         };
00371 
00376         class TextFile: public File{
00377         public:
00378                 TextFile(const string& rFilename, char delim);                          
00379                 ~TextFile();
00380                 double readDouble();
00381                 float readFloat();
00382                 int readInt();
00383                 bool eof();
00384         private:
00385                 ifstream mFile;
00386                 char mDelim;
00387         };
00388 
00389 #ifdef ENABLEHDF
00390 
00395         class HDFFile: public File{
00396         public:
00397                 HDFFile(H5::H5File* pFile,const string& rDataset, const string& rGroup);                                
00398                 ~HDFFile();
00399                 
00400                 double readDouble();
00401                 float readFloat();
00402                 int readInt();
00403                 bool eof();
00404 
00410                 H5::DataSpace* getDataSpace();
00411         private:
00412                 char* mBuf;   //Whole dataset is read into this buffer in constructor.
00413                 long mOffset;  //keeps track of which byte to read from.
00414                 long mSize;   //Size in bytes of data.
00415                 H5::DataSet mDataset;
00416                 H5::Group mGroup;
00417                 H5::H5File* mFile;
00418         };
00419 #endif
00420 }
00421 #endif //XMLPARSER