예제 #1
0
static inline void wbImportCSV_delete(wbImportCSV_t csv) {
    if (csv != NULL) {
        wbImportCSV_setFile(csv, NULL);
        if (wbImportCSV_getData(csv)) {
            wbDelete(wbImportCSV_getData(csv));
        }
        wbDelete(csv);
    }
}
예제 #2
0
static inline void wbImportRaw_delete(wbImportRaw_t raw) {
    if (raw != NULL) {
        wbImportRaw_setFile(raw, NULL);
        if (wbImportRaw_getData(raw)) {
            wbDelete(wbImportRaw_getData(raw));
        }
        wbDelete(raw);
    }
}
예제 #3
0
파일: wbLogger.cpp 프로젝트: RustIron/libwb
void wbLogger_delete(wbLogger_t logger) {
  if (logger != NULL) {
    wbLogger_clear(logger);
    wbDelete(logger);
  }
  return;
}
예제 #4
0
파일: wbExport.cpp 프로젝트: abduld/libwb
static wbExportKind_t _parseExportExtension(const char *file) {
  char *extension;
  wbExportKind_t kind;

  extension = wbFile_extension(file);

  if (wbString_sameQ(extension, "csv")) {
    kind = wbExportKind_csv;
  } else if (wbString_sameQ(extension, "tsv")) {
    kind = wbExportKind_tsv;
  } else if (wbString_sameQ(extension, "raw") ||
             wbString_sameQ(extension, "dat")) {
    kind = wbExportKind_raw;
  } else if (wbString_sameQ(extension, "text") ||
             wbString_sameQ(extension, "txt")) {
    kind = wbExportKind_text;
  } else if (wbString_sameQ(extension, "ppm") ||
             wbString_sameQ(extension, "pbm")) {
    kind = wbExportKind_ppm;
  } else {
    kind = wbExportKind_unknown;
    wbLog(ERROR, "File ", file, " does not have a compatible extension.");
  }

  wbDelete(extension);

  return kind;
}
예제 #5
0
파일: wbExport.cpp 프로젝트: sujesha/libwb
static inline void wbExportRaw_delete(wbExportRaw_t raw) {
  if (raw != NULL) {
    wbExportRaw_setFile(raw, NULL);
    wbDelete(raw);
  }
  return;
}
예제 #6
0
파일: wbExport.cpp 프로젝트: abduld/libwb
static inline void wbExportText_delete(wbExportText_t text) {
  if (text != nullptr) {
    wbExportText_setFile(text, NULL);
    wbDelete(text);
  }
  return;
}
예제 #7
0
파일: wbExport.cpp 프로젝트: abduld/libwb
static inline void wbExport_close(wbExport_t exprt) {
  wbExportKind_t kind;

  kind = wbExport_getKind(exprt);

  if (wbExport_getFile(exprt)) {
    wbDelete(wbExport_getFile(exprt));
  }

  if (kind == wbExportKind_tsv || kind == wbExportKind_csv) {
    wbExportCSV_t csv = wbExport_getCSV(exprt);
    wbExportCSV_delete(csv);
    wbExport_setCSV(exprt, NULL);
  } else if (kind == wbExportKind_raw) {
    wbExportRaw_t raw = wbExport_getRaw(exprt);
    wbExportRaw_delete(raw);
    wbExport_setRaw(exprt, NULL);
  } else if (kind == wbExportKind_text) {
    wbExportText_t text = wbExport_getText(exprt);
    wbExportText_delete(text);
    wbExport_setText(exprt, NULL);
  } else if (kind == wbExportKind_ppm) {
  } else {
    wbLog(ERROR, "Invalid export type.");
    wbExit();
  }
  return;
}
예제 #8
0
static inline wbImport_t wbImport_open(const char * file, const char * type0) {
    wbImport_t imp;
    wbImportKind_t kind;
    char * type;

    type = wbString_toLower(type0);

    if (wbString_sameQ(type, "cvs")) {
        kind = wbImportKind_csv;
    } else if (wbString_sameQ(type, "tsv")) {
        kind = wbImportKind_tsv;
    } else if (wbString_sameQ(type, "raw") || wbString_sameQ(type, "dat")) {
        kind = wbImportKind_raw;
    } else if (wbString_sameQ(type, "ppm")) {
        kind = wbImportKind_ppm;
    } else {
        wbLog(ERROR, "Invalid import type ", type0);
        wbExit();
    }

    imp = wbImport_open(file, kind);

    wbDelete(type);

    return imp;
}
예제 #9
0
파일: wbLogger.cpp 프로젝트: RustIron/libwb
static inline void wbLogEntry_delete(wbLogEntry_t elem) {
  if (elem != NULL) {
    if (wbLogEntry_getMessage(elem) != NULL) {
      wbFree(wbLogEntry_getMessage(elem));
    }
    wbDelete(elem);
  }
  return;
}
예제 #10
0
void wbFile_delete(wbFile_t file) {
    if (file != NULL) {
        int idx = wbFile_getIndex(file);
        if (wbFile_getFileName(file) != NULL) {
            wbDelete(wbFile_getFileName(file));
        }
        if (wbFile_getMode(file) != NULL) {
            wbDelete(wbFile_getMode(file));
        }
        if (wbFile_getFileHandle(file) != NULL) {
            fclose(wbFile_getFileHandle(file));
        }
        if (idx >= 0) {
            wbAssert(wbFile_handles[idx] == file);
            wbFile_handles[idx] = NULL;
        }
        if (wbFile_getData(file) != NULL) {
            wbDelete(wbFile_getData(file));
        }
        wbDelete(file);
    }
}
예제 #11
0
void wbArg_delete(wbArg_t arg) {
  if (wbArg_getInputCount(arg) > 0 && wbArg_getInputFiles(arg) != NULL) {
    int ii;
    for (ii = 0; ii < wbArg_getInputCount(arg); ii++) {
      wbDelete(wbArg_getInputFile(arg, ii));
    }
    wbDelete(wbArg_getInputFiles(arg));
    wbArg_setInputCount(arg, 0);
    wbArg_setInputFiles(arg, NULL);
  }
  if (wbArg_getOutputFile(arg)) {
    wbDelete(wbArg_getOutputFile(arg));
    wbArg_setOutputFile(arg, NULL);
  }
  if (wbArg_getExpectedOutputFile(arg)) {
    wbDelete(wbArg_getExpectedOutputFile(arg));
    wbArg_setExpectedOutputFile(arg, NULL);
  }
  if (wbArg_getType(arg)) {
    wbDelete(wbArg_getType(arg));
    wbArg_setType(arg, NULL);
  }
  return;
}
예제 #12
0
char * wbFile_read(wbFile_t file, size_t size, size_t count) {
    size_t res;
    char * buffer;
    FILE * handle;

    if (file == NULL) {
        return NULL;
    }

    handle = wbFile_getFileHandle(file);
    buffer = wbNewArray(char, size*count);

    res = fread(buffer, size, count, handle);
    if (res != count) {
        wbLog(ERROR, "Failed to read data from ", wbFile_getFileName(file));
        wbDelete(buffer);
        return NULL;
    }

    return buffer;
}
예제 #13
0
파일: wbFile.cpp 프로젝트: YurieCo/HPP_2015
char *wbFile_extension(const char *file) {
  char *extension;
  char *extensionLower;
  char *end;
  size_t len;

  len = strlen(file);
  end = (char *)&file[len - 1];
  while (*end != '.') {
    end--;
  }
  if (*end == '.') {
    end++;
  }

  extension = wbString_duplicate(end);
  extensionLower = wbString_toLower(extension);
  wbDelete(extension);

  return extensionLower;
}
예제 #14
0
static inline wbImportCSV_t wbImportCSV_read(wbImportCSV_t csv, wbBool asIntegerQ) {
    void * data;
    wbFile_t file;
    char seperator;
    int rows, columns;

    if (csv == NULL) {
        return NULL;
    }

    if (wbImportCSV_getRowCount(csv) == -1 || wbImportCSV_getColumnCount(csv) == -1) {
        if (wbImportCSV_findDimensions(csv, &rows, &columns) == NULL) {
            wbLog(ERROR, "Failed to figure out csv dimensions.");
            return NULL;
        }
        wbImportCSV_setRowCount(csv, rows);
        wbImportCSV_setColumnCount(csv, columns);
    }

    file = wbImportCSV_getFile(csv);
    seperator = wbImportCSV_getSeperator(csv);
    rows = wbImportCSV_getRowCount(csv);
    columns = wbImportCSV_getColumnCount(csv);

    if (wbImportCSV_getData(csv) != NULL) {
        wbDelete(wbImportCSV_getData(csv));
        wbImportCSV_setData(csv, NULL);
    }

    if (asIntegerQ) {
        data = csv_readAsInteger(file, seperator, rows, columns);
    } else {
        data = csv_readAsReal(file, seperator, rows, columns);
    }

    wbImportCSV_setData(csv, data);

    return csv;
}
예제 #15
0
static inline wbImportRaw_t wbImportRaw_read(wbImportRaw_t raw, wbBool asIntegerQ) {
    void * data;
    wbFile_t file;
    char seperator;
    int rows, columns;

    if (raw == NULL) {
        return NULL;
    }

    if (wbImportRaw_getRowCount(raw) == -1 || wbImportRaw_getColumnCount(raw) == -1) {
        if (wbImportRaw_findDimensions(raw)) {
            wbLog(ERROR, "Failed to figure out raw dimensions.");
            return NULL;
        }
    }

    file = wbImportRaw_getFile(raw);
    seperator = ' ';
    rows = wbImportRaw_getRowCount(raw);
    columns = wbImportRaw_getColumnCount(raw);

    if (wbImportRaw_getData(raw) != NULL) {
        wbDelete(wbImportRaw_getData(raw));
        wbImportRaw_setData(raw, NULL);
    }

    if (asIntegerQ) {
        data = csv_readAsInteger(file, seperator, rows, columns);
    } else {
        data = csv_readAsReal(file, seperator, rows, columns);
    }

    wbImportRaw_setData(raw, data);

    return raw;
}
예제 #16
0
static inline wbBool wbImportRaw_findDimensions(wbImportRaw_t raw) {
    if (raw != NULL) {
        int rows;
        int columns;
        char * line;
        wbFile_t file;
        char * strippedLine;

        file = wbImportRaw_getFile(raw);

        wbFile_rewind(file);

        line = wbFile_readLine(file);

        if (line == NULL) {
            return wbTrue;
        }

        strippedLine = lineStrip(line);

        if (lineHasSpace(strippedLine)) {
            sscanf(strippedLine, "%d %d", &rows, &columns);
        } else {
            columns = 1;
            sscanf(strippedLine, "%d", &rows);
        }

        wbImportRaw_setRowCount(raw, rows);
        wbImportRaw_setColumnCount(raw, columns);

        wbDelete(strippedLine);

        return wbFalse;
    }

    return wbTrue;
}
예제 #17
0
파일: wbExport.cpp 프로젝트: sujesha/libwb
static inline void wbExportCSV_delete(wbExportCSV_t csv) {
  if (csv != NULL) {
    wbExportCSV_setFile(csv, NULL);
    wbDelete(csv);
  }
}