bool field::setMembers( std::deque<CString> members ) { try { if( members.size() != 4 ) { try { if( strlen( members[0] ) <= 0 ) throw( Exception("A field name must be specified.") ); fieldName = new char[ strlen( members[0] ) ]; strcpy( fieldName, members[0] ); fieldWidth = CStringToInt( members[1] ); number_of_decimals = CStringToInt( members[2] ); type = (DBFFieldType)CStringToInt( members[3] ); return true; } catch( Exception e ) { return false; } } else throw( Exception("Cannot create field ... wrong number of parameters.") ); } catch( Exception e ) { return false; } }
Rgba StringToRgba(const std::string& s) { Rgba color; std::vector<std::string> colorComponents = SplitString(s, ","); color.r = (unsigned char)CStringToInt(colorComponents[0].c_str()); color.g = (unsigned char)CStringToInt(colorComponents[1].c_str()); color.b = (unsigned char)CStringToInt(colorComponents[2].c_str()); color.a = 255;//CStringToInt(colorComponents[3].c_str()); return color; }
bool record::setMembers( std::deque<CString> members ) { try { if( members.size() != 1 ) throw( Exception("Cannot create record ... wrong number of parameters.") ); setValue( members[0] ); setValue( CStringToInt( members[0] ) ); setValue( CStringToDouble( members[0] ) ); return true; } catch( Exception e ) { return false; } }
MATRIX* ReliefF::ReadFromDataset(CString filename, UINT width, UINT height) { MATRIX *_matrix; UINT nwidth = 0, nheight = 0, i; _matrix = (MATRIX*) malloc (sizeof (MATRIX)); if (!_matrix) printf(IDS_ERROR_INIT); _matrix->width = width; _matrix->height = height; _matrix->data = (REAL**) malloc (height * sizeof (REAL*)); if (NULL == _matrix->data) printf(IDS_ERROR_INIT); for (i = 0; i < height; i++) { _matrix->data[i] = (REAL*)malloc(width * sizeof(REAL)); if (NULL == _matrix->data[i]) printf(IDS_ERROR_INIT); } FILE *file; UINT buf_size = 0xFFFF; CHAR *buffer, *ptr; buffer = (CHAR*)malloc(buf_size * sizeof(CHAR)); if(NULL == buffer) printf(IDS_ERROR_INIT); // Open price file - abort if filename invalid char *temp = filename.GetBuffer(filename.GetLength()); file = fopen(temp, "r"); if(NULL == file) { printf(IDS_ERROR_FILE, filename); err_exit(temp, 0); } CString real, imaginary; while (!feof(file)) { if (NULL != fgets(buffer, buf_size, file)) { // if line is more than a NL char if (strlen(buffer) > strlen("\n")) { nwidth = 0; ptr = strtok(buffer, " e"); while (NULL != ptr) { real = ptr; ptr = strtok(NULL, " e"); if (NULL != ptr) { imaginary = ptr; } REAL test = CStringToInt(real) * pow(10, CStringToInt(imaginary)); _matrix->data[nheight][nwidth] = test; ++nwidth; ptr = strtok(NULL, " e"); } if (width != nwidth) { printf("width != nwidth"); } ++nheight; } } } free(buffer); FILE *fp; fp = fopen("C:\\fancy_data.txt", "w+"); fprintf(fp, "基因个数=%d\n", width); for (int j = 0; j < height; j++) for (int i = 0; i < width; i++) { fprintf(fp, "%f", _matrix->data[j][i]); fprintf(fp, " "); fprintf(fp, "\n"); } fclose(fp); return _matrix; }