]> git.lyx.org Git - lyx.git/blob - src/mathed/array.h
fix "make dist" target
[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
25 class MathedInset;
26 class MathMacro;
27
28 #ifdef __GNUG__
29 #pragma interface
30 #endif
31
32 /** \class MathedArray
33     \brief A resizable array.
34     
35     A general purpose resizable array.
36     
37     \author Alejandro Aguilar Sierra
38     \author André Pönitz
39     \author Lars Gullik Bjønnes
40     \version February 2001
41   */
42 class MathedArray  {
43 public:
44         ///
45         typedef std::vector<byte>           buffer_type;
46         typedef byte                        value_type;
47         typedef buffer_type::size_type      size_type;
48         typedef buffer_type::iterator       iterator;
49         typedef buffer_type::const_iterator const_iterator;
50         
51         ///
52         MathedArray();
53         ///
54         MathedArray(MathedArray const &);
55         ///
56         MathedArray & operator=(MathedArray const &);
57         ///
58         ~MathedArray();
59
60         ///
61         iterator begin();
62         ///
63         iterator end();
64         ///
65         const_iterator begin() const;
66         ///
67         const_iterator end() const;
68         
69         ///
70         int empty() const;
71         ///
72         void clear();
73    
74         ///
75         int last() const;
76         ///
77         void last(int l);
78
79         ///
80         void swap(MathedArray &);
81         ///
82         void shrink(int pos1, int pos2);
83
84 #if 0
85         ///
86         void insert(iterator pos, const_iterator beg, const_iterator end);
87 #else
88         /// Merge \a dx elements from array \a a at \apos.
89         /// This doesn't changes the size (dangerous)
90         void merge(MathedArray const & a, int pos); 
91 #endif
92         ///
93         void raw_pointer_copy(MathedInset ** p, int pos) const;
94 #if 0
95         ///
96         void insertInset(int pos, MathedInset * p, int type);
97         ///
98         MathedInset * getInset(int pos);
99 #else
100         ///
101         void raw_pointer_insert(void * p, int pos);
102 #endif
103         ///
104         void strange_copy(MathedArray * dest, int dpos, int spos, int len);
105         ///
106         byte operator[](int) const;
107         ///
108         byte & operator[](int i);
109         
110         ///
111         void move(int p, int shift);
112         ///
113         void resize(int newsize);
114         /// Make sure we can access at least \a needed elements
115         void need_size(int needed);
116         ///
117         void dump(std::ostream &) const;
118         ///
119         void dump2(std::ostream &) const;
120         /// creates copies of all embedded insets
121         void deep_copy();
122         ///
123         void substitute(MathMacro *);
124         ///
125         void push_back(MathedInset * inset, int t);
126         ///
127         void push_back(byte, MathedTextCodes);
128 private:
129         /// Buffer
130         buffer_type bf_;
131 #if 0
132         ///
133         struct InsetTable {
134                 ///
135                 int pos;
136                 ///
137                 MathedInset * inset;
138                 ///
139                 InsetTable(int p, MathedInset * i)
140                         : pos(p), inset(i) {}
141                 
142         };
143         /// 
144         typedef std::vector<InsetTable> InsetList;
145         /// The list of insets in this array.
146         InsetList insetList_;
147 #endif
148         /// Last position inserted.
149         int last_;
150 };
151
152 inline 
153 std::ostream & operator<<(std::ostream & os, MathedArray const & ar)
154 {
155         ar.dump(os);
156         return os;
157 }
158
159 #endif