GNU Octave  4.2.1
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-2016 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@cybercatalyst.com>
26 
27 #if ! defined (octave_parser_h)
28 #define octave_parser_h 1
29 
30 #include <QStringList>
31 #include <QIODevice>
32 #include <QFileInfoList>
33 #include <QHash>
34 
35 /**
36  * @class parser
37  * This class gets nodes and searchs inside of 'info files'.
38  * <p>Each info file has nodes. Every node has the documentation.
39  * Info files contains a map with position of each node.</p>
40  * <p>What is position?
41  * There is a simple answer:
42  * If you make a queue with info files, position will be the number of bytes
43  * from begining to node position.</p>
44  * <p>
45  * But is not so easy. There is headers, and qtinfo must not take these
46  * headers into account.
47  * </p>
48  * <p>
49  * This class also translates info files to html.
50  * </p>
51  */
52 class parser
53  : public QObject
54 {
55  Q_OBJECT
56 
57 public:
58  parser (QObject *parent = 0);
59  bool set_info_path (const QString& _info_path);
60  QString get_info_path ();
61  QString search_node (const QString& node);
62  QString global_search (const QString& text, int maxFounds);
63 
64  QString find_ref (const QString &name);
65 
66  /** Checks if this node is reference. If node is reference, it will be
67  * returned its position in text, else it will be returned -1.
68  */
69  int is_ref (const QString& node);
70 
71  /** Translates text of node to Html. If anchorPos is not -1, then anchor is
72  * inserted in that position.
73  */
74  QString node_text_to_html (const QString& text, int anchorPos = -1,
75  const QString& anchor = QString ());
76 
77 private:
79  {
80  QString _node_name;
81  int pos;
82  };
83 
85  {
86  int pos;
87  };
88 
90  {
91  QFileInfo file_info;
92  int real_size;
93  };
94 
95  QString search_node (const QString& node, QIODevice * io);
96  QString get_next_node (QIODevice * io);
97  QString get_node_name (const QString& text);
98  QString get_node_up (const QString& text);
99  QString get_node_next (const QString& text);
100  QString get_node_prev (const QString& text);
101 
102  /** Parses info files and gets map of node positions.*/
103  void parse_info_map();
104 
105  /** Open info files and uncompress them. */
106  QIODevice *open_file(QFileInfo & fileInfo);
107 
108  /** Calculates real position of nodes.
109  * @param pos position from info file.
110  * @param fileInfo returns file what contains that position.
111  * @param realPos returns real position inside of fileInfo.
112  */
113  void real_position (int pos, QFileInfo & file_info, int & real_pos);
114 
115  /** Seeks to position pos. */
116  void seek (QIODevice *io, int pos);
117 
118  QString _info_path;
119  QFileInfoList _info_files;
120  QHash<QString, node_map_item> _node_map;
121  QHash<QString, node_position> _ref_map;
123  QHash<QString, QString> _compressors_map;
124 };
125 
126 #endif
QList< info_file_item > _info_file_real_size_list
Definition: parser.h:122
QString get_node_name(const QString &text)
Definition: parser.cc:281
QString _node_name
Definition: parser.h:80
void seek(QIODevice *io, int pos)
Seeks to position pos.
Definition: parser.cc:550
QString global_search(const QString &text, int maxFounds)
Definition: parser.cc:577
QString get_next_node(QIODevice *io)
Definition: parser.cc:209
QFileInfo file_info
Definition: parser.h:91
QIODevice * open_file(QFileInfo &fileInfo)
Open info files and uncompress them.
Definition: parser.cc:95
QString get_node_next(const QString &text)
Definition: parser.cc:293
QHash< QString, node_position > _ref_map
Definition: parser.h:121
This class gets nodes and searchs inside of 'info files'.
Definition: parser.h:52
QHash< QString, QString > _compressors_map
Definition: parser.h:123
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable name
Definition: input.cc:871
QString get_info_path()
Definition: parser.cc:89
QFileInfoList _info_files
Definition: parser.h:119
void parse_info_map()
Parses info files and gets map of node positions.
Definition: parser.cc:442
void real_position(int pos, QFileInfo &file_info, int &real_pos)
Calculates real position of nodes.
Definition: parser.cc:525
QString _info_path
Definition: parser.h:118
parser(QObject *parent=0)
Definition: parser.cc:40
QHash< QString, node_map_item > _node_map
Definition: parser.h:120
QString node_text_to_html(const QString &text, int anchorPos=-1, const QString &anchor=QString())
Translates text of node to Html.
Definition: parser.cc:390
int is_ref(const QString &node)
Checks if this node is reference.
Definition: parser.cc:136
bool set_info_path(const QString &_info_path)
Definition: parser.cc:51
QString find_ref(const QString &name)
Definition: parser.cc:666
QString get_node_prev(const QString &text)
Definition: parser.cc:299
QString search_node(const QString &node)
Definition: parser.cc:152
QString get_node_up(const QString &text)
Definition: parser.cc:287