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