|
gimme-alpha 0.1
|
Include dependency graph for gimme_alpha_types.h:
This graph shows which files directly or indirectly include this file:Go to the source code of this file.
Enumerations | |
| enum | data_types { INT_TYPE, LONG_INT_TYPE, FLOAT_TYPE, DOUBLE_TYPE, LONG_DOUBLE_TYPE, COMPLEX_TYPE, STRING_TYPE, BOOLEAN_TYPE } |
| enum | data_type_string_format_type { STRING_FORMATTED_LIKE_C, STRING_FORMATTED_LIKE_FORTRAN } |
Functions | |
| ___const char * | format_string_for_type_print (enum data_types t) |
| ___const char * | format_string_for_type_scan (enum data_types t) |
| ___malloc void * | string_to_data (char *s, enum data_types t) |
| ___malloc void * | string_to_data_x2 (char *s1, char *s2, enum data_types t) |
| ___malloc void * | string_to_data_fortran (char *s, enum data_types t) |
| ___malloc void * | string_to_data_generic (char *s, enum data_types t, enum data_type_string_format_type fmt) |
| ___malloc void * | string_to_data_xN (gchar **s, enum data_types t) |
Definition at line 52 of file gimme_alpha_types.h.
| enum data_types |
| INT_TYPE | |
| LONG_INT_TYPE | |
| FLOAT_TYPE | |
| DOUBLE_TYPE | |
| LONG_DOUBLE_TYPE | |
| COMPLEX_TYPE | |
| STRING_TYPE | |
| BOOLEAN_TYPE |
Definition at line 40 of file gimme_alpha_types.h.
| ___const char* format_string_for_type_print | ( | enum data_types | t | ) |
Definition at line 46 of file gimme_alpha_types.c.
References COMPLEX_TYPE, DOUBLE_TYPE, FLOAT_TYPE, INT_TYPE, LONG_DOUBLE_TYPE, LONG_INT_TYPE, and STRING_TYPE.
{
switch(t) {
case INT_TYPE: return "%d";
case LONG_INT_TYPE: return "%ld";
case FLOAT_TYPE: return "%f";
case DOUBLE_TYPE: return "%G";
case LONG_DOUBLE_TYPE: return "%lG";
case COMPLEX_TYPE: return NULL;
case STRING_TYPE:
default:
return "%s";
}
}
| ___const char* format_string_for_type_scan | ( | enum data_types | t | ) |
Definition at line 32 of file gimme_alpha_types.c.
References COMPLEX_TYPE, DOUBLE_TYPE, FLOAT_TYPE, INT_TYPE, LONG_DOUBLE_TYPE, LONG_INT_TYPE, and STRING_TYPE.
Referenced by string_to_data(), string_to_data_fortran(), string_to_data_x2(), and string_to_data_xN().
{
switch(t) {
case INT_TYPE: return "%d";
case LONG_INT_TYPE: return "%ld";
case FLOAT_TYPE: return "%f";
case DOUBLE_TYPE: return "%le";
case LONG_DOUBLE_TYPE: return "%e";
case COMPLEX_TYPE: return NULL;
case STRING_TYPE:
default:
return "%s";
}
}
Here is the caller graph for this function:| ___malloc void* string_to_data | ( | char * | s, |
| enum data_types | t | ||
| ) |
Definition at line 60 of file gimme_alpha_types.c.
References COMPLEX_TYPE, DOUBLE_TYPE, FLOAT_TYPE, format_string_for_type_scan(), INT_TYPE, LONG_DOUBLE_TYPE, LONG_INT_TYPE, STRING_TYPE, and unlikely.
Referenced by process_args(), read_nextnano_extract_item_typed(), read_nextnano_extract_list_typed(), read_titled_whitespaced_data(), and string_to_data_generic().
{
if(t == STRING_TYPE) return s;
if(t == COMPLEX_TYPE) return NULL;
char *format = format_string_for_type_scan(t);
if(unlikely(format == NULL)) return NULL;
size_t size;
switch(t) {
case INT_TYPE: size = sizeof(int); break;
case LONG_INT_TYPE: size = sizeof(long int); break;
case FLOAT_TYPE: size = sizeof(float); break;
case DOUBLE_TYPE: size = sizeof(double); break;
case LONG_DOUBLE_TYPE: size = sizeof(long double); break;
default:
return NULL;
}
void* data;
if(unlikely((data = malloc(size)) == NULL)) return NULL;
int n;
if(unlikely((n = sscanf(s, format, data)) != 1)) {
free(data);
return NULL;
}
return data;
}
Here is the call graph for this function:
Here is the caller graph for this function:| ___malloc void* string_to_data_fortran | ( | char * | s, |
| enum data_types | t | ||
| ) |
Definition at line 156 of file gimme_alpha_types.c.
References COMPLEX_TYPE, DOUBLE_TYPE, FLOAT_TYPE, format_string_for_type_scan(), INT_TYPE, LONG_DOUBLE_TYPE, LONG_INT_TYPE, STRING_TYPE, and unlikely.
Referenced by string_to_data_generic().
{
if(t == STRING_TYPE) return s;
if(t == COMPLEX_TYPE) return NULL;
char *format = format_string_for_type_scan(t);
if(unlikely(format == NULL)) return NULL;
size_t size;
switch(t) {
case INT_TYPE: size = sizeof(int); break;
case LONG_INT_TYPE: size = sizeof(long int); break;
case FLOAT_TYPE: size = sizeof(float); break;
case DOUBLE_TYPE: size = sizeof(double); break;
case LONG_DOUBLE_TYPE: size = sizeof(long double); break;
default:
return NULL;
}
void* data;
if(unlikely((data = malloc(size)) == NULL)) return NULL;
int n;
if(unlikely((n = sscanf(s, format, data)) != 1)) {
free(data);
return NULL;
}
return data;
}
Here is the call graph for this function:
Here is the caller graph for this function:| ___malloc void* string_to_data_generic | ( | char * | s, |
| enum data_types | t, | ||
| enum data_type_string_format_type | fmt | ||
| ) |
Definition at line 183 of file gimme_alpha_types.c.
References STRING_FORMATTED_LIKE_C, STRING_FORMATTED_LIKE_FORTRAN, string_to_data(), and string_to_data_fortran().
{
switch(fmt) {
case STRING_FORMATTED_LIKE_C:
return string_to_data(s, t);
case STRING_FORMATTED_LIKE_FORTRAN:
return string_to_data_fortran(s, t);
default:
return NULL;
}
}
Here is the call graph for this function:| ___malloc void* string_to_data_x2 | ( | char * | s1, |
| char * | s2, | ||
| enum data_types | t | ||
| ) |
Definition at line 85 of file gimme_alpha_types.c.
References COMPLEX_TYPE, DOUBLE_TYPE, FLOAT_TYPE, format_string_for_type_scan(), INT_TYPE, LONG_DOUBLE_TYPE, LONG_INT_TYPE, STRING_TYPE, and unlikely.
Referenced by process_args().
{
if(t == STRING_TYPE) {
GString *s = g_string_new(s1);
s = g_string_append(s, s2);
char* ess = s->str;
g_string_free(s, FALSE);
return ess;
}
if(t == COMPLEX_TYPE) return NULL;
char *format = format_string_for_type_scan(t);
if(unlikely(format == NULL)) return NULL;
size_t size;
switch(t) {
case INT_TYPE: size = sizeof(int); break;
case LONG_INT_TYPE: size = sizeof(long int); break;
case FLOAT_TYPE: size = sizeof(float); break;
case DOUBLE_TYPE: size = sizeof(double); break;
case LONG_DOUBLE_TYPE: size = sizeof(long double); break;
default:
return NULL;
}
char* data;
if(unlikely((data = malloc(size*2)) == NULL)) return NULL;
int n;
if(unlikely((n = sscanf(s1, format, &data[0])) != 1)) {
free(data);
return NULL;
}
if(unlikely((n = sscanf(s2, format, &data[size])) != 1)) {
free(data);
return NULL;
}
return data;
}
Here is the call graph for this function:
Here is the caller graph for this function:| ___malloc void* string_to_data_xN | ( | gchar ** | s, |
| enum data_types | t | ||
| ) |
Gets a contiguous block of N values
| s | GNOME string vector (http://library.gnome.org/devel/glib/stable/glib-String-Utility-Functions.html#g-strsplit) with the strings containing the numbers |
| t | data type to be dealt with |
Definition at line 120 of file gimme_alpha_types.c.
References COMPLEX_TYPE, DOUBLE_TYPE, FLOAT_TYPE, format_string_for_type_scan(), INT_TYPE, LONG_DOUBLE_TYPE, LONG_INT_TYPE, STRING_TYPE, and unlikely.
{
int N = g_strv_length(s);
if(t == STRING_TYPE) {
GString *gs = g_string_new(s[0]);
for(int i=1; i<N; i++) {
gs = g_string_append(gs, s[i]);
}
char* ess = gs->str;
g_string_free(gs, FALSE);
return ess;
}
if(t == COMPLEX_TYPE) return NULL;
char *format = format_string_for_type_scan(t);
if(unlikely(format == NULL)) return NULL;
size_t size;
switch(t) {
case INT_TYPE: size = sizeof(int); break;
case LONG_INT_TYPE: size = sizeof(long int); break;
case FLOAT_TYPE: size = sizeof(float); break;
case DOUBLE_TYPE: size = sizeof(double); break;
case LONG_DOUBLE_TYPE: size = sizeof(long double); break;
default:
return NULL;
}
char* data;
if(unlikely((data = malloc(size*N)) == NULL)) return NULL;
int n;
for(int i=0; i<N; i++) {
if(unlikely((n = sscanf(s[i], format, &data[size*i])) != 1)) {
free(data);
return NULL;
}
}
return data;
}
Here is the call graph for this function: