Commit dca486dd authored by Arnaud Blanchard's avatar Arnaud Blanchard
Browse files

Add constructor and destructors for blc_arrays. Add a property total_length...

Add constructor and destructors for blc_arrays. Add a property total_length which set the total number of elements.
parent 45539b8c
......@@ -39,7 +39,10 @@ typedef struct blc_array
#ifdef __cplusplus
:blc_mem {
blc_array();
/**Define and allocates the array */
blc_array(uint32_t type, uint32_t format, int dims_nb, int length0, ...);
/**Free dims. The data is freed by ~blc_mem()*/
~blc_array();
......@@ -52,6 +55,9 @@ typedef struct blc_array
/*the name should be changed*/
void init(char const *properties);
void vinit(uint32_t type, uint32_t format, int dims_nb, int length, va_list arguments);
void init(uint32_t type, uint32_t format, int dims_nb, int length0, ...);
void add_dim(int length, int step);
void add_dim(int length);
......@@ -90,6 +96,7 @@ typedef struct blc_array
blc_dim * dims;
int dims_nb;
uint32_t type, format;
size_t total_length;
} blc_array;
START_EXTERN_C
......
......@@ -33,18 +33,25 @@ char *file_texts=NULL;
blc_array::blc_array():dims(NULL), dims_nb(0){}
blc_array::blc_array(uint32_t type, uint32_t format, int dims_nb, int length0, ...){
va_list arguments;
va_start(arguments, length0);
vdef_array( type, format, dims_nb, length0, arguments);
allocate();
va_end(arguments);
}
blc_array::~blc_array(){
if (dims) FREE(dims);
}
void blc_array::init(char const *properties){
sscan_properties(properties);
}
void blc_array::vdef_array(uint32_t type, uint32_t format, int dims_nb, int length, va_list arguments){
blc_dim *dim;
total_length=1;
this->dims_nb=dims_nb;
this->type=type;
this->format=format;
......@@ -59,6 +66,7 @@ void blc_array::vdef_array(uint32_t type, uint32_t format, int dims_nb, int leng
dim->length=length;
length=va_arg(arguments, int);
}
total_length=size/get_type_size();
}
void blc_array::def_array(uint32_t type, uint32_t format, int dims_nb, int length, ...){
......@@ -81,6 +89,7 @@ void blc_array::def_array(uint32_t type, uint32_t format, int dims_nb, blc_dim *
memcpy(this->dims, dims, sizeof(blc_dim)*dims_nb);
size =dims[dims_nb-1].length*dims[dims_nb-1].step;
total_length=size/get_type_size();
}
void blc_array::def_array(uint32_t type, uint32_t format, char const *dims_string){
......@@ -89,6 +98,28 @@ void blc_array::def_array(uint32_t type, uint32_t format, char const *dims_strin
sscan_dims(dims_string);
}
void blc_array::init(char const *properties){
sscan_properties(properties);
allocate();
}
void blc_array::vinit(uint32_t type, uint32_t format, int dims_nb, int length, va_list arguments){
vdef_array(type, format, dims_nb, length, arguments);
allocate();
}
void blc_array::init(uint32_t type, uint32_t format, int dims_nb, int length, ...){
va_list arguments;
va_start(arguments, length);
vinit(type, format, dims_nb, length, arguments);
va_end(arguments);
}
void blc_array::add_dim(int length, int step){
......@@ -99,6 +130,7 @@ void blc_array::add_dim(int length, int step){
APPEND_ITEM(&dims, &dims_nb, &dim);
size=step*length; //Check if it always true ??
total_length=size/get_type_size();
}
void blc_array::add_dim(int length){
......@@ -110,7 +142,7 @@ void blc_array::set_dims(int dims_nb, int length, ...){
blc_dim *dim;
va_list args;
::free(dims);
FREE(dims);
this->dims_nb=dims_nb;
dims=MANY_ALLOCATIONS(dims_nb, blc_dim);
......@@ -125,6 +157,7 @@ void blc_array::set_dims(int dims_nb, int length, ...){
length=va_arg(args, int);
}
va_end(args);
total_length=size/get_type_size();
}
int blc_array::get_type_size(){
......@@ -185,6 +218,7 @@ void blc_array::fscan_dims(FILE *file){
size*=dim->length;
}while(fscanf(file, "x%d", &length)==1);
}
total_length=size/get_type_size();
}
int blc_array::sscan_dims(char const *string){
......@@ -207,6 +241,7 @@ int blc_array::sscan_dims(char const *string){
size*=dim->length;
}while(sscanf(string+total_pos, "x%lu%n", &dim->length, &pos)==1);
}
total_length=size/get_type_size();
return total_pos;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment