File: auto_array.h

package info (click to toggle)
bowtie 1.2.3+dfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 16,888 kB
  • sloc: cpp: 35,784; perl: 5,903; ansic: 1,247; sh: 1,180; python: 487; makefile: 426
file content (38 lines) | stat: -rw-r--r-- 605 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
 * auto_array.h
 *
 *  Created on: Oct 12, 2009
 *      Author: Ben Langmead
 */

#include <cstring>

#ifndef AUTO_ARRAY_H_
#define AUTO_ARRAY_H_

/**
 * A simple fixed-length array of type T, automatically freed in the
 * destructor.
 */
template<typename T>
class AutoArray {
public:
	AutoArray(size_t sz) {
		t_ = NULL;
		t_ = new T[sz];
		memset(t_, 0, sz*sizeof(T));
		sz_ = sz;
	}
	~AutoArray() { if(t_ != NULL) delete[] t_; }
	T& operator[](size_t sz) {
		return t_[sz];
	}
	const T& operator[](size_t sz) const {
		return t_[sz];
	}
private:
	T *t_;
	size_t sz_;
};

#endif /* AUTO_ARRAY_H_ */