]> git.lyx.org Git - lyx.git/blob - src/mathed/math_data.h
move things around
[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  {
44 public:
45         ///
46         typedef std::vector<MathAtom>        buffer_type;
47         ///
48         typedef buffer_type::const_iterator  const_iterator;
49         ///
50         typedef buffer_type::iterator        iterator;
51         ///
52         typedef buffer_type::size_type       size_type;
53         ///
54         typedef buffer_type::difference_type difference_type;
55         ///
56         typedef buffer_type::size_type       idx_type;
57         ///
58         typedef buffer_type::size_type       pos_type;
59
60 public:
61         ///
62         MathArray();
63         ///
64         MathArray(MathArray const & ar, size_type from, size_type to);
65         ///
66         MathArray(iterator from, iterator to);
67
68         ///
69         size_type size() const;
70         ///
71         bool empty() const;
72         ///
73         void clear();
74         ///
75         void swap(MathArray &);
76
77         /// inserts single atom at position pos
78         void insert(size_type pos, MathAtom const & at);
79         /// inserts multiple atoms at position pos
80         void insert(size_type pos, MathArray const & ar);
81
82         /// erase range from pos1 to pos2
83         void erase(iterator pos1, iterator pos2);
84         /// erase single atom
85         void erase(iterator pos);
86         /// erase range from pos1 to pos2
87         void erase(size_type pos1, size_type pos2);
88         /// erase single atom
89         void erase(size_type pos);
90         /// erase everythng
91         void erase();
92
93         ///
94         void push_back(MathAtom const & at);
95         ///
96         void push_back(MathArray const & ar);
97         ///
98         void pop_back();
99         ///
100         MathAtom & back();
101
102         ///
103         MathAtom & front();
104         ///
105         MathAtom const & front() const;
106
107         ///
108         void dump() const;
109         ///
110         void dump2() const;
111         ///
112         void substitute(MathMacro const & macro);
113         ///
114         void replace(ReplaceData &);
115
116         /// looks for exact match
117         bool match(MathArray const & ar) const;
118         /// looks for inclusion match starting at pos
119         bool matchpart(MathArray const & ar, pos_type pos) const;
120         /// looks for containment, return == size mean not found
121         size_type find(MathArray const & ar) const;
122         /// looks for containment, return == size mean not found
123         size_type find_last(MathArray const & ar) const;
124         ///
125         bool contains(MathArray const & ar) const;
126
127         /// write acccess to single atom
128         MathAtom & operator[](size_type pos) { return at(pos); }
129         /// read access o single atom
130         MathAtom const & operator[](size_type pos) const { return at(pos); }
131         ///
132         const_iterator begin() const;
133         ///
134         const_iterator end() const;
135         ///
136         iterator begin();
137         ///
138         iterator end();
139
140         ///
141         void validate(LaTeXFeatures &) const;
142
143 private:
144         /// is this an exact match at this position?
145         bool find1(MathArray const & ar, size_type pos) const;
146         /// write acccess to single atom
147         MathAtom & at(size_type pos);
148         /// read access o single atom
149         MathAtom const & at(size_type pos) const;
150
151         /// Buffer
152         buffer_type bf_;
153 };
154
155 ///
156 std::ostream & operator<<(std::ostream & os, MathArray const & ar);
157
158
159 #endif