Created
June 20, 2011 09:05
-
-
Save sonney2k/1035341 to your computer and use it in GitHub Desktop.
datatype free
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<class T> class SGVector | |
{ | |
public: | |
/** default constructor */ | |
SGVector() : vector(NULL), vlen(0), do_free(false) { } | |
/** constructor for setting params */ | |
SGVector(T* v, index_t len, bool free_vec=false) | |
: vector(v), vlen(len), do_free(free_vec) { } | |
/** copy constructor */ | |
SGVector(const SGVector &orig) | |
: vector(orig.vector), vlen(orig.vlen) { } | |
void free_vector() | |
{ | |
if (do_free) | |
delete[] vector; | |
vector=NULL; | |
do_free=false; | |
vlen=0; | |
} | |
public: | |
/** vector */ | |
T* vector; | |
/** length of vector */ | |
index_t vlen; | |
/** whether vector needs to be freed */ | |
bool do_free; | |
}; | |
template<class T> class SGMatrix | |
{ | |
public: | |
/** default constructor */ | |
SGMatrix() : matrix(NULL), num_rows(0), num_cols(0), do_free(false) { } | |
/** constructor for setting params */ | |
SGMatrix(T* m, index_t nrows, index_t ncols, bool free_matrix=false) | |
: matrix(m), num_rows(nrows), num_cols(ncols), do_free(free_matrix) { } | |
/** copy constructor */ | |
SGMatrix(const SGMatrix &orig) | |
: matrix(orig.matrix), num_rows(orig.num_rows), | |
num_cols(orig.num_cols), do_free(free_matrix) { } | |
void free_matrix() | |
{ | |
if (do_free) | |
delete[] matrix; | |
matrix=NULL; | |
do_free=false; | |
num_rows=0; | |
num_cols=0; | |
} | |
public: | |
/** matrix */ | |
T* matrix; | |
/** number of rows of matrix */ | |
index_t num_rows; | |
/** number of columns of matrix */ | |
index_t num_cols; | |
/** whether matrix needs to be freed */ | |
bool do_free; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment