]> git.lyx.org Git - lyx.git/blob - src/mathed/array.h
mathed11.diff from Andre
[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
21
22 class MathedInset;
23
24 #ifdef __GNUG__
25 #pragma interface
26 #endif
27
28 #ifndef byte
29 #define byte unsigned char
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         ///
49         enum {
50                 ///
51                 ARRAY_SIZE = 256,
52                 ///
53                 ARRAY_STEP = 16,
54                 ///
55                 ARRAY_MIN_SIZE = 4
56         };
57
58         ///
59         explicit
60         MathedArray(int size = ARRAY_STEP);
61
62         ///
63         int empty() const;
64    
65         ///
66         int last() const;
67         ///
68         void last(int l);
69    
70         /// Merge \a dx elements from array \a a at \apos.
71         /// This doesn't changes the size (dangerous)
72         void mergeF(MathedArray * a, int pos, int dx); 
73
74         /// Insert a character at position \a pos
75         void insert(int pos, byte);
76
77         ///
78         void raw_pointer_copy(MathedInset ** p, int pos) const;
79         ///
80         void raw_pointer_insert(void * p, int pos, int len);
81         ///
82         void strange_copy(MathedArray * dest, int dpos, int spos, int len);
83         ///
84         byte operator[](int) const;
85         ///
86         byte & operator[](int i);
87         
88         ///
89         void move(int p, int shift);
90         ///
91         void resize(int newsize);
92         ///
93         int maxsize() const;
94         /// Make sure we can access at least \a needed elements
95         void need_size(int needed);
96 private:
97
98         /// Buffer
99         buffer_type bf_;
100         /// Last position inserted.
101         int last_;
102 };
103 #endif