]> git.lyx.org Git - features.git/blob - src/support/block.h
iNew configure flag --with-lyxname. Misc small compilation fixes.
[features.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 #warning I disabled this to be able to compile... (JMarc)
21   // I think that, sor the same reason that string->char* is not
22   // automatic, we should have a c_array() method to do that. However,
23   // Lars, it is your choice...  
24   //    operator T* () { return arr; }
25         reference at(int i) {
26                 Assert(i >= 0 && i < s);
27                 return arr[i];
28         }
29         const_reference at(int i) const {
30                 Assert(i >= 0 && i < s);
31                 return arr[i];
32         }
33         reference operator[](int i) { return arr[i]; }
34         const_reference operator[](int i) const { return arr[i]; }
35         void operator=(block const & b) {
36                 Assert(b.size() == size());
37                 for (size_t i = 0; i < size(); ++i) {
38                         arr[i] == b[i];
39                 }
40         }
41         bool operator==(block const & b) const {
42                 Assert(b.size() == size());
43                 for (size_t i = 0; i < size(); ++i) {
44                         if (arr[i] != b[i]) return false;
45                 }
46                 return true;
47         }
48         iterator begin() { return arr[0]; }
49         iterator end() { return arr[s]; }
50         const_iterator begin() const { return arr[0]; }
51         const_iterator end() const { return arr[s]; }
52 private:
53         T arr[s];
54 };
55
56 #endif // BLOCK_H_