|
funkalicious 0.1
|
#include <stdlib.h>#include <string.h>#include <glib-2.0/glib.h>#include <stdio.h>#include "binary_data_common.h"
Include dependency graph for binary_data_common.c:Go to the source code of this file.
Defines | |
| #define | DOTCODE_BINARY_DATA_COMMON_GERROR_DOMAN 43712 |
Functions | |
| enum dotcode_type | dotcode_type_from_string (const char *s) |
| char * | dotcode_string_from_type (enum dotcode_type t) |
| const char * | dotcode_string_from_type2 (enum dotcode_type t) |
| void | flip_endian (char *buffer, int num_bytes) |
| void | dotcode_free_type (enum dotcode_type t, void *ptr, long unsigned int count, GError **err, gboolean free_struct) |
| static void | determine_templated_type_ (char *t1, char *t2, GList **tlist, GError **err) |
| void | dotcode_determine_templated_type (const char *str, GList **tlist, GError **err) |
| #define DOTCODE_BINARY_DATA_COMMON_GERROR_DOMAN 43712 |
Definition at line 33 of file binary_data_common.c.
Referenced by determine_templated_type_(), and dotcode_free_type().
| static void determine_templated_type_ | ( | char * | t1, |
| char * | t2, | ||
| GList ** | tlist, | ||
| GError ** | err | ||
| ) | [static] |
Determines a type from a type string.
| t1 | is the first item in the char** returned from g_strsplit(str, "<", 1) |
| t2 | is the second string in the char** |
| tlist | a pointer to an *existing* NULL GList*. Types may be nested, hence the need for a GList of types. The data in the GList is enum dotcode_type. NOTE that the tlist MUST be initialized to NULL before calling this function, as it's recursive. |
Definition at line 202 of file binary_data_common.c.
References DOTCODE_BINARY_DATA_COMMON_GERROR_DOMAN, dotcode_type_from_string(), and dotcode_tensor::t.
Referenced by dotcode_determine_templated_type().
{
if(t1 == NULL) return;
enum dotcode_type *t = (enum dotcode_type*)malloc(sizeof(enum dotcode_type));
if(t == NULL) {
*err = g_error_new(DOTCODE_BINARY_DATA_COMMON_GERROR_DOMAN, 180, "dotcode::read_binary_data::read_vector: ERROR failed to allocate storage for a new vector.");
}
*t = dotcode_type_from_string(t1);
if(t2 != NULL) {
/*Here's the recursive step.*/
char** sstr = g_strsplit(t2, "<", 2);
determine_templated_type_(sstr[0], sstr[1], tlist, err);
g_strfreev(sstr);
}
*tlist = g_list_prepend(*tlist, t);
}
Here is the call graph for this function:
Here is the caller graph for this function:| void dotcode_determine_templated_type | ( | const char * | str, |
| GList ** | tlist, | ||
| GError ** | err | ||
| ) |
This is the front-end to the determine_templated_type_ function.
| str | is the list |
| tlist | a pointer to an *existing* GList*, which will be set to NULL. |
| err | is a pointer to an existing NULL GError* |
Definition at line 226 of file binary_data_common.c.
References determine_templated_type_().
Referenced by dotcode_read_tensor(), and read_dotcode_generic_file().
{
*tlist = NULL;
/*Remove invalid chars; valid are alphanumeric, underscoe, and >; this will
remove '>', but that's fine; we don't really want it.
*/
char* dstr = g_strdup(str);
g_strcanon(dstr, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_<", ' ');
g_strchug(dstr);
char** sstr = g_strsplit(dstr, "<", 2);
determine_templated_type_(sstr[0], sstr[1], tlist, err);
g_free(dstr);
g_strfreev(sstr);
}
Here is the call graph for this function:
Here is the caller graph for this function:| void dotcode_free_type | ( | enum dotcode_type | t, |
| void * | ptr, | ||
| long unsigned int | count, | ||
| GError ** | err, | ||
| gboolean | free_struct | ||
| ) |
Definition at line 102 of file binary_data_common.c.
References dotcode_tensor::data, DOTCODE_ARRAY, DOTCODE_BINARY_DATA_COMMON_GERROR_DOMAN, DOTCODE_FLOAT4, DOTCODE_FLOAT8, dotcode_free_type(), DOTCODE_GRID, DOTCODE_INT, DOTCODE_SSTRING, dotcode_string_from_type2(), DOTCODE_TENSOR, DOTCODE_VECTOR, e, dotcode_tensor::indices, and dotcode_tensor::metadata.
Referenced by dotcode_free_type(), dotcode_grid_from_density(), dotcode_internal_read_gridspec(), dotcode_read_grid(), libdotcode_readwrite_suite_add_tests(), main(), read_dotcode_generic_file(), read_dotcode_typed_file(), and read_random_10x10x10_float8_grid().
{
GError *e = NULL;
/*If we have a buffer of a simple type, just free it.*/
switch(t) {
case DOTCODE_FLOAT8:
case DOTCODE_FLOAT4:
case DOTCODE_INT:
case DOTCODE_SSTRING:
free(ptr);
return;
default:
break;
}
long unsigned int size = 1;
for(long unsigned int i=0; i<count; i++) {
/*Since these are freeing an array of actual structures (as
opposed to an array of pointers to structures) we don't need to
free the struct at the end.*/
switch(t) {
case DOTCODE_VECTOR:
dotcode_free_type(((struct dotcode_vector*)ptr)->t,
((struct dotcode_vector*)ptr)->data,
3,
&e,
FALSE);
break;
case DOTCODE_ARRAY:
dotcode_free_type(((struct dotcode_array*)ptr)->t,
((struct dotcode_array*)ptr)->storage,
(((struct dotcode_array*)ptr)->imax - ((struct dotcode_array*)ptr)->imax +1),
&e,
FALSE);
break;
case DOTCODE_TENSOR:
/*need to know how many items there are, for the derived types
(irrelevant for float, int)*/
size = 1;
for(long unsigned int j=0; j<((struct dotcode_tensor*)ptr)->Nd; j++)
size*=((((struct dotcode_tensor*)ptr)->indices)[2*j+1]-(((struct dotcode_tensor*)ptr)->indices)[2*j]+1);
/*need to know how many items there are*/
dotcode_free_type(((struct dotcode_tensor*)ptr)->t,
((struct dotcode_tensor*)ptr)->data,
size,
&e,
FALSE);
free(((struct dotcode_tensor*)ptr)->indices);
free(((struct dotcode_tensor*)ptr)->metadata);
break;
case DOTCODE_GRID:
for(int i=0; i<3; i++) {
dotcode_free_type(DOTCODE_ARRAY,
((struct dotcode_grid*)ptr)->gridsites[i],
1,
&e,
TRUE);
}
dotcode_free_type(DOTCODE_TENSOR,
((struct dotcode_grid*)ptr)->data,
1,
&e,
TRUE);
break;
default:
*err = g_error_new(DOTCODE_BINARY_DATA_COMMON_GERROR_DOMAN, 1, "dotcode::binary_data_common::dotcode_free_type: Invalid type %d (%s)", t, dotcode_string_from_type2(t));
return;
}
if(e != NULL) {
g_propagate_prefixed_error(err, e, "dotcode::binary_data_common::dotcode_free_type: Failure when freeing type %d (%s)", t, dotcode_string_from_type2(t));
return;
}
}
if(free_struct) {
switch(t) {
case DOTCODE_VECTOR:
free((struct dotcode_vector*)ptr);
break;
case DOTCODE_ARRAY:
free((struct dotcode_array*)ptr);
break;
case DOTCODE_TENSOR:
free((struct dotcode_tensor*)ptr);
break;
case DOTCODE_GRID:
free((struct dotcode_grid*)ptr);
break;
default:
break;
}
}
}
Here is the call graph for this function:
Here is the caller graph for this function:| char* dotcode_string_from_type | ( | enum dotcode_type | t | ) |
Definition at line 58 of file binary_data_common.c.
References dotcode_string_from_type2().
Referenced by dotcode_write_array(), dotcode_write_tensor(), and main().
{
const char* s = dotcode_string_from_type2(t);
if(s == NULL) return NULL;
return g_strdup(s);
}
Here is the call graph for this function:
Here is the caller graph for this function:| const char* dotcode_string_from_type2 | ( | enum dotcode_type | t | ) |
This one is nice for using for one-off situations, e.g. error strings
Definition at line 64 of file binary_data_common.c.
References DOTCODE_ARRAY, DOTCODE_FLOAT4, DOTCODE_FLOAT8, DOTCODE_GRID, DOTCODE_INT, DOTCODE_INVALID_TYPE, DOTCODE_SSTRING, DOTCODE_TENSOR, and DOTCODE_VECTOR.
Referenced by dotcode_free_type(), dotcode_read_generic(), dotcode_read_tensor(), dotcode_string_from_type(), dotcode_write_array(), dotcode_write_float4(), dotcode_write_float8(), dotcode_write_generic(), dotcode_write_grid(), dotcode_write_int(), dotcode_write_sstring(), dotcode_write_tensor(), dotcode_write_typed_file(), main(), read_dotcode_generic_file(), and read_dotcode_typed_file().
{
switch(t) {
case DOTCODE_FLOAT8:
return g_strdup("float8");
case DOTCODE_FLOAT4:
return g_strdup("float4");
case DOTCODE_INT:
return g_strdup("int4");
case DOTCODE_VECTOR:
return g_strdup("Vector");
case DOTCODE_ARRAY:
return g_strdup("Array");
case DOTCODE_TENSOR:
return g_strdup("Tensor");
case DOTCODE_GRID:
return g_strdup("Grid");
case DOTCODE_SSTRING:
return g_strdup("SString");
case DOTCODE_INVALID_TYPE:
return g_strdup("INVALID TYPE");
default:
return NULL;
}
return NULL;
}
Here is the caller graph for this function:| enum dotcode_type dotcode_type_from_string | ( | const char * | s | ) |
Definition at line 35 of file binary_data_common.c.
References DOTCODE_ARRAY, DOTCODE_FLOAT4, DOTCODE_FLOAT8, DOTCODE_GRID, DOTCODE_INT, DOTCODE_INVALID_TYPE, DOTCODE_SSTRING, DOTCODE_TENSOR, and DOTCODE_VECTOR.
Referenced by determine_templated_type_().
{
if(!g_ascii_strncasecmp(s, "float8", strlen("float8"))){
return DOTCODE_FLOAT8;
}else if(!g_ascii_strncasecmp(s, "float4", strlen("float4"))){
return DOTCODE_FLOAT4;
}else if(!g_ascii_strncasecmp(s, "int", strlen("int"))){
return DOTCODE_INT;
}else if(!g_ascii_strncasecmp(s, "int4", strlen("int4"))){
return DOTCODE_INT;
}else if(!g_ascii_strncasecmp(s, "Vector", strlen("Vector"))){
return DOTCODE_VECTOR;
}else if(!g_ascii_strncasecmp(s, "Array", strlen("Array"))){
return DOTCODE_ARRAY;
}else if(!g_ascii_strncasecmp(s, "Tensor", strlen("Tensor"))){
return DOTCODE_TENSOR;
}else if(!g_ascii_strncasecmp(s, "Grid", strlen("Grid"))){
return DOTCODE_GRID;
}else if(!g_ascii_strncasecmp(s, "SString", strlen("SString"))){
return DOTCODE_SSTRING;
}
return DOTCODE_INVALID_TYPE;
}
Here is the caller graph for this function:| void flip_endian | ( | char * | buffer, |
| int | num_bytes | ||
| ) |
Definition at line 90 of file binary_data_common.c.
References c.
Referenced by dotcode_read_float4(), dotcode_read_float8(), and dotcode_read_int().
{
int i, j;
char c;
int max = num_bytes >> 1;
for(i=0, j=(num_bytes-1); i<max; ++i, --j) {
c=buffer[i];
buffer[i]=buffer[j];
buffer[j]=c;
}
}
Here is the caller graph for this function: