useDynLib(HDF5Array)

import(methods)
importFrom(utils, read.table)
importFrom(stats, setNames)
importFrom(tools, file_path_as_absolute)
importFrom(Matrix, sparseMatrix)

### We import rhdf5filters only for the side effect of setting system
### environment variable HDF5_PLUGIN_PATH to rhdf5filters::hdf5_plugin_path().
### This is done by rhdf5filters:::.onLoad(). The only filter we actually
### care about at the moment is LZF.
import(rhdf5filters)
import(rhdf5)
import(BiocGenerics)
import(S4Vectors)
import(IRanges)
import(S4Arrays)
import(DelayedArray)


### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export S4 classes
###

exportClasses(
    H5FileID, H5File, character_OR_H5File,
    H5DSetDescriptor,
    HDF5ArraySeed,
    HDF5Array, HDF5Matrix,
    ReshapedHDF5ArraySeed,
    ReshapedHDF5Array, ReshapedHDF5Matrix,
    HDF5RealizationSink,
    H5SparseMatrixSeed, CSC_H5SparseMatrixSeed, CSR_H5SparseMatrixSeed,
    H5SparseMatrix,
    H5ADMatrixSeed,
    Dense_H5ADMatrixSeed, CSC_H5ADMatrixSeed, CSR_H5ADMatrixSeed,
    H5ADMatrix,
    TENxMatrixSeed,
    TENxMatrix,
    TENxRealizationSink
)


### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export S3 methods
###

S3method(close, H5FileID)
S3method(close, H5File)

S3method(open, H5FileID)
S3method(open, H5File)

S3method(t, CSC_H5SparseMatrixSeed)
S3method(t, CSR_H5SparseMatrixSeed)
S3method(t, CSC_H5ADMatrixSeed)
S3method(t, CSR_H5ADMatrixSeed)

### We also export them thru the export() directive so that (a) they can be
### called directly, (b) tab-completion on the name of the generic shows them,
### and (c) methods() doesn't asterisk them.

export(
    close.H5FileID,
    close.H5File,

    open.H5FileID,
    open.H5File,

    t.CSC_H5SparseMatrixSeed,
    t.CSR_H5SparseMatrixSeed,
    t.CSC_H5ADMatrixSeed,
    t.CSR_H5ADMatrixSeed
)


### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export S4 methods for generics not defined in HDF5Array
###

exportMethods(
    ## Methods for generics defined in the base package:
    dim, dimnames, t,

    ## Methods for generics defined in the methods package:
    coerce, show,

    ## Methods for generics defined in the BiocGenerics package:
    path, "path<-", type, updateObject,

    ## Methods for generics defined in the S4Arrays package:
    extract_array, is_sparse, "is_sparse<-",

    ## Methods for generics defined in the DelayedArray package:
    chunkdim, write_block,
    sparsity, OLD_extract_sparse_array, read_sparse_block,
    matrixClass, DelayedArray,
    close
)


### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export non-generic functions
###

export(
    H5FileID, H5File,
    h5ls,
    H5DSetDescriptor, destroy_H5DSetDescriptor,
    get_h5mread_returned_type, h5mread,
    h5mread_from_reshaped,
    set_h5dimnames, get_h5dimnames, h5writeDimnames, h5readDimnames,
    HDF5ArraySeed,
    HDF5Array,
    ReshapedHDF5ArraySeed,
    ReshapedHDF5Array,
    setHDF5DumpDir, getHDF5DumpDir,
    setHDF5DumpFile, getHDF5DumpFile, lsHDF5DumpFile,
    setHDF5DumpName, getHDF5DumpName,
    setHDF5DumpChunkLength, getHDF5DumpChunkLength,
    setHDF5DumpChunkShape, getHDF5DumpChunkShape,
    getHDF5DumpChunkDim,
    setHDF5DumpCompressionLevel, getHDF5DumpCompressionLevel,
    appendDatasetCreationToHDF5DumpLog, showHDF5DumpLog,
    HDF5RealizationSink, writeHDF5Array,
    saveHDF5SummarizedExperiment, loadHDF5SummarizedExperiment,
    quickResaveHDF5SummarizedExperiment,
    H5SparseMatrixSeed,
    H5SparseMatrix,
    H5ADMatrixSeed,
    H5ADMatrix,
    TENxMatrixSeed,
    TENxMatrix,
    TENxRealizationSink, writeTENxMatrix
)


### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export S4 generics defined in HDF5Array, and corresponding methods
###

export(
    ## H5SparseMatrixSeed-class.R:
    extractNonzeroDataByCol, extractNonzeroDataByRow
)

### Exactly the same list as above.
exportMethods(
    extractNonzeroDataByCol, extractNonzeroDataByRow
)

### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Export internal utility functions for developers
###

export(
    shorten_assay2h5_links,
    restore_absolute_assay2h5_links,
    validate_HDF5ArraySeed_dataset_geometry,
    write_h5_assays,
    create_dir,
    replace_dir,
    check_and_delete_files,
    stop_if_bad_dir
)
