]> git.lyx.org Git - lyx.git/blob - src/support/block.h
some new (not extensive) changes, some fixes, will probably reverto to .la libs later...
[lyx.git] / src / support / block.h
1 // -*- C++ -*-
2
3 #ifndef BLOCK_H
4 #define BLOCK_H
5
6 #include "LAssert.h"
7
8 template <class T, size_t s>
9 class block {
10 public:
11         typedef T value_type;
12         typedef size_t size_type;
13         typedef T * pointer;
14         typedef T const * const_pointer;
15         typedef T & reference;
16         typedef T const & const_reference;
17         typedef T * iterator;
18         typedef T const * const_iterator;
19         size_type size() const { return s; }
20         operator T* () { return arr; }
21         reference at(int i) {
22                 Assert(i >= 0 && i < s);
23                 return arr[i];
24         }
25         const_reference at(int i) const {
26                 Assert(i >= 0 && i < s);
27                 return arr[i];
28         }
29         reference operator[](int i) { return arr[i]; }
30         const_reference operator[](int i) const { return arr[i]; }
31         void operator=(block const & b) {
32                 Assert(b.size() == size());
33                 for (size_t i = 0; i < size(); ++i) {
34                         arr[i] == b[i];
35                 }
36         }
37         bool operator==(block const & b) const {
38                 Assert(b.size() == size());
39                 for (size_t i = 0; i < size(); ++i) {
40                         if (arr[i] != b[i]) return false;
41                 }
42                 return true;
43         }
44         iterator begin() { return arr[0]; }
45         iterator end() { return arr[s]; }
46         const_iterator begin() const { return arr[0]; }
47         const_iterator end() const { return arr[s]; }
48 private:
49         T arr[s];
50 };
51
52 #endif // BLOCK_H_