00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <string.h>
00021 #include "flgrCoreMalloc.h"
00022 #include "flgrCoreData.h"
00023 #include "flgrCoreTypes.h"
00024 #include "flgrCoreDispatch.h"
00025
00026 #define FLGR_MACRO_PARSE_STR_CONSTANT(dtype,motif,var) \
00027 for(k=0 ; k<spp ; k++) { \
00028 sscanf(strin,motif,&var); \
00029 *(((dtype*) (constout))+k) = (dtype) var; \
00030 while((*strin!=' ') && (*strin!='\0')) strin++; \
00031 } \
00032 break
00033
00034 FLGR_Ret flgr_parse_str_constant(FLGR_Type type, int spp, char *strin, void *constout) {
00035 long long val_fixed;
00036 fgFLOAT64 val_float;
00037 int k;
00038
00039
00040
00041 if(spp<0) {
00042 POST_ERROR("Size of vectors could not be < 1\n");
00043 return FLGR_RET_VECTOR_SIZE_ERROR;
00044 }
00045
00046 switch(type) {
00047 case FLGR_BIT:
00048 FLGR_MACRO_PARSE_STR_CONSTANT(fgBIT,"%Ld",val_fixed);
00049 case FLGR_UINT8:
00050 FLGR_MACRO_PARSE_STR_CONSTANT(fgUINT8,"%Ld",val_fixed);
00051 case FLGR_UINT16:
00052 FLGR_MACRO_PARSE_STR_CONSTANT(fgUINT16,"%Ld",val_fixed);
00053 case FLGR_UINT32:
00054 FLGR_MACRO_PARSE_STR_CONSTANT(fgUINT32,"%Ld",val_fixed);
00055 case FLGR_UINT64:
00056 FLGR_MACRO_PARSE_STR_CONSTANT(fgUINT64,"%Ld",val_fixed);
00057 case FLGR_INT8:
00058 FLGR_MACRO_PARSE_STR_CONSTANT(fgINT8,"%Ld",val_fixed);
00059 case FLGR_INT16:
00060 FLGR_MACRO_PARSE_STR_CONSTANT(fgINT16,"%Ld",val_fixed);
00061 case FLGR_INT32:
00062 FLGR_MACRO_PARSE_STR_CONSTANT(fgINT32,"%Ld",val_fixed);
00063 case FLGR_INT64:
00064 FLGR_MACRO_PARSE_STR_CONSTANT(fgINT64,"%Ld",val_fixed);
00065 case FLGR_FLOAT32:
00066 FLGR_MACRO_PARSE_STR_CONSTANT(fgFLOAT32,"%lf",val_float);
00067 case FLGR_FLOAT64:
00068 FLGR_MACRO_PARSE_STR_CONSTANT(fgFLOAT64,"%lf",val_float);
00069 default:
00070 POST_ERROR("type unknown!\n");
00071 return FLGR_RET_TYPE_UNKNOWN;
00072 }
00073
00074 return FLGR_RET_OK;
00075
00076 }
00077
00078
00079 #define FLGR_MACRO_ALLOCATE_VECTOR_CONST(dtype) \
00080 for(k=0 ; k<spp ; k++) { \
00081 ((dtype *) tmp)[k] = *((dtype*) valueForEachVectorElement); \
00082 } \
00083 break
00084
00085 void *flgr_allocate_vector_const(FLGR_Type type, int spp, void *valueForEachVectorElement) {
00086 FLGR_Ret ret;
00087 void *tmp;
00088 int k;
00089
00090
00091
00092 if( (ret=flgr_is_data_type_valid(type))!=FLGR_RET_OK) {
00093 POST_ERROR("unknown type\n");
00094 return NULL;
00095 }
00096
00097 if(spp<0) {
00098 POST_ERROR("Size of vectors could not be < 1\n");
00099 return NULL;
00100 }
00101
00102 tmp = flgr_malloc(flgr_get_sizeof(type) * spp);
00103
00104 switch(type) {
00105 case FLGR_BIT:
00106 FLGR_MACRO_ALLOCATE_VECTOR_CONST(fgBIT);
00107 case FLGR_UINT8:
00108 FLGR_MACRO_ALLOCATE_VECTOR_CONST(fgUINT8);
00109 case FLGR_UINT16:
00110 FLGR_MACRO_ALLOCATE_VECTOR_CONST(fgUINT16);
00111 case FLGR_UINT32:
00112 FLGR_MACRO_ALLOCATE_VECTOR_CONST(fgUINT32);
00113 case FLGR_INT8:
00114 FLGR_MACRO_ALLOCATE_VECTOR_CONST(fgINT8);
00115 case FLGR_INT16:
00116 FLGR_MACRO_ALLOCATE_VECTOR_CONST(fgINT16);
00117 case FLGR_INT32:
00118 FLGR_MACRO_ALLOCATE_VECTOR_CONST(fgINT32);
00119 case FLGR_FLOAT32:
00120 FLGR_MACRO_ALLOCATE_VECTOR_CONST(fgFLOAT32);
00121 case FLGR_FLOAT64:
00122 FLGR_MACRO_ALLOCATE_VECTOR_CONST(fgFLOAT64);
00123 default:
00124 POST_ERROR("type unknown!\n");
00125 return NULL;
00126 }
00127
00128 return tmp;
00129 }