]> git.lyx.org Git - lyx.git/blob - src/mathed/math_data.h
the up/down stuff reworked
[lyx.git] / src / mathed / math_data.h
1 // -*- C++ -*-
2 /*
3  *  Purpose:     A general purpose resizable array.
4  *  Author:      Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
5  *  Created:     January 1996
6  *
7  *  Dependencies: None (almost)
8  *
9  *  Copyright: 1996, Alejandro Aguilar Sierra
10  *                 1997  The LyX Team!
11  *
12  *   You are free to use and modify this code under the terms of
13  *   the GNU General Public Licence version 2 or later.
14  */
15
16 #ifndef MATH_DATA_H
17 #define MATH_DATA_H
18
19 #include <iosfwd>
20 #include <vector>
21
22 #include "math_atom.h"
23
24 class MathMacro;
25 class LaTeXFeatures;
26 class ReplaceData;
27
28
29 #ifdef __GNUG__
30 #pragma interface
31 #endif
32
33
34 /** \class MathArray
35     \brief Low level container for math insets
36
37     \author Alejandro Aguilar Sierra
38     \author André Pönitz
39     \author Lars Gullik Bjønnes
40     \version February 2001
41   */
42
43 class MathArray : private std::vector<MathAtom> {
44 public:
45         /// re-use inhertited stuff
46         typedef std::vector<MathAtom> base_type;
47         using base_type::const_iterator;
48         using base_type::iterator;
49         using base_type::size_type;
50         using base_type::difference_type;
51         using base_type::size;
52         using base_type::empty;
53         using base_type::clear;
54         using base_type::begin;
55         using base_type::end;
56         using base_type::push_back;
57         using base_type::pop_back;
58         using base_type::back;
59         using base_type::front;
60         using base_type::swap;
61         ///
62         typedef size_type idx_type;
63         typedef size_type pos_type;
64         
65 public:
66         ///
67         MathArray() {}
68         ///
69         MathArray(const_iterator from, const_iterator to);
70         ///
71         void append(MathArray const & ar);
72
73         /// inserts single atom at position pos
74         void insert(size_type pos, MathAtom const & at);
75         /// inserts multiple atoms at position pos
76         void insert(size_type pos, MathArray const & ar);
77
78         /// erase range from pos1 to pos2
79         void erase(iterator pos1, iterator pos2);
80         /// erase single atom
81         void erase(iterator pos);
82         /// erase range from pos1 to pos2
83         void erase(size_type pos1, size_type pos2);
84         /// erase single atom
85         void erase(size_type pos);
86
87         ///
88         void dump() const;
89         ///
90         void dump2() const;
91         ///
92         void substitute(MathMacro const & macro);
93         ///
94         void replace(ReplaceData &);
95
96         /// looks for exact match
97         bool match(MathArray const & ar) const;
98         /// looks for inclusion match starting at pos
99         bool matchpart(MathArray const & ar, pos_type pos) const;
100         /// looks for containment, return == size mean not found
101         size_type find(MathArray const & ar) const;
102         /// looks for containment, return == size mean not found
103         size_type find_last(MathArray const & ar) const;
104         ///
105         bool contains(MathArray const & ar) const;
106         ///
107         void validate(LaTeXFeatures &) const;
108
109         /// checked write access
110         MathAtom & operator[](pos_type);
111         /// checked read access
112         MathAtom const & operator[](pos_type) const;
113 private:
114         /// is this an exact match at this position?
115         bool find1(MathArray const & ar, size_type pos) const;
116 };
117
118 ///
119 std::ostream & operator<<(std::ostream & os, MathArray const & ar);
120
121
122 #endif