forked from billvaglienti/ProtoGen
-
Notifications
You must be signed in to change notification settings - Fork 5
/
xmllinelocator.h
87 lines (60 loc) · 2.2 KB
/
xmllinelocator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef XMLLINELOCATOR_H
#define XMLLINELOCATOR_H
#include <QString>
#include <QList>
class XMLContent
{
friend class XMLLineLocator;
protected:
//! decleare XMLContent with starting line number and outline level
XMLContent(void) :
mylinenumber(0),
outline(0)
{}
//! declare XMLContent with line number and outline level
XMLContent(int line, int level) :
mylinenumber(line),
outline(level)
{}
//! Override name for the contens
void overrideName(QString newname) {name = newname;}
//! Set the contents of this XMLContent, including subs
void setXMLContents(const QString& text, int& startindex, int& linenumber);
//! Get the line number (if any) that matches the hierarchical name
int getMatchingLineNumber(const QStringList& names, int level) const;
//! Determine the "name" attribute
void parseNameFromContents(void);
//! Determine an attribute value
static QString parseAttribute(const QString& label, const QString& text);
//! Count the number of linefeeds between a start and end index
static int countLines(const QString& text, int startindex, int endindex);
//! The list of sub-contents
QList<XMLContent> subs;
//! Content of this XML
QString contents;
//! "name" attribute of this XML
QString name;
//! Line number at the start of this XML
int mylinenumber;
//! Outline level of this XML (0 is outermost)
int outline;
};
class XMLLineLocator
{
public:
XMLLineLocator(){}
//! Input the contents of the XML file, this will trigger a parse operation
void setXMLContents(std::string text, std::string path, std::string file, std::string topname = std::string());
//! Find the line number given a hierarchical name
int getLineNumber(std::string hierarchicalName) const;
//! Output a warning
bool emitWarning(std::string hierarchicalName, std::string warning) const;
protected:
//! The path to the file this locator represents
QString inputpath;
//! The name of the file this locator represents
QString inputfile;
//! The contents of the file used for line number lookups
XMLContent contents;
};
#endif // XMLLINELOCATOR_H