RedPanda-CPP/RedPandaIDE/gdbmiresultparser.h

90 lines
2.5 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();
2021-11-21 08:38:03 +08:00
explicit ParseValue(const QByteArray& value);
2021-11-12 22:42:51 +08:00
explicit ParseValue(const ParseObject &object);
explicit ParseValue(const QList<ParseObject>& array);
ParseValue(const ParseValue&) = delete;
2021-11-21 08:38:03 +08:00
const QByteArray &value() const;
const QList<ParseObject> &array() const;
const ParseObject &object() const;
2021-11-21 10:36:50 +08:00
int intValue(int defaultValue=-1) const;
2021-11-12 22:42:51 +08:00
ParseValueType type() const;
2021-11-21 08:38:03 +08:00
ParseValue& operator=(const QByteArray& value);
2021-11-12 22:42:51 +08:00
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-21 08:38:03 +08:00
QByteArray mValue;
2021-11-12 22:42:51 +08:00
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);
2021-11-21 10:36:50 +08:00
bool parseAsyncResult(const QByteArray& record, QByteArray& result, ParseObject& multiValue);
2021-11-12 22:42:51 +08:00
private:
2021-11-21 10:36:50 +08:00
bool parseMultiValues(const char*p, ParseObject& multiValue);
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