library/src/datastructures/BP-LinkedList.cc
// This will take each element in the array, create a buffer of appropriate length
// and store each element within the newly created buffer essentially creating a
// flat unsigned char array representing the entire list.
This will take each element in the array, create a buffer of appropriate length
and store each element within the newly created buffer essentially creating a
flat unsigned char array representing the entire list.
This will take each element in the array create a buffer of appropriate length and store each element within the newly created buffer essentially creating a flat unsigned char array representing the entire list .
BP_ERROR_T BP_LinkLFlattenRaw(P_BP_LINKL head)
{
	if(!head)
		return ERR_FAILURE;
	if(head->flat_buff)
	{
		bpfree(head->flat_buff);
		head->flat_buff_n = 0;
		head->flat_buff   = NULL;
	}
	if(!head->total_size)
		return ERR_FAILURE;
	P_BP_LINKL_DATA first_item = TAILQ_FIRST(&head->head);
	if(!first_item)
		return ERR_FAILURE;
	size_t current_pos = 0;
	size_t n = 0;
	head->flat_buff = (unsigned char *) bpcalloc(head->total_size+1, 1);
	head->flat_buff_n = head->total_size;
	unsigned char * data = NULL;
	TAILQ_FOREACH(first_item, &head->head, linkl_data)
	{
		data = (unsigned char *) first_item->data;
		for(n=0; n < first_item->data_size; n++)
		{
			head->flat_buff[current_pos] = (unsigned char) data[n];
			current_pos++;
 		}
	}
	return ERR_SUCCESS;
}
BP_ERROR_T BP_LinkLFlattenRaw ( P_BP_LINKL head ) { if ( ! head ) return ERR_FAILURE ; if ( head -> flat_buff ) { bpfree ( head -> flat_buff ) ; head -> flat_buff_n = 0 ; head -> flat_buff = NULL ; } if ( ! head -> total_size ) return ERR_FAILURE ; P_BP_LINKL_DATA first_item = TAILQ_FIRST ( & head -> head ) ; if ( ! first_item ) return ERR_FAILURE ; size_t current_pos = 0 ; size_t n = 0 ; head -> flat_buff = ( unsigned char * ) bpcalloc ( head -> total_size + 1 , 1 ) ; head -> flat_buff_n = head -> total_size ; unsigned char * data = NULL ; TAILQ_FOREACH ( first_item , & head -> head , linkl_data ) { data = ( unsigned char * ) first_item -> data ; for ( n = 0 ; n < first_item -> data_size ; n ++ ) { head -> flat_buff [ current_pos ] = ( unsigned char ) data [ n ] ; current_pos ++ ; } } return ERR_SUCCESS ; }
This will take each element in the array, create a buffer of appropriate length
and store each element within the newly created buffer essentially creating a
flat unsigned char array representing the entire list.
This will take each element in the array create a buffer of appropriate length and store each element within the newly created buffer essentially creating a flat unsigned char array representing the entire list .
// ensure we have a head // destroy flattened data if it already exists // ensure the list has a total size // attempt to get the first item // ensure we have a first item // current position, used for writing data to the string // inner iterator for data // allocate space for the buffer (+1 for mandatory null termination) // since void has no type, we need a temporary data pointer // looks for a pointer in the item // set temporary pointer // now write the buffer into position // return indicating success