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
txt-eng.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2009-2017 Michael Goffioul
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_txt_eng_h)
24 #define octave_txt_eng_h 1
25 
26 #include "octave-config.h"
27 
28 #include <memory>
29 #include <string>
30 
31 #include "base-list.h"
32 #include "caseless-str.h"
33 #include "dMatrix.h"
34 
35 class text_element;
38 class text_element_list;
45 class text_element_color;
46 
47 class text_processor;
48 
49 class
52 {
53 public:
54  text_element (void) { }
55 
56  virtual ~text_element (void) { }
57 
58  virtual void accept (text_processor& p) = 0;
59 
60 private:
61  text_element (const text_element&);
62 };
63 
64 class
67 {
68 public:
70  : text_element (), str (s) { }
71 
73 
74  std::string string_value (void) const { return str; }
75 
76  void accept (text_processor& p);
77 
78 private:
80 
81 private:
83 };
84 
85 class
88 {
89 public:
90  enum { invalid_code = 0xFFFFFFFFU };
91 
92 public:
94  : text_element (), symbol (sym) { }
95 
97 
98  int get_symbol (void) const { return symbol; }
99 
100  uint32_t get_symbol_code (void) const;
101 
102  void accept (text_processor& p);
103 
104 private:
105  int symbol;
106 };
107 
108 class
112 {
113 public:
115  : text_element (), octave::base_list<text_element*> () { }
116 
118  : text_element (), octave::base_list<text_element*> ()
119  { push_back (e); }
120 
122  {
123  while (! empty ())
124  {
125  iterator it = begin ();
126  delete (*it);
127  erase (it);
128  }
129  }
130 
131  void accept (text_processor& p);
132 };
133 
134 class
137 {
138 public:
140  : text_element (), elem (e) { }
141 
143  : text_element ()
144  { elem = new text_element_string (std::string (1, c)); }
145 
147  { delete elem; }
148 
149  void accept (text_processor& p);
150 
151  text_element* get_element (void) { return elem; }
152 
153 private:
155 
156 private:
157  text_element_subscript (void);
158 };
159 
160 class
163 {
164 public:
166  : text_element (), elem (e) { }
167 
169  : text_element ()
170  { elem = new text_element_string (std::string (1, c)); }
171 
173  { delete elem; }
174 
175  void accept (text_processor& p);
176 
177  text_element* get_element (void) { return elem; }
178 
179 private:
181 
182 private:
184 };
185 
186 class
189 {
190 public:
192  : text_element_list (e) { }
193 
195  : text_element_list(e1)
196  { push_back (e2); }
197 
198  void accept (text_processor& p);
199 };
200 
201 class
204 {
205 public:
207  {
211  oblique
212  };
213 
215  : text_element (), style (st) { }
216 
218 
219  fontstyle get_fontstyle (void) const { return style; }
220 
221  void accept (text_processor& p);
222 
223 private:
225 
226 private:
227  text_element_fontstyle (void);
228 };
229 
230 class
233 {
234 public:
236  : text_element (), name (fname) { }
237 
239 
240  const std::string& get_fontname (void) const { return name; }
241 
242  void accept (text_processor& p);
243 
244 private:
246 
247 private:
248  text_element_fontname (void);
249 };
250 
251 class
254 {
255 public:
256  text_element_fontsize (double fsize)
257  : text_element (), size (fsize) { }
258 
260 
261  double get_fontsize (void) const { return size; }
262 
263  void accept (text_processor& p);
264 
265 private:
266  double size;
267 
268 private:
269  text_element_fontsize (void);
270 };
271 
272 class
275 {
276 public:
277  text_element_color (double r, double g, double b)
278  : text_element (), rgb (1, 3, 0.0)
279  {
280  rgb(0) = r;
281  rgb(1) = g;
282  rgb(2) = b;
283  }
284 
286  : text_element (), rgb (1, 3, 0.0)
287  {
288 #define ASSIGN_COLOR(r,g,b) { rgb(0) = r; rgb(1) = g; rgb(2) = b; }
289  if (cname == "red") ASSIGN_COLOR(1, 0, 0)
290  else if (cname == "green") ASSIGN_COLOR(0, 1, 0)
291  else if (cname == "yellow") ASSIGN_COLOR(1, 1, 0)
292  else if (cname == "magenta") ASSIGN_COLOR(1, 0, 1)
293  else if (cname == "blue") ASSIGN_COLOR(0, 0, 1)
294  else if (cname == "black") ASSIGN_COLOR(0, 0, 0)
295  else if (cname == "white") ASSIGN_COLOR(1, 1, 1)
296  else if (cname == "gray") ASSIGN_COLOR(.5, .5, .5)
297  else if (cname == "darkGreen") ASSIGN_COLOR(0, .5, 0)
298  else if (cname == "orange") ASSIGN_COLOR(1, .65, 0)
299  else if (cname == "lightBlue") ASSIGN_COLOR(0.68, .85, .9)
300 #undef ASSIGN_COLOR
301  }
302 
304 
305  Matrix get_color (void) { return rgb; }
306 
307  void accept (text_processor& p);
308 
309 private:
311 };
312 
313 class
316 {
317 public:
318  virtual void visit (text_element_string& e) = 0;
319 
320  virtual void visit (text_element_symbol&) { }
321 
322  virtual void visit (text_element_list& e)
323  {
324  for (text_element_list::iterator it = e.begin ();
325  it != e.end (); ++it)
326  {
327  (*it)->accept (*this);
328  }
329  }
330 
331  virtual void visit (text_element_subscript& e)
332  { e.get_element ()->accept (*this); }
333 
334  virtual void visit (text_element_superscript& e)
335  { e.get_element ()->accept (*this); }
336 
337  virtual void visit (text_element_combined&) { }
338 
339  virtual void visit (text_element_fontstyle&) { }
340 
341  virtual void visit (text_element_fontname&) { }
342 
343  virtual void visit (text_element_fontsize&) { }
344 
345  virtual void visit (text_element_color&) { }
346 
347  virtual void reset (void) { }
348 
349 protected:
350  text_processor (void) { }
351 
352  virtual ~text_processor (void) { }
353 };
354 
355 #define TEXT_ELEMENT_ACCEPT(cls) \
356  inline void \
357  cls::accept (text_processor& p) \
358  { \
359  p.visit (*this); \
360  }
361 
372 
373 class
376 {
377 public:
378  text_parser (void) { }
379 
380  virtual ~text_parser (void) { }
381 
382  virtual text_element* parse (const std::string& s) = 0;
383 
384 public:
385  static text_element* parse (const std::string& s,
386  const caseless_str& interpreter);
387 };
388 
389 class
392 {
393 public:
395 
396  ~text_parser_none (void) { }
397 
398  // FIXME: is it possible to use reference counting to manage the
399  // memory for the object returned by the text parser? That would be
400  // preferable to having to know when and where to delete the object it
401  // creates...
402 
404  {
405  return new text_element_string (s);
406  }
407 };
408 
409 class
412 {
413 public:
415  : text_parser (), scanner (0), buffer_state (0), result (0)
416  { }
417 
419  { destroy_lexer (); }
420 
421  text_element* parse (const std::string& s);
422 
423  void* get_scanner (void) { return scanner; }
424 
426 
428 
429 private:
430  bool init_lexer (const std::string& s);
431 
432  void destroy_lexer (void);
433 
434 private:
435  void* scanner;
436 
438 
440 };
441 
442 inline text_element*
443 text_parser::parse (const std::string& s, const caseless_str& interpreter)
444 {
445  std::unique_ptr<text_parser> parser;
446 
447  if (interpreter.compare ("tex"))
448  parser.reset (new text_parser_tex ());
449  else
450  parser.reset (new text_parser_none ());
451 
452  return parser->parse (s);
453 }
454 
455 #endif
~text_element_color(void)
Definition: txt-eng.h:303
text_element * get_element(void)
Definition: txt-eng.h:177
text_element_string(const std::string &s="")
Definition: txt-eng.h:69
Octave interface to the compression and uncompression libraries.
Definition: aepbalance.cc:47
virtual ~text_processor(void)
Definition: txt-eng.h:352
~text_element_superscript(void)
Definition: txt-eng.h:172
fname
Definition: load-save.cc:754
text_element_subscript(char c)
Definition: txt-eng.h:142
void * buffer_state
Definition: txt-eng.h:437
void * scanner
Definition: txt-eng.h:435
fontstyle get_fontstyle(void) const
Definition: txt-eng.h:219
text_element_list(text_element *e)
Definition: txt-eng.h:117
virtual void visit(text_element_list &e)
Definition: txt-eng.h:322
void set_parse_result(text_element *e)
Definition: txt-eng.h:425
text_element_superscript(char c)
Definition: txt-eng.h:168
std::list< text_element * >::iterator iterator
Definition: base-list.h:40
virtual ~text_parser(void)
Definition: txt-eng.h:380
double get_fontsize(void) const
Definition: txt-eng.h:261
~text_parser_tex(void)
Definition: txt-eng.h:418
text_processor(void)
Definition: txt-eng.h:350
virtual void visit(text_element_fontsize &)
Definition: txt-eng.h:343
s
Definition: file-io.cc:2682
Matrix get_color(void)
Definition: txt-eng.h:305
i e
Definition: data.cc:2724
~text_parser_none(void)
Definition: txt-eng.h:396
text_element_color(double r, double g, double b)
Definition: txt-eng.h:277
text_element * parse(const std::string &s)
Definition: txt-eng.h:403
text_element * get_parse_result(void)
Definition: txt-eng.h:427
text_element_fontstyle(fontstyle st)
Definition: txt-eng.h:214
~text_element_subscript(void)
Definition: txt-eng.h:146
int get_symbol(void) const
Definition: txt-eng.h:98
text_element(void)
Definition: txt-eng.h:54
virtual void visit(text_element_superscript &e)
Definition: txt-eng.h:334
~text_element_fontstyle(void)
Definition: txt-eng.h:217
This class gets nodes and searchs inside of 'info files'.
Definition: parser.h:52
#define ASSIGN_COLOR(r, g, b)
~text_element_fontname(void)
Definition: txt-eng.h:238
text_element_fontname(const std::string &fname)
Definition: txt-eng.h:235
create a structure array and initialize its values The dimensions of each cell array of values must match Singleton cells and non cell values are repeated so that they fill the entire array If the cells are empty
Definition: ov-struct.cc:1688
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
~text_element_list(void)
Definition: txt-eng.h:121
text_element_superscript(text_element *e)
Definition: txt-eng.h:165
iterator end(void)
Definition: base-list.h:86
virtual void reset(void)
Definition: txt-eng.h:347
#define OCTINTERP_API
Definition: mexproto.h:69
std::string name
Definition: txt-eng.h:245
text_element * get_element(void)
Definition: txt-eng.h:151
text_element_list(void)
Definition: txt-eng.h:114
virtual void visit(text_element_fontname &)
Definition: txt-eng.h:341
text_element_subscript(text_element *e)
Definition: txt-eng.h:139
std::string str
Definition: hash.cc:118
virtual void accept(text_processor &p)=0
#define TEXT_ELEMENT_ACCEPT(cls)
Definition: txt-eng.h:355
static int elem
Definition: __contourc__.cc:50
std::string string_value(void) const
Definition: txt-eng.h:74
virtual void visit(text_element_subscript &e)
Definition: txt-eng.h:331
~text_element_symbol(void)
Definition: txt-eng.h:96
text_parser_none(void)
Definition: txt-eng.h:394
virtual text_element * parse(const std::string &s)=0
virtual void visit(text_element_color &)
Definition: txt-eng.h:345
Definition: dMatrix.h:37
text_element_fontsize(double fsize)
Definition: txt-eng.h:256
text_element_combined(text_element *e1, text_element *e2)
Definition: txt-eng.h:194
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
text_element_symbol(int sym)
Definition: txt-eng.h:93
text_element * result
Definition: txt-eng.h:439
With real return the complex result
Definition: data.cc:3375
text_element_combined(text_element *e)
Definition: txt-eng.h:191
~text_element_string(void)
Definition: txt-eng.h:72
std::string str
Definition: txt-eng.h:79
virtual ~text_element(void)
Definition: txt-eng.h:56
text_parser_tex(void)
Definition: txt-eng.h:414
virtual void visit(text_element_fontstyle &)
Definition: txt-eng.h:339
text_element * elem
Definition: txt-eng.h:154
void * get_scanner(void)
Definition: txt-eng.h:423
p
Definition: lu.cc:138
virtual void visit(text_element_symbol &)
Definition: txt-eng.h:320
#define scanner
bool compare(const std::string &s, size_t limit=std::string::npos) const
Definition: caseless-str.h:76
b
Definition: cellfun.cc:398
virtual void visit(text_element_combined &)
Definition: txt-eng.h:337
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 or any other valid Octave code The number of return their size
Definition: input.cc:871
~text_element_fontsize(void)
Definition: txt-eng.h:259
virtual void visit(text_element_string &e)=0
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
text_parser(void)
Definition: txt-eng.h:378
text_element_color(const std::string &cname)
Definition: txt-eng.h:285
const std::string & get_fontname(void) const
Definition: txt-eng.h:240
iterator begin(void)
Definition: base-list.h:83
text_element * elem
Definition: txt-eng.h:180