Itasca C++ Interface
Loading...
Searching...
No Matches
iparse.h
Go to the documentation of this file.
1#pragma once
2
3#include "base/src/baseqt.h"
4
5#include "dim.h"
6#include "utility/interface/itextinput.h"
7
13namespace itasca {
14 class ITextOutput;
15
17
50 class IParse {
51 public:
53 class IMark {
54 public:
56 virtual void destroy()=0;
57 };
58
67
69 virtual ~IParse() { }
70
72 virtual bool interactiveSource() const=0;
73 virtual void tagLastInputForSmartUndo(const QString &label,uint64 maxLevel,
74 const QString &undoCommand)=0;
75
79 virtual int getTokenIndex(IMark *p=nullptr) const=0;
83 virtual int getLineNumber(IMark *p=nullptr) const=0;
87 virtual IVect2 getTokenExtent(IMark *p=nullptr) const=0;
88
92 virtual const ITextInput *getITextInput() const=0;
95
97 virtual const QList<InputLine> &getOriginalInput() const=0;
98
100 virtual IParse * createTemporaryParse(const QString &)=0;
101
104 virtual IMark *createMark(int pos=0) const=0;
105
109 virtual IMark *createMarkCopy(IMark *p=nullptr) const=0;
110
112 virtual void increment(IMark *p=nullptr) const=0;
114 virtual void decrement(IMark *p=nullptr) const=0;
116 virtual void setMark(IMark *pNew,IMark *p=nullptr) const=0;
117
120 virtual IString getToken(IMark *p=nullptr) const=0;
121
126 virtual bool isToken(IMark *p=nullptr) const=0;
127
130 virtual void checkError(RetCode rc,IMark *p=nullptr) const=0;
131 virtual bool checkError(bool b,IMark *p=nullptr) const=0;
132
134 virtual void addHelp(const IString &s) const=0;
135
137 virtual bool isHelp(IMark *p=nullptr) const=0;
138
139
143 virtual RetCode isString(QString *ps=nullptr,IMark *p=nullptr,bool encodeBackslash=true) const=0;
147 virtual RetCode isBool(bool *pb=nullptr,IMark *p=nullptr,bool implicitOn=false) const=0;
151 virtual RetCode isInt(int *pi=nullptr,IMark *p=nullptr,int iMin=limits<int>::min(),
152 int iMax=limits<int>::max()) const=0;
156 virtual RetCode isLong(qint64 *pl=nullptr,IMark *p=nullptr,qint64 lMin=limits<qint64>::min(),
157 qint64 lMax=limits<qint64>::max()) const=0;
161 virtual RetCode isUInt(uint32 *pu=nullptr,IMark *p=nullptr,uint32 uMin=0,
162 uint32 uMax=limits<uint32>::max()) const=0;
166 virtual RetCode isULong(uint64 *pu=nullptr,IMark *p=nullptr,uint64 uMin=0,
167 uint64 uMax=limits<uint64>::max()) const=0;
168 virtual RetCode isName(QString *ps=nullptr,IMark *p=nullptr) const=0;
172 virtual RetCode isDouble(double *pd=nullptr,IMark *p=nullptr,
173 double dMin=limits<double>::lowest(),
174 double dMax=limits<double>::max()) const=0;
186 virtual RetCode isKeyword(const IString &key,uint32 *pPos=nullptr,IMark *p=nullptr) const=0;
187 virtual RetCode isMultiKeyword(const IString &key,std::vector<uint32> *pPos,IMark *p=nullptr) const=0;
188 virtual RetCode isDVect2(DVect2 *pv=nullptr,IMark *p=nullptr) const=0;
192 virtual RetCode isDVect3(DVect3 *pv=nullptr,IMark *p=nullptr) const=0;
196 virtual RetCode isDVect(DVect *pv=nullptr,IMark *p=nullptr) const=0;
200 virtual RetCode isSymTensor(SymTensor *pv=nullptr,IMark *p=nullptr) const=0;
204 //virtual RetCode isDVect(DVect *pv=nullptr,IMark *p=nullptr) const=0;
208 //virtual RetCode isDAVect(DAVect *pv=nullptr,IMark *p=nullptr) const=0;
212 virtual RetCode isVariant(int type,QVariant *pv=nullptr,IMark *p=nullptr,uint32 len=0) const=0;
217 virtual RetCode isVariant(QVariant *pv=nullptr,IMark *p=nullptr) const=0;
218
219
230 virtual RetCode isFilename(QString *ps=nullptr,const IString &def_ext={},bool openForRead=false,IMark *p=nullptr) const=0;
231
235 virtual IString toString(IMark *p=nullptr) const=0;
239 virtual bool toBool(IMark *p=nullptr,bool implicitOn=false) const=0;
243 virtual int toInt(IMark *p=nullptr,int iMin=limits<int>::min(),
244 int iMax=limits<int>::max()) const=0;
248 virtual qint64 toLong(IMark *p=nullptr,qint64 lMin=limits<qint64>::min(),
249 qint64 lMax=limits<qint64>::max()) const=0;
253 virtual uint32 toUInt(IMark *p=nullptr,uint32 uMin=0,
254 uint32 uMax=limits<uint32>::max()) const=0;
258 virtual uint64 toULong(IMark *p=nullptr,uint64 uMin=0,
259 uint64 uMax=limits<uint64>::max()) const=0;
260 virtual IString toName(IMark *p=nullptr) const=0;
264 virtual double toDouble(IMark *p=nullptr,double dMin=-limits<double>::max(),
265 double dMax= limits<double>::max()) const=0;
270 virtual uint32 toKeyword(const IString &key,IMark *p=nullptr) const=0;
274 virtual DVect toDVect(IMark *p = 0) const = 0;
278 virtual DVect2 toDVect2(IMark *p=nullptr) const=0;
282 virtual DVect3 toDVect3(IMark *p=nullptr) const=0;
286 virtual SymTensor toSymTensor(IMark *p=nullptr) const=0;
290 //virtual DVect toDVect(IMark *p=nullptr) const=0;
294 //virtual DAVect toDAVect(IMark *p=nullptr) const=0;
298 virtual QVariant toVariant(int type,IMark *p=nullptr,uint32 len=0) const=0;
303 virtual QVariant toVariant(IMark *p=nullptr) const=0;
306 virtual IString toFilename(const IString &def_ext={},bool openForRead=false,IMark *p=nullptr) const=0;
311 virtual int isStringCharStart(QChar c) const=0;
316 virtual int isStringCharEnd(QChar c) const=0;
317
319 virtual QStringList getSkipList() const=0;
322 virtual bool checkSkipPre(QStringList *skipList,QChar c,IMark *p=nullptr) const=0;
325 virtual bool checkSkipPost(QStringList *skipList,QChar c,IMark *p=nullptr) const=0;
327 virtual void addSkipPre(QStringList *skipList,QChar c,IMark *p=nullptr) const=0;
329 virtual void addSkipPost(QStringList *skipList,QChar c,IMark *p=nullptr) const=0;
333 virtual bool findKeyword(const QString &keyword,IMark *pFound,IMark *pStart=nullptr) const=0;
337 virtual void stripTokens(IMark *mBegin,IMark *mEnd,IMark *p=nullptr)=0;
339 virtual bool activateHelp(bool b)=0;
341 virtual bool hasHelpToken() const=0;
342 virtual void destroy()=0;
343 };
344
345#ifdef THREED
347 inline IParse::RetCode isDVect(const IParse &par,DVect3 *v=nullptr,IParse::IMark *m=nullptr) { return par.isDVect3(v,m); }
349 inline IParse::RetCode isDAvect(const IParse &par,DAVect3 *v=nullptr,IParse::IMark *m=nullptr) { return par.isDVect3(v,m); }
351 inline DVect3 toDVect(const IParse &par,IParse::IMark *m=nullptr) { return par.toDVect3(m); }
353 inline DAVect3 toDAVect(const IParse &par,IParse::IMark *m=nullptr) { return par.toDVect3(m); }
354#endif
355#ifdef TWOD
357 inline IParse::RetCode isDVect(const IParse &par,DVect2 *v=nullptr,IParse::IMark *m=nullptr) { return par.isDVect2(v,m); }
359 inline IParse::RetCode isDAvect(const IParse &par,DAVect2 *v=nullptr,IParse::IMark *m=nullptr) { double d; IParse::RetCode rc = par.isDouble(&d,m); if (rc==IParse::rcOK && v) *v = DAVect2(d); return rc; }
361 inline DVect2 toDVect(const IParse &par,IParse::IMark *m=nullptr) { return par.toDVect2(m); }
363 inline DAVect2 toDAVect(const IParse &par,IParse::IMark *m=nullptr) { return DAVect2(par.toDouble(m)); }
364#endif
365} // namespace itascaxd
366namespace module {
367 using itasca::IParse;
368}
369// EoF
All default base headers if Qt is being used.
Definition istring.h:14
Definition idef.h:50
A symmetric 2nd order tensor.
Definition symtensor.h:22
Opaque position indicator class. Do not attempt to use directly for anything.
Definition iparse.h:53
virtual void destroy()=0
Destroys this mark.
Interface to the main command processing class.
Definition iparse.h:50
virtual QStringList getSkipList() const =0
Returns the original skip list parsed from the input line.
virtual const QList< InputLine > & getOriginalInput() const =0
Returns the original strings used to generate the set of command tokens.
virtual bool hasHelpToken() const =0
Return a boolean indicating whether or not a help token is in the token list.
virtual IVect2 getTokenExtent(IMark *p=nullptr) const =0
virtual uint32 toUInt(IMark *p=nullptr, uint32 uMin=0, uint32 uMax=limits< uint32 >::max()) const =0
virtual RetCode isInt(int *pi=nullptr, IMark *p=nullptr, int iMin=limits< int >::min(), int iMax=limits< int >::max()) const =0
virtual void addSkipPost(QStringList *skipList, QChar c, IMark *p=nullptr) const =0
Adds a character to the start of the skip string AFTER the current token.
virtual QVariant toVariant(int type, IMark *p=nullptr, uint32 len=0) const =0
virtual IParse * createTemporaryParse(const QString &)=0
A method to return a temporary IParse Object that must be deleted.
virtual bool toBool(IMark *p=nullptr, bool implicitOn=false) const =0
virtual void addHelp(const IString &s) const =0
Adds a QString representing a token type to the help list. Multiple matching Strings are filtered.
virtual void addSkipPre(QStringList *skipList, QChar c, IMark *p=nullptr) const =0
Adds a character to the end of the skip string BEFORE the current token.
virtual ITextOutput * getITextOutput()=0
Returns an ITextIO interface associated with this parser.
virtual ITextInput * getITextInput()=0
Returns an ITextInput interface associated with this parser.
virtual RetCode isVariant(QVariant *pv=nullptr, IMark *p=nullptr) const =0
virtual bool interactiveSource() const =0
Returns TRUE if the input source for the command being processed was interactive.
virtual IString toFilename(const IString &def_ext={}, bool openForRead=false, IMark *p=nullptr) const =0
virtual int isStringCharStart(QChar c) const =0
virtual SymTensor toSymTensor(IMark *p=nullptr) const =0
virtual RetCode isBool(bool *pb=nullptr, IMark *p=nullptr, bool implicitOn=false) const =0
virtual IString getToken(IMark *p=nullptr) const =0
virtual RetCode isFilename(QString *ps=nullptr, const IString &def_ext={}, bool openForRead=false, IMark *p=nullptr) const =0
virtual void increment(IMark *p=nullptr) const =0
Increments the provided or internal mark.
virtual void setMark(IMark *pNew, IMark *p=nullptr) const =0
Sets the internal position indicator to p.
virtual int getLineNumber(IMark *p=nullptr) const =0
virtual DVect toDVect(IMark *p=0) const =0
virtual int isStringCharEnd(QChar c) const =0
virtual const ITextInput * getITextInput() const =0
Returns an ITextInput interface associated with this parser.
virtual bool checkSkipPost(QStringList *skipList, QChar c, IMark *p=nullptr) const =0
virtual RetCode isLong(qint64 *pl=nullptr, IMark *p=nullptr, qint64 lMin=limits< qint64 >::min(), qint64 lMax=limits< qint64 >::max()) const =0
virtual RetCode isDouble(double *pd=nullptr, IMark *p=nullptr, double dMin=limits< double >::lowest(), double dMax=limits< double >::max()) const =0
virtual qint64 toLong(IMark *p=nullptr, qint64 lMin=limits< qint64 >::min(), qint64 lMax=limits< qint64 >::max()) const =0
virtual uint64 toULong(IMark *p=nullptr, uint64 uMin=0, uint64 uMax=limits< uint64 >::max()) const =0
virtual bool findKeyword(const QString &keyword, IMark *pFound, IMark *pStart=nullptr) const =0
virtual RetCode isUInt(uint32 *pu=nullptr, IMark *p=nullptr, uint32 uMin=0, uint32 uMax=limits< uint32 >::max()) const =0
virtual RetCode isDVect(DVect *pv=nullptr, IMark *p=nullptr) const =0
RetCode
Possible return codes for isXXX() functions.
Definition iparse.h:60
@ rcOK
token was interpreted successfully.
Definition iparse.h:61
@ rcRange
the token was interpreted correctly but it's value fell outside of a restricted range given.
Definition iparse.h:64
@ rcExtra
an extra unused token was found at the end of the command line.
Definition iparse.h:65
@ rcMiss
no token was present at that position.
Definition iparse.h:62
@ rcBad
the token could not be interepreted as asked.
Definition iparse.h:63
virtual DVect2 toDVect2(IMark *p=nullptr) const =0
virtual RetCode isSymTensor(SymTensor *pv=nullptr, IMark *p=nullptr) const =0
virtual void stripTokens(IMark *mBegin, IMark *mEnd, IMark *p=nullptr)=0
virtual RetCode isDVect3(DVect3 *pv=nullptr, IMark *p=nullptr) const =0
virtual IMark * createMark(int pos=0) const =0
virtual bool checkSkipPre(QStringList *skipList, QChar c, IMark *p=nullptr) const =0
virtual RetCode isString(QString *ps=nullptr, IMark *p=nullptr, bool encodeBackslash=true) const =0
virtual void checkError(RetCode rc, IMark *p=nullptr) const =0
virtual int getTokenIndex(IMark *p=nullptr) const =0
virtual IString toString(IMark *p=nullptr) const =0
virtual RetCode isKeyword(const IString &key, uint32 *pPos=nullptr, IMark *p=nullptr) const =0
virtual RetCode isVariant(int type, QVariant *pv=nullptr, IMark *p=nullptr, uint32 len=0) const =0
virtual DVect3 toDVect3(IMark *p=nullptr) const =0
virtual IMark * createMarkCopy(IMark *p=nullptr) const =0
virtual int toInt(IMark *p=nullptr, int iMin=limits< int >::min(), int iMax=limits< int >::max()) const =0
virtual uint32 toKeyword(const IString &key, IMark *p=nullptr) const =0
virtual RetCode isULong(uint64 *pu=nullptr, IMark *p=nullptr, uint64 uMin=0, uint64 uMax=limits< uint64 >::max()) const =0
virtual bool isHelp(IMark *p=nullptr) const =0
Returns TRUE if the token matches one of the help_tokens.
virtual QVariant toVariant(IMark *p=nullptr) const =0
virtual ~IParse()
Virtual destructor.
Definition iparse.h:69
virtual bool activateHelp(bool b)=0
Turne help on/off.
virtual double toDouble(IMark *p=nullptr, double dMin=-limits< double >::max(), double dMax=limits< double >::max()) const =0
virtual bool isToken(IMark *p=nullptr) const =0
virtual void decrement(IMark *p=nullptr) const =0
Decrements the provided or internal mark.
Definition itextinput.h:39
Provides a interface for simple writing of text.
Definition itextoutput.h:13
debug checked shorthand for std::numeric_limits<T>::
Definition limit.h:25
DIM - Provides code portability between 2D and 3D codes.
DVect3 DVect
Vector of doubles, either 2D or 3D.
Definition dim.h:154
namespace Itasca
Definition basememory.cpp:10
IParse::RetCode isDAvect(const IParse &par, DAVect3 *v=nullptr, IParse::IMark *m=nullptr)
Thin wrapper for IParse::isDVect3, designed to make it easier to write code that is the same in 2D an...
Definition iparse.h:349
DAVect3 toDAVect(const IParse &par, IParse::IMark *m=nullptr)
Thin wrapper for IParse::toDVect3, designed to make it easier to write code that is the same in 2D an...
Definition iparse.h:353
DVect3 toDVect(const IParse &par, IParse::IMark *m=nullptr)
Thin wrapper for IParse::toDVect3, designed to make it easier to write code that is the same in 2D an...
Definition iparse.h:351
IParse::RetCode isDVect(const IParse &par, DVect3 *v=nullptr, IParse::IMark *m=nullptr)
Thin wrapper for IParse::isDVect3, designed to make it easier to write code that is the same in 2D an...
Definition iparse.h:347