libtgd 4.3
A library that makes working with multidimensional arrays in C++ easy
|
The importer class imports arrays from files or streams. More...
#include <io.hpp>
Public Member Functions | |
Importer () | |
Constructor. This must be initialized with initialize(). | |
Importer (const std::string &fileName, const TagList &hints=TagList()) | |
Constructor. | |
void | initialize (const std::string &fileName, const TagList &hints=TagList()) |
Initialize. See the constructor documentation. | |
const std::string & | fileName () const |
Returns the file name. | |
Error | checkAccess () const |
Checks if the file is accessible and the format is supported. This function does not access the file contents yet, and does not result in an open file descriptor. | |
int | arrayCount () |
Returns the number of arrays in this file. Returns -1 if that information is not available, e.g. if the file is actually a stream or if the file format does not provide that information. | |
ArrayContainer | readArray (Error *error=nullptr, int arrayIndex=-1) |
Read an array from the file and return it. On error, the error code will be set (if error is not nullptr) and a null array will be returned. | |
bool | hasMore (Error *error=nullptr) |
Returns whether there are more arrays in the file, i.e. whether you can read the next array with readArray(). This information is always available, for all file formats and also for streams. If (and only if) this function returns false, then it sets the error code. | |
The importer class imports arrays from files or streams.
TGD::Importer::Importer | ( | ) |
Constructor. This must be initialized with initialize().
Constructor.
The file name is required. The special file name "-" is interpreted as standard input. The optional hints may be useful depending on the file format. For example, raw files contain no information about array dimension or type, so the hints must contain the tags COMPONENTS and TYPE as well as SIZE (for 1D arrays), WIDTH and HEIGHT (for 2D arrays), WIDTH, HEIGHT and DEPTH (for 3D arrays) or DIMENSIONS, DIMENSION0, DIMENSION1, ... (for arrays of arbitrary dimension).
Note that this initialization does not try to open the file yet, it merely sets up the necessary information (and thus cannot fail). The functions that access the data will report any errors that might occur. If you want to perform some lightweight checks without accessing the file contents, use the checkAccess() function.
int TGD::Importer::arrayCount | ( | ) |
Returns the number of arrays in this file. Returns -1 if that information is not available, e.g. if the file is actually a stream or if the file format does not provide that information.
Error TGD::Importer::checkAccess | ( | ) | const |
Checks if the file is accessible and the format is supported. This function does not access the file contents yet, and does not result in an open file descriptor.
|
inline |
Returns the file name.
bool TGD::Importer::hasMore | ( | Error * | error = nullptr | ) |
Returns whether there are more arrays in the file, i.e. whether you can read the next array with readArray(). This information is always available, for all file formats and also for streams. If (and only if) this function returns false, then it sets the error code.
Initialize. See the constructor documentation.
ArrayContainer TGD::Importer::readArray | ( | Error * | error = nullptr, |
int | arrayIndex = -1 ) |
Read an array from the file and return it. On error, the error code will be set (if error is not nullptr) and a null array will be returned.
By default, the next array in the file will be read, but you can give an index to chose the array you want (this only works reliably if arrayCount() returns something other than -1).