Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Block.h
- *
- * Created on: 23/04/2015
- * Author: Matt
- */
- #include "stdlib.h"
- #include <stdexcept>
- #include <assert.h>
- #include <iostream>
- #ifndef BLOCK_H_
- #define BLOCK_H_
- #define BLOCK_SIZE 8
- template<class T>
- class Block {
- public:
- typedef int row[BLOCK_SIZE];
- Block() {
- CELL_VALUE = NULL;
- allocate();
- }
- ~Block() {
- destroy();
- }
- row& operator[](std::size_t i) {
- assert(i < BLOCK_SIZE);
- return m_data[i];
- }
- private:
- void allocate() {
- CELL_VALUE = new T*[BLOCK_SIZE];
- for (int i = 0; i < BLOCK_SIZE; i++) {
- CELL_VALUE[i] = new T[BLOCK_SIZE];
- }
- }
- void destroy() {
- if (NULL == CELL_VALUE)
- return;
- for (int i = 0; i < BLOCK_SIZE; i++) {
- delete[] CELL_VALUE[i];
- }
- delete[] CELL_VALUE;
- CELL_VALUE = NULL;
- }
- row m_data[BLOCK_SIZE];
- T** CELL_VALUE;
- };
- #endif /* BLOCK_H_ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement