]> git.lyx.org Git - features.git/blob - src/mathed/array.h
c5ec80b7870b1628bb57d45493c0a8e34a53a10d
[features.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 MathScriptInset;
28 class MathMacro;
29 class Painter;
30
31 #ifdef __GNUG__
32 #pragma interface
33 #endif
34
35 /** \class MathArray
36     \brief A resizable array.
37     
38     A general purpose resizable array.
39     
40     \author Alejandro Aguilar Sierra
41     \author André Pönitz
42     \author Lars Gullik Bjønnes
43     \version February 2001
44   */
45 class MathArray  {
46 public:
47         ///
48         MathArray();
49         ///
50         MathArray(MathArray const &);
51         ///
52         MathArray & operator=(MathArray const &);
53         ///
54         ~MathArray();
55
56         ///
57         int size() const;
58         ///
59         bool empty() const;
60         ///
61         void clear();
62         ///
63         void swap(MathArray &);
64         
65         ///
66         void insert(int pos, MathInset * inset);
67         ///
68         void insert(int pos, byte, MathTextCodes);
69         ///
70         void insert(int pos, MathArray const &);
71
72         ///
73         void erase(int pos1, int pos2);
74         ///
75         void erase(int pos);
76         ///
77         void replace(int pos, MathInset * inset);
78         ///
79         bool prev(int & pos) const;
80         ///
81         bool next(int & pos) const;
82         ///
83         bool last(int & pos) const;
84
85
86         ///
87         void push_back(MathInset * inset);
88         ///
89         void push_back(byte, MathTextCodes);
90         ///
91         void push_back(MathArray const &);
92         ///
93         MathInset * back_inset() const;
94
95         ///
96         void dump(std::ostream &) const;
97         ///
98         void dump2(std::ostream &) const;
99         ///
100         void substitute(MathMacro const &);
101         ///
102
103         ///
104         MathInset * GetInset(int pos) const;
105         ///
106         MathScriptInset * prevScriptInset(int pos) const;
107         ///
108         MathScriptInset * nextScriptInset(int pos) const;
109         ///
110         byte GetChar(int pos) const;
111         /// read subsequent chars of the same kind.
112         // pos is afterwards one behind the last char belonging to the string
113         string GetString(int & pos) const;
114         ///
115         MathTextCodes GetCode(int pos) const;
116         ///
117         void setCode(int pos, MathTextCodes t);
118         ///
119         bool isInset(int pos) const;
120         ///
121         void Write(std::ostream &, bool) const;
122         ///
123         void WriteNormal(std::ostream &) const;
124 private:
125         ///
126         typedef std::vector<byte>           buffer_type;
127         ///
128         typedef byte                        value_type;
129
130         ///
131         int item_size(int pos) const;
132         /// Buffer
133         buffer_type bf_;
134 };
135
136
137 std::ostream & operator<<(std::ostream & os, MathArray const & ar);
138
139 #endif