DeltaQt
Version 0.2.0 End user documentation
A C++/Qt library for parsing DELTA (DEscription Language for TAxonomy) files
|
00001 /* Copyright 2012 Craig Robbins 00002 00003 This file is part of DeltaQt 00004 00005 DeltaQt is free software: you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation, either version 3 of the License, or 00008 (at your option) any later version. 00009 00010 DeltaQt is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with DeltaQt. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 #ifndef DELTAPARSERPRIVATE_H 00020 #define DELTAPARSERPRIVATE_H 00021 00022 #include <QString> 00023 #include <QChar> 00024 #include <QFile> 00025 #include <QTextStream> 00026 00027 #include "deltadirectives.h" 00028 00029 class DeltaParseContext; // fwd decl 00030 00031 class DpReadBuffer 00032 { 00033 friend class DeltaParseContext; 00034 public: 00035 DpReadBuffer(); 00036 ~DpReadBuffer(); 00037 DpReadBuffer(QString filename); 00038 DpReadBuffer(QString filename, int maxBuffSize); 00039 00040 inline bool isReady(void) const { return m_file->isOpen(); } 00041 00042 bool useFile(QString filename, int maxBuffSize = -1); 00043 00044 bool get(QChar* ch); 00045 00046 int readUntil(const DeltaParseContext& parseCtxt, 00047 const QString& searchChars, 00048 QString* dest, 00049 QChar* firstChar = NULL); 00050 00051 inline void close(void) { reset(); } 00052 void reset(void); 00053 00054 protected: 00055 void ctorCommonInit(void); 00056 QChar peek(int after) const; 00057 int fillBuffer(void); 00058 00059 void deallocateResources(void); 00060 00061 private: 00062 inline int endOfBufferIdx(void) const { return m_buff->count()-1; } 00063 bool charInSearchChars(QChar ch, const QString& searchChars); 00064 00065 00066 int m_maxBuffSize; 00067 int m_buffOffsetInFile; 00068 int m_startPosInBuff; 00069 int m_commentDepth; 00070 QChar m_prevPageLastChar; 00071 00072 QString* m_buff; 00073 QFile* m_file; 00074 QTextStream* m_stream; 00075 00076 static int m_defaultMinBuffSize; 00077 static int m_defaultMaxBuffSize; 00078 00079 }; 00080 00081 00082 class DeltaParseContext 00083 { 00084 friend class DeltaParser; 00085 00086 public: 00087 DeltaParseContext(); 00088 ~DeltaParseContext(); 00089 00090 inline const DeltaDirectives::Def* directiveCtxt(void) const 00091 { return m_currDirective; } 00092 00093 /* Because the DELTA spec defines different rules for allowed for 00094 characters before and after the comment deliminters depending on 00095 context (i.e. the rules are different when parsing attributes) 00096 these functions return a result based not only on the character at 00097 pos, but also the current 'parse context' 00098 */ 00099 bool isCommentStart(QChar ch, QChar prevCh) const; 00100 bool isCommentEnd(QChar ch, QChar nextCh) const; 00101 00102 // context-based legal pre/post comment delim character strings 00103 QString getLegalCommentPreChars(void) const; 00104 QString getLegalCommentPostChars(void) const; 00105 00106 void clear(void); 00107 void switchDirectiveCtxt(const DeltaDirectives::Def* directive); 00108 void switchFileContext(QString newFilename); 00109 00110 private: 00111 bool isLegalCommentPreChar(QChar ch) const; 00112 bool isLegalCommentPostChar(QChar ch) const; 00113 00114 const DeltaDirectives::Def* m_currDirective; 00115 int m_currCommentDepth; 00116 QString m_currFilename; 00117 int m_currLineNum; 00118 int m_currPosInFile; 00119 00120 }; 00121 00122 #endif // DELTAPARSERPRIVATE_H