Project

General

Profile

Statistics
| Branch: | Revision:

root / src / nedxml / nedfilebuffer.h @ 79bb12dc

History | View | Annotate | Download (3.34 KB)

1 01873262 Georg Kunz
//==========================================================================
2
//  NEDFILEBUFFER.H - part of
3
//
4
//                     OMNeT++/OMNEST
5
//            Discrete System Simulation in C++
6
//
7
//==========================================================================
8
9
/*--------------------------------------------------------------*
10
  Copyright (C) 2002-2008 Andras Varga
11
  Copyright (C) 2006-2008 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 __NEDFILEBUFFER_H
18
#define __NEDFILEBUFFER_H
19
20
#include "nedparser.h"   // for YYLTYPE
21
22
NAMESPACE_BEGIN
23
24
/**
25
 * Used internally by NEDParser. Stores the full text of a NED file,
26
 * and makes it possible to retrieve parts of it by (line1,col1,line2,col2)
27
 * coordinates passed in an YYLTYPE structure. Also finds and retrieves
28
 * comments near a position passed in an YYLTYPE.
29
 *
30
 * @ingroup NEDParser
31
 */
32
class NEDXML_API NEDFileBuffer
33
{
34
  private:
35
    enum {COMMENT_LINE, BLANK_LINE, CODE_LINE};
36
37
    char *wholeFile;
38
39
    int numLines;
40
    char **lineBeg;
41
42
    char *end;
43
    char savedChar;
44
45
    char *commentBuf;
46
    int commentBufLen;
47
48
  private:
49
    int getLineType(int lineNumber);
50
    int getLineType(const char *s);
51
    bool lineContainsCode(const char *s);
52
    int getLineIndent(int lineNumber);
53
    int getLineIndent(const char *s);
54
    char *getPosition(int line, int column);
55
56
    bool indexLines();
57
    int topLineOfBannerComment(int li);
58
    char *stripComment(const char *s);
59
60
    YYLTYPE getFileCommentPos();
61
    YYLTYPE getBannerCommentPos(YYLTYPE pos);
62
    YYLTYPE getTrailingCommentPos(YYLTYPE pos);
63
64
  public:
65
    /**
66
     * Constructor.
67
     */
68
    NEDFileBuffer();
69
70
    /**
71
     * Destructor.
72
     */
73
    ~NEDFileBuffer();
74
75
    /**
76
     * Reads NED file given with its filename.
77
     *
78
     * @see setData()
79
     */
80
    bool readFile(const char *filename);
81
82
    /**
83
     * Uses literal NED text.
84
     *
85
     * @see readFile()
86
     */
87
    bool setData(const char *data);
88
89
    /**
90
     * Returns pointer to a text region defined by (beg-line, beg-col) and
91
     * (end-line, end-col). The text is NOT copied, only a null character
92
     * is written temporarily into the stored string at (end-line, end-col) --
93
     * this also means you should NOT keep more than one pointer returned by
94
     * get()!
95
     */
96
    const char *get(YYLTYPE pos);
97
98
    /**
99
     * Returns comment at top of file. Uses get()!
100
     */
101
    const char *getFileComment();
102
103
    /**
104
     * Returns banner comment above text range passed in pos. Uses get()!
105
     */
106
    const char *getBannerComment(YYLTYPE pos);
107
108
    /**
109
     * Returns trailing comment below text range passed in pos. Uses get()!
110
     */
111
    const char *getTrailingComment(YYLTYPE pos);
112
113
    /**
114
     * Returns the next comment inside the given region, and moves
115
     * the region's start past the comment. Uses get()!
116
     */
117
    const char *getNextInnerComment(YYLTYPE& pos);
118
119
    /**
120
     * Returns 1:0...end.
121
     */
122
    YYLTYPE getFullTextPos();
123
124
    /**
125
     * Returns pointer to the full source code. Uses get()!
126
     */
127
    const char *getFullText();
128
129
    /**
130
     * Shrinks the given region to exclude any leading/trailing whitespace
131
     * and comments.
132
     */
133
    void trimSpaceAndComments(YYLTYPE& pos);
134
};
135
136
NAMESPACE_END
137
138
139
#endif