VHISTlib  1.84.0.3018
/daten/ahuesgen/projects/vhist/code/vhistlib/include/unvhistlib/vhistparser.h
00001 /* $HEADERS
00002  $Id: vhistparser.h 2792 2013-05-06 11:25:27Z michael $
00003  */
00004 
00005 #ifndef VHISTPARSER_INCLUDED
00006 #define VHISTPARSER_INCLUDED
00007 
00008 #include "../shared/misc_defines.h"
00009 
00010 #include "tags.h"
00011 
00012 #include "fileiterator.h"
00013 //#include "../shared/maybe.tpl"
00014 #include "../shared/logsource.h"
00015 
00016 #include <QObject>
00017 #include <QPair>
00018 #include <QSharedPointer>
00019 #include <QRegExp>
00020 
00021 class QString;
00022 
00023 namespace vhist
00024 {
00025 
00026 
00030 enum ParseMode
00031 {
00032     MODE_CORRECT = 0,
00033     MODE_ROBUST = 1
00034 };
00035 
00036 typedef QSharedPointer<SectionTag> MaybeSectionTag;
00037 typedef QSharedPointer<FileTag> MaybeFileTag;
00038 typedef QSharedPointer<QByteArray> MaybeBytes;
00039 
00040 
00041 // <compressed sum, uncompressed sum>
00042 typedef QPair<QString, QString> MD5Sums;
00043 
00044 
00045 void VHIST_EXTERN printSectionTag(const SectionTag& section);
00046 void VHIST_EXTERN printFileTag(const FileTag& file);
00047 
00048 
00061 class VHIST_EXTERN VhistParser : public LogSource
00062 {
00063     Q_OBJECT
00064     
00065     public: // construction, destruction and assignment
00066         VhistParser(ParseMode mode = MODE_ROBUST, QObject *pLogTarget = NULL);
00067         virtual ~VhistParser();
00068     
00069     public:
00070         bool open(const QString& filename);
00071         
00072         SectionTagList getSections();
00073         int getNumSections();
00074         
00075         FileTagList getFiles();
00076         int getNumFiles();
00077         FileTagList getFilesInSection(int sectionId);
00078         //FileTagList getFilesInNoSection();
00079         FileTagList getSectionlessFiles();
00080         
00081         MaybeSectionTag getSection(int id);
00082         MaybeFileTag getFile(int id);
00083         
00084         MaybeBytes getFileContent(int id);
00085         bool writeFileToDisk(int id, const QString& filename);
00086         MD5Sums calcChecksumsForFile(int id);
00087         
00088         QByteArray getBytes(int startPos, int numBytes);
00089     
00090     private:
00091         bool headerFound();
00092         SectionTagList readSections();
00093         FileTagList findFiles();
00094         
00095         QByteArray makeValidationTag(const QString& md5ToReplace);
00096         MaybeSectionTag findLastSection();
00097         MaybeSectionTag findPrevSection(const SectionTag& section);
00098         MaybeSectionTag parseSection(const QString& line);
00099         MaybeFileTag parseFile(const QString& file);
00100         
00101         bool fileInSection(const FileTag& file, const SectionTag& section);
00102         
00103         MaybeBytes getCompressedFile(int id);
00104         QByteArray decompressBytes(QByteArray& data,quint32 expectedSize);
00105     
00106     private:
00107         FileIterator m_iter;
00108         SectionTagList m_sections;
00109         FileTagList m_files;
00110         ParseMode m_mode;
00111 
00112     private:
00113         QRegExp m_fileRegex;
00114         QRegExp m_sectionRegex;
00115 };
00116 
00117 
00118 } // namespace
00119 
00120 #endif // VHISTPARSER_INCLUDED
00121 

VHISTlib 1.84.0.3018 of Jun 28 2013, generated by doxygen.