farsamiscutilities.h
Go to the documentation of this file.
1 /********************************************************************************
2  * FARSA Utilities Library *
3  * Copyright (C) 2007-2012 *
4  * Gianluca Massera <emmegian@yahoo.it> *
5  * Stefano Nolfi <stefano.nolfi@istc.cnr.it> *
6  * Tomassino Ferrauto <tomassino.ferrauto@istc.cnr.it> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
21  ********************************************************************************/
22 
23 #ifndef FARSAMISCUTILITIES_H
24 #define FARSAMISCUTILITIES_H
25 
26 #include "utilitiesconfig.h"
27 #include <QString>
28 #include <QList>
29 
39 #if defined(__GNUC__) || defined(__clang__)
40  #define FARSA_DEPRECATED __attribute__((deprecated))
41 #elif defined(_MSC_VER)
42  #define FARSA_DEPRECATED __declspec(deprecated)
43 #endif
44 
45 namespace farsa {
52  struct FARSA_UTIL_TEMPLATE CommentPosition
53  {
57  enum CommentType {
59  CppComment
60  };
61 
66  originalStart(0),
67  originalEnd(0),
68  parsedPosition(0),
69  type(CComment)
70  {
71  }
72 
84  CommentPosition(unsigned int s, unsigned int e, unsigned int p, CommentType t) :
85  originalStart(s),
86  originalEnd(e),
87  parsedPosition(p),
88  type(t)
89  {
90  }
91 
96  unsigned int originalStart;
97 
102  unsigned int originalEnd;
103 
108  unsigned int parsedPosition;
109 
114  };
115 
119  typedef QList<CommentPosition> CommentsPositions;
120 
129  struct FARSA_UTIL_TEMPLATE StringPosition
130  {
134  enum Type {
136  Character
137  };
138 
143  originalStart(0),
144  originalEnd(0),
145  parsedStart(0),
146  parsedEnd(0),
147  type(String)
148  {
149  }
150 
164  StringPosition(unsigned int os, unsigned int oe, unsigned int ps, unsigned int pe, Type t) :
165  originalStart(os),
166  originalEnd(oe),
167  parsedStart(ps),
168  parsedEnd(pe),
169  type(t)
170  {
171  }
172 
177  unsigned int originalStart;
178 
183  unsigned int originalEnd;
184 
189  unsigned int parsedStart;
190 
195  unsigned int parsedEnd;
196 
201  };
202 
206  typedef QList<StringPosition> StringsPositions;
207 
225  QString FARSA_UTIL_API removeComments(const QString& program, CommentsPositions* commentsPos = NULL, StringsPositions* stringsPos = NULL);
226 }
227 
228 #endif
This file contains the common type defitions used on the whole framework.
Type
String or character.
QList< StringPosition > StringsPositions
A list of positions of strings.
QList< CommentPosition > CommentsPositions
A list of positions of comments.
unsigned int originalEnd
The ending position of the comment in the original program (i.e. the position of the closing " or ') ...
A macro to deprecate functions.
unsigned int parsedStart
The starting position of the comment in the parsed program (i.e. the position of the opening " or ') ...
CommentPosition()
Constructor.
StringPosition()
Constructor.
QString removeComments(const QString &program, CommentsPositions *commentsPos, StringsPositions *stringsPos)
A simple function to remove all C and C++ comments from a program.
unsigned int originalStart
The starting position of the comment in the original program (i.e. the position of the opening " or '...
unsigned int originalStart
The starting position of the comment in the original program (i.e. the position of the first characte...
unsigned int originalEnd
The ending position of the comment in the original program (i.e. the position of the last character) ...
CommentType type
The type of comment.
StringPosition(unsigned int os, unsigned int oe, unsigned int ps, unsigned int pe, Type t)
Constructor.
A structure keeping the position of C/C++ strings or characters in a program.
unsigned int parsedPosition
The position of the space with which the comment was substituted in the parsed program.
CommentType
The possible types of comments (C or C++ style)
Type type
Whether this is a string or a character.
A structure keeping the position of C/C++ comments in a string.
CommentPosition(unsigned int s, unsigned int e, unsigned int p, CommentType t)
Constructor.
unsigned int parsedEnd
The ending position of the comment in the parsed program (i.e. the position of the closing " or ') ...