]> git.lyx.org Git - lyx.git/blob - src/mathed/array.h
Fix Angus' drawing bug + cosmetics
[lyx.git] / src / mathed / array.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 MATHEDARRAY_H
17 #define MATHEDARRAY_H
18
19 #include <vector>
20 #include <iosfwd>
21
22 #include "mathed/support.h"
23 #include "math_defs.h"
24 #include "LString.h"
25
26 class MathInset;
27 class MathMacro;
28 class Painter;
29
30 #ifdef __GNUG__
31 #pragma interface
32 #endif
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 class MathArray  {
43 public:
44         ///
45         MathArray();
46         ///
47         MathArray(MathArray const &);
48         ///
49         MathArray & operator=(MathArray const &);
50         ///
51         ~MathArray();
52
53         ///
54         int size() const;
55         ///
56         bool empty() const;
57         ///
58         void clear();
59         ///
60         void swap(MathArray &);
61         
62         ///
63         void insert(int pos, MathInset * inset);
64         ///
65         void insert(int pos, unsigned char, MathTextCodes);
66         ///
67         void insert(int pos, MathArray const &);
68
69         ///
70         void erase(int pos1, int pos2);
71         ///
72         void erase(int pos);
73         ///
74         void replace(int pos, MathInset * inset);
75         ///
76         bool prev(int & pos) const;
77         ///
78         bool next(int & pos) const;
79         ///
80         bool last(int & pos) const;
81
82
83         ///
84         void push_back(MathInset * inset);
85         ///
86         void push_back(unsigned char, MathTextCodes);
87         ///
88         void push_back(MathArray const &);
89         ///
90         MathInset * back_inset() const;
91
92         ///
93         void dump(std::ostream &) const;
94         ///
95         void dump2(std::ostream &) const;
96         ///
97         void substitute(MathMacro const &);
98         ///
99
100         ///
101         MathInset * nextInset(int pos) const;
102         ///
103         MathInset * prevInset(int pos) const;
104         ///
105         unsigned char GetChar(int pos) const;
106         /// read subsequent chars of the same kind.
107         // pos is afterwards one behind the last char belonging to the string
108         string GetString(int & pos) const;
109         ///
110         MathTextCodes GetCode(int pos) const;
111         ///
112         void setCode(int pos, MathTextCodes t);
113         ///
114         bool isInset(int pos) const;
115         ///
116         void Write(std::ostream &, bool) const;
117         ///
118         void WriteNormal(std::ostream &) const;
119 private:
120         ///
121         typedef std::vector<unsigned char>           buffer_type;
122         ///
123         typedef unsigned char                        value_type;
124
125         ///
126         int item_size(int pos) const;
127         /// Buffer
128         buffer_type bf_;
129 };
130
131
132 std::ostream & operator<<(std::ostream & os, MathArray const & ar);
133
134 #endif