1999-09-27 18:44:28 +00:00
|
|
|
|
// -*- C++ -*-
|
|
|
|
|
/*
|
|
|
|
|
* Purpose: A general purpose resizable array.
|
|
|
|
|
* Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
|
|
|
|
|
* Created: January 1996
|
|
|
|
|
*
|
|
|
|
|
* Dependencies: None (almost)
|
|
|
|
|
*
|
2000-03-09 03:36:48 +00:00
|
|
|
|
* Copyright: 1996, Alejandro Aguilar Sierra
|
1999-09-27 18:44:28 +00:00
|
|
|
|
* 1997 The LyX Team!
|
|
|
|
|
*
|
|
|
|
|
* You are free to use and modify this code under the terms of
|
|
|
|
|
* the GNU General Public Licence version 2 or later.
|
|
|
|
|
*/
|
|
|
|
|
|
2001-02-12 08:55:14 +00:00
|
|
|
|
#ifndef MATHEDARRAY_H
|
|
|
|
|
#define MATHEDARRAY_H
|
|
|
|
|
|
2001-02-09 17:17:08 +00:00
|
|
|
|
#include <vector>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
|
#include "math_defs.h"
|
2001-02-12 08:55:14 +00:00
|
|
|
|
|
|
|
|
|
class MathedInset;
|
|
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
|
#pragma interface
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/** \class MathedArray
|
|
|
|
|
\brief A resizable array.
|
|
|
|
|
|
2000-08-07 20:58:24 +00:00
|
|
|
|
A general purpose resizable array.
|
2001-02-12 08:55:14 +00:00
|
|
|
|
|
|
|
|
|
\author Alejandro Aguilar Sierra
|
|
|
|
|
\author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
\author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
\version February 2001
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*/
|
2001-02-12 08:55:14 +00:00
|
|
|
|
class MathedArray {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
public:
|
2001-02-09 17:17:08 +00:00
|
|
|
|
///
|
2001-02-12 08:55:14 +00:00
|
|
|
|
typedef std::vector<byte> buffer_type;
|
|
|
|
|
typedef byte value_type;
|
|
|
|
|
typedef buffer_type::size_type size_type;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
///
|
|
|
|
|
enum {
|
|
|
|
|
///
|
|
|
|
|
ARRAY_SIZE = 256,
|
|
|
|
|
///
|
|
|
|
|
ARRAY_STEP = 16,
|
|
|
|
|
///
|
|
|
|
|
ARRAY_MIN_SIZE = 4
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
///
|
2000-04-08 17:02:02 +00:00
|
|
|
|
explicit
|
2001-02-12 08:55:14 +00:00
|
|
|
|
MathedArray(int size = ARRAY_STEP);
|
2000-04-08 17:02:02 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
///
|
2001-02-12 08:55:14 +00:00
|
|
|
|
int empty() const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
///
|
2001-02-12 08:55:14 +00:00
|
|
|
|
int last() const;
|
|
|
|
|
///
|
|
|
|
|
void last(int l);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-02-12 08:55:14 +00:00
|
|
|
|
/// Merge \a dx elements from array \a a at \apos.
|
|
|
|
|
/// This doesn't changes the size (dangerous)
|
|
|
|
|
void mergeF(MathedArray * a, int pos, int dx);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-02-12 08:55:14 +00:00
|
|
|
|
/// Insert a character at position \a pos
|
|
|
|
|
void insert(int pos, byte);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
///
|
2001-02-12 08:55:14 +00:00
|
|
|
|
void raw_pointer_copy(MathedInset ** p, int pos) const;
|
|
|
|
|
///
|
|
|
|
|
void raw_pointer_insert(void * p, int pos, int len);
|
|
|
|
|
///
|
|
|
|
|
void strange_copy(MathedArray * dest, int dpos, int spos, int len);
|
|
|
|
|
///
|
|
|
|
|
byte operator[](int) const;
|
|
|
|
|
///
|
|
|
|
|
byte & operator[](int i);
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
void move(int p, int shift);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
///
|
2001-02-12 08:55:14 +00:00
|
|
|
|
void resize(int newsize);
|
|
|
|
|
///
|
|
|
|
|
int maxsize() const;
|
2001-02-12 11:25:44 +00:00
|
|
|
|
/// Make sure we can access at least \a needed elements
|
|
|
|
|
void need_size(int needed);
|
2001-02-12 08:55:14 +00:00
|
|
|
|
private:
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
/// Buffer
|
2001-02-12 08:55:14 +00:00
|
|
|
|
buffer_type bf_;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
/// Last position inserted.
|
2001-02-12 08:55:14 +00:00
|
|
|
|
int last_;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
};
|
2001-02-12 08:55:14 +00:00
|
|
|
|
#endif
|