GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
parser.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2009 P.L. Lucas
4 Copyright (C) 2012-2013 Jacob Dawid
5 
6 This file is part of Octave.
7 
8 Octave is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 // Author: P. L. Lucas
25 // Author: Jacob Dawid <jacob.dawid@gmail.com>
26 
27 #include <QStringList>
28 #include <QIODevice>
29 #include <QFileInfoList>
30 #include <QHash>
31 
32 /**
33  * \class parser
34  * This class gets nodes and searchs inside of 'info files'.
35  * <p>Each info file has nodes. Every node has the documentation.
36  * Info files contains a map with position of each node.</p>
37  * <p>What is position?
38  * There is a simple answer:
39  * If you make a queue with info files, position will be the number of bytes
40  * from begining to node position.</p>
41  * <p>
42  * But is not so easy. There is headers, and qtinfo must not take these
43  * headers into account.
44  * </p>
45  * <p>
46  * This class also translates info files to html.
47  * </p>
48  */
49 class parser
50  : public QObject
51 {
52  Q_OBJECT
53 
54 public:
55  parser (QObject *parent = 0);
56  void set_info_path (const QString& _info_path);
57  QString get_info_path ();
58  QString search_node (const QString& node);
59  QString global_search (const QString& text, int maxFounds);
60 
61  QString find_ref (const QString &name);
62 
63  /** Checks if this node is reference. If node is reference, it will be
64  * returned its position in text, else it will be returned -1.
65  */
66  int is_ref (const QString& node);
67 
68  /** Translates text of node to Html. If anchorPos is not -1, then anchor is
69  * inserted in that position.
70  */
71  QString node_text_to_html (const QString& text, int anchorPos = -1,
72  const QString& anchor = QString ());
73 
74 private:
76  {
77  QString _node_name;
78  int pos;
79  };
80 
82  {
83  int pos;
84  };
85 
87  {
88  QFileInfo file_info;
89  int real_size;
90  };
91 
92  QString search_node (const QString& node, QIODevice * io);
93  QString get_next_node (QIODevice * io);
94  QString get_node_name (const QString& text);
95  QString get_node_up (const QString& text);
96  QString get_node_next (const QString& text);
97  QString get_node_prev (const QString& text);
98 
99  /** Parses info files and gets map of node positions.*/
100  void parse_info_map();
101 
102  /** Open info files and uncompress them. */
103  QIODevice *open_file(QFileInfo & fileInfo);
104 
105  /** Calculates real position of nodes.
106  * \param pos position from info file.
107  * \param fileInfo returns file what contains that position.
108  * \param realPos returns real position inside of fileInfo.
109  */
110  void real_position (int pos, QFileInfo & file_info, int & real_pos);
111 
112  /** Seeks to position pos. */
113  void seek (QIODevice *io, int pos);
114 
115 
116  QString _info_path;
117  QFileInfoList _info_files;
118  QHash<QString, node_map_item> _node_map;
119  QHash<QString, node_position> _ref_map;
121  QHash<QString, QString> _compressors_map;
122 };