RedPanda-CPP/RedPandaIDE/gdbmiresultparser.h

87 lines
2.3 KiB
C
Raw Normal View History

2021-11-12 10:51:00 +08:00
#ifndef GDBMIRESULTPARSER_H
#define GDBMIRESULTPARSER_H
#include <QByteArray>
2021-11-13 11:16:05 +08:00
#include <QHash>
#include <QList>
2021-11-13 11:16:05 +08:00
#include <memory>
2021-11-12 10:51:00 +08:00
enum class GDBMIResultType {
Breakpoint,
BreakpointTable,
FrameStack,
LocalVariables,
Locals,
Frame,
Disassembly,
Evaluation,
RegisterNames,
RegisterValues,
Memory
};
class GDBMIResultParser
{
2021-11-13 11:16:05 +08:00
public:
2021-11-12 22:42:51 +08:00
enum class ParseValueType {
Value,
Object,
Array,
NotAssigned
};
2021-11-13 11:16:05 +08:00
class ParseValue;
class ParseObject {
public:
const ParseValue operator[](const QByteArray& name) const;
ParseValue& operator[](const QByteArray& name);
ParseObject& operator=(const ParseObject& object);
private:
QHash<QByteArray, ParseValue> mProps;
};
2021-11-12 22:42:51 +08:00
class ParseValue {
public:
explicit ParseValue();
explicit ParseValue(const QString& value);
explicit ParseValue(const ParseObject &object);
explicit ParseValue(const QList<ParseObject>& array);
ParseValue(const ParseValue&) = delete;
const QString &value() const;
const QList<ParseObject> &array() const;
const ParseObject &object() const;
2021-11-12 22:42:51 +08:00
ParseValueType type() const;
ParseValue& operator=(const QString& value);
ParseValue& operator=(const ParseObject& object);
ParseValue& operator=(const QList<ParseObject>& array);
ParseValue& operator=(const ParseValue& value);
2021-11-12 10:51:00 +08:00
private:
2021-11-12 22:42:51 +08:00
QString mValue;
QList<ParseObject> mArray;
ParseObject mObject;
ParseValueType mType;
2021-11-12 10:51:00 +08:00
};
2021-11-12 22:42:51 +08:00
using PParseValue = std::shared_ptr<ParseValue>;
2021-11-12 10:51:00 +08:00
public:
GDBMIResultParser();
2021-11-12 22:42:51 +08:00
bool parse(const QByteArray& record, GDBMIResultType& type, ParseValue& value);
private:
2021-11-13 11:16:05 +08:00
bool parseNameAndValue(const char *&p,QByteArray& name, ParseValue& value);
bool parseValue(const char* &p, ParseValue& value);
bool parseStringValue(const char*&p, QByteArray& stringValue);
bool parseObject(const char*&p, ParseObject& obj);
bool parseArray(const char*&p, QList<ParseObject>& array);
void skipSpaces(const char* &p);
2021-11-12 22:42:51 +08:00
bool isNameChar(char ch);
bool isSpaceChar(char ch);
private:
QHash<QByteArray, GDBMIResultType> mResultTypes;
2021-11-12 10:51:00 +08:00
};
#endif // GDBMIRESULTPARSER_H