per test
[rattatechess.git] / array.h
blob48bc283a8b3b805575efecadd56ddb42829b644f
1 /***************************************************************************
2 array.h - 0x88 and bounds-checked static array
3 -------------------
4 begin : Sun Sep 23 2007
5 copyright : (C) 2007 by Maurizio Monge
6 email : monge@linuz.sns.it
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #ifndef __ARRAY_H__
19 #define __ARRAY_H__
21 #include "compiler.h"
23 template<typename T, int S>
24 class Array {
25 public:
26 #ifdef DEBUG
27 class PACKED Type {
28 public:
29 T data[S];
30 T& operator[](unsigned int index) const {
31 ASSERT(index < S);
32 return ((T*)data)[index];
35 #else //DEBUG
36 typedef T Type[S];
37 #endif //DEBUG
40 #ifdef DEBUG
42 class PACKED A88Data {
43 public:
44 uint8_t data[128];
45 uint8_t& operator[](unsigned int index) const {
46 ASSERT(!(index & (uint8_t)0x08));
47 ASSERT(index < 0x80);
48 return ((uint8_t*)data)[index];
52 class PACKED A88 {
53 public:
54 uint8_t* ptr;
55 A88(uint8_t *p) : ptr(p) {}
56 A88(const A88Data& d) : ptr((uint8_t*)d.data) {}
57 uint8_t& operator[](unsigned int index) const {
58 ASSERT(!(index & (uint8_t)0x08));
59 ASSERT(index < 0x80);
60 return ((uint8_t*)ptr)[index];
63 #define DEF2_A88(a,b) A88Data a; A88Data b
65 #else //DEBUG
67 typedef uint8_t* A88;
68 #define DEF2_A88(a,b) union { uint8_t a[128]; struct { uint8_t _pad_for_##b[8]; uint8_t b[120]; }; }
70 #endif //DEBUG
72 inline void zero_a88(A88 d)
74 register uint64_t *z = (uint64_t*)&d[0];
75 for(int i=0;i<8;i++)
77 *z++ = 0;
78 z++;
82 #endif //__ARRAY_H__