File indexing completed on 2024-03-24 15:18:46

0001 /*
0002  * OriginAnyParser.h
0003  *
0004  * Copyright 2017 Miquel Garriga <gbmiquel@gmail.com>
0005  *
0006  * This program is free software: you can redistribute it and/or modify
0007  * it under the terms of the GNU General Public License as published by
0008  * the Free Software Foundation, either version 3 of the License, or
0009  * (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License
0017  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018  *
0019  * Parser for all versions. Based mainly on Origin750Parser.h
0020  */
0021 #ifndef ORIGIN_ANY_PARSER_H
0022 #define ORIGIN_ANY_PARSER_H
0023 
0024 #include "OriginParser.h"
0025 #include "endianfstream.hh"
0026 #include <string>
0027 #include <cmath> // for floor()
0028 
0029 using namespace std;
0030 using namespace Origin;
0031 
0032 class OriginAnyParser : public OriginParser
0033 {
0034 public:
0035     explicit OriginAnyParser(const string& fileName);
0036     bool parse() override;
0037 
0038 protected:
0039     unsigned int readObjectSize();
0040     string readObjectAsString(unsigned int);
0041     void readFileVersion();
0042     void readGlobalHeader();
0043     bool readDataSetElement();
0044     bool readWindowElement();
0045     bool readLayerElement();
0046     unsigned int readAnnotationList();
0047     bool readAnnotationElement();
0048     bool readCurveElement();
0049     bool readAxisBreakElement();
0050     bool readAxisParameterElement(unsigned int);
0051     bool readParameterElement();
0052     bool readNoteElement();
0053     void readProjectTree();
0054     unsigned int readFolderTree(tree<ProjectNode>::iterator, unsigned int);
0055     void readProjectLeaf(tree<ProjectNode>::iterator);
0056     void readAttachmentList();
0057     bool getColumnInfoAndData(const string&, unsigned int, const string&, unsigned int);
0058     void getMatrixValues(const string&, unsigned int, short, char, char, vector<Origin::Matrix>::difference_type);
0059     void getWindowProperties(Origin::Window&, const string&, unsigned int);
0060     void getLayerProperties(const string&, unsigned int);
0061     Origin::Color getColor(const string&);
0062     void getAnnotationProperties(const string&, unsigned int, const string&, unsigned int, const string&, unsigned int, const string&, unsigned int);
0063     void getCurveProperties(const string&, unsigned int, const string&, unsigned int);
0064     void getAxisBreakProperties(const string&, unsigned int);
0065     void getAxisParameterProperties(const string&, unsigned int, int);
0066     void getNoteProperties(const string&, unsigned int, const string&, unsigned int, const string&, unsigned int);
0067     void getColorMap(ColorMap&, const string&, unsigned int);
0068     void getZcolorsMap(ColorMap&, const string&, unsigned int);
0069     void getProjectLeafProperties(tree<ProjectNode>::iterator, const string&, unsigned int);
0070     void getProjectFolderProperties(tree<ProjectNode>::iterator, const string&, unsigned int);
0071     void outputProjectTree(std::ostream &);
0072 
0073     inline time_t doubleToPosixTime(double jdt)
0074     {
0075         /* 2440587.5 is julian date for the unixtime epoch */
0076         return (time_t) floor((jdt - 2440587) * 86400. + 0.5);
0077     }
0078 
0079     iendianfstream file;
0080     FILE *logfile;
0081 
0082     streamsize d_file_size;
0083     streamoff curpos;
0084     unsigned int objectIndex, parseError;
0085     vector<Origin::SpreadSheet>::difference_type ispread;
0086     vector<Origin::Matrix>::difference_type imatrix;
0087     vector<Origin::Excel>::difference_type iexcel;
0088     int igraph, ilayer;
0089 };
0090 
0091 #endif // ORIGIN_ANY_PARSER_H