sourcedocument.h Source File

NEDXML API: sourcedocument.h Source File
NEDXML API
sourcedocument.h
1//==========================================================================
2// SOURCEDOCUMENT.H - part of
3//
4// OMNeT++/OMNEST
5// Discrete System Simulation in C++
6//
7//==========================================================================
8
9/*--------------------------------------------------------------*
10 Copyright (C) 2002-2017 Andras Varga
11 Copyright (C) 2006-2017 OpenSim Ltd.
12
13 This file is distributed WITHOUT ANY WARRANTY. See the file
14 `license' for details on this and other legal matters.
15*--------------------------------------------------------------*/
16
17#ifndef __OMNETPP_NEDXML_SOURCEDOCUMENT_H
18#define __OMNETPP_NEDXML_SOURCEDOCUMENT_H
19
20#include "nedxmldefs.h"
21
22namespace omnetpp {
23namespace nedxml {
24
25struct YYLoc;
26
37class NEDXML_API SourceDocument
38{
39 private:
40 enum {COMMENT_LINE, BLANK_LINE, CODE_LINE};
41
42 char *wholeFile = nullptr;
43
44 int numLines = 0;
45 char **lineBeg = nullptr;
46
47 char *end = nullptr;
48 char savedChar = 0;
49
50 int commentBufLen = 1024; // has to be before commentBuf to get initialized before it
51 char *commentBuf;
52
53 private:
54 int getLineType(int lineNumber);
55 int getLineType(const char *s);
56 bool lineContainsCode(const char *s);
57 int getLineIndent(int lineNumber);
58 int getLineIndent(const char *s);
59 char *getPosition(int line, int column);
60
61 bool indexLines();
62 int topLineOfBannerComment(int li);
63 char *stripComment(const char *s);
64
65 YYLoc getFileCommentPos();
66 YYLoc getBannerCommentPos(YYLoc pos);
67 YYLoc getTrailingCommentPos(YYLoc pos);
68
69 public:
74
79
85 bool readFile(const char *filename);
86
92 bool setData(const char *data);
93
101 const char *get(YYLoc pos);
102
106 const char *getFileComment();
107
111 const char *getBannerComment(YYLoc pos);
112
116 const char *getTrailingComment(YYLoc pos);
117
122 const char *getNextInnerComment(YYLoc& pos);
123
128
132 const char *getFullText();
133
138 void trimSpaceAndComments(YYLoc& pos);
139};
140
141} // namespace nedxml
142} // namespace omnetpp
143
144
145#endif
146
bool setData(const char *data)
const char * get(YYLoc pos)
const char * getNextInnerComment(YYLoc &pos)
const char * getTrailingComment(YYLoc pos)
bool readFile(const char *filename)
void trimSpaceAndComments(YYLoc &pos)
const char * getBannerComment(YYLoc pos)