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