File: txmath1.h

package info (click to toggle)
tralics 2.14.4-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, stretch, wheezy
  • size: 17,152 kB
  • ctags: 8,260
  • sloc: cpp: 49,403; xml: 18,145; sh: 140; makefile: 118
file content (109 lines) | stat: -rw-r--r-- 3,365 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// -*- C++ -*-
// $Id: txmath1.h,v 2.8 2008/10/28 15:41:59 grimm Exp $
// TRALICS, copyright (C)INRIA/apics (Jose' Grimm) 2006, 2007,2008

// This software is governed by the CeCILL license under French law and
// abiding by the rules of distribution of free software.  You can  use, 
// modify and/ or redistribute the software under the terms of the CeCILL
// license as circulated by CEA, CNRS and INRIA at the following URL
// "http://www.cecill.info". 
// (See the file COPYING in the main directory for details)



// Helper for finding start and end of <mrow>
class MathQ {
  int start; // position of the item
  int end; // type of the item
public:
  // no default Ctor, but two specialised ones 
  MathQ(int i, int t) : start(i), end(t) {}
  void get_both(int& i, int& t) const { i = start; t = end; }
  void print(ostream&fp)const { fp << start << ", " << end << "; "; }
};


// Helper for finding big small etc
class MathPAux {
  int pos; // position of the item
  math_types type; // type of the item
public:
  // no default Ctor, but two specialised ones 
  MathPAux(int i, math_types t) : pos(i), type(t) {}
  int get_pos() const { return pos; }
  math_types get_type() const { return type; }
  void get_both(int& i, math_types& t) const { i = pos; t = type;  }
  void print(ostream&) const;
  bool is_small() const  { return type==mt_flag_small_l || type == mt_flag_small_r || type == mt_flag_small_m; }
};

typedef std::list<MathPAux> MathPList;
typedef std::list<MathPAux>::const_iterator const_math_p_iterator;
typedef std::list<MathPAux>::iterator math_p_iterator;


class MathPAuxType: public unary_function<MathPAux,bool> {
  math_types T;
public:
  explicit MathPAuxType(math_types TT) : T (TT) {}
  bool operator() (const MathPAux& m) { return m.get_type() == T; }
};

class MathPAuxSmall: public unary_function<MathPAux,bool> {
public:
  explicit MathPAuxSmall() {}
  bool operator() (const MathPAux& m) { 
    return m.is_small();
  }
};

class MathP {
  MathPList value;
 public:
  friend ostream& operator<<(ostream& fp, const MathP& X);
  void clear() { value.clear(); }
  bool empty() const { return value.empty(); }
  MathP find_big(int &);
  bool is_lbr(int&,int&) const;
  bool is_lbr2(int&,int&) const;
  bool find_paren_rec(MathQList& res) const;
  void find_paren2(int start, MathQList& res,bool);
  void push_back(MathPAux N) { value.push_back(N); } 
  void remove_binrel();
  bool has_small() const;
  bool find_paren_matched1() const;
  void find_paren_matched2(MathQList& res) const;

 private:
  bool analyse1(bool) const;
  MathP find_relbin(int &);
  void find_paren1(int start1, int end1,MathQList& res,bool);
};


// Helper for finding start and end of <mrow>
class MathF {
  bool state;
  bool t_big;
  int next_change;
  int next_finish;
  MathQList aux;
  MathList res;
  Xmlp t;
public:
  MathF(const Math&,bool);
  bool in_mrow() const { return state; }
  bool is_next_change(int i) const { return i == next_change; }
  MathQList& get_aux() { return aux; }
  void change_state();
  void make_t_big() { t_big = true; }
  void handle_t();
  void push_in_t(Xmlp x);
  void push_in_res(MathElt x) { res.push_back(x); }
  void push_in_res(Xmlp x) { res.push_back(MathElt(x,-1,mt_flag_small)); }
  void reset() { t = 0; state = true; t_big = false;}
  void finish(MathList&);
  void dump_aux();
  void pop_last(Xmlp);
};