libtgd 4.2
A library that makes working with multidimensional arrays in C++ easy
Public Member Functions | List of all members
TGD::Importer Class Reference

The importer class imports arrays from files or streams. More...

#include <io.hpp>

Public Member Functions

 Importer ()
 Constructor. This must be initialized with initialize(). More...
 
 Importer (const std::string &fileName, const TagList &hints=TagList())
 Constructor. More...
 
void initialize (const std::string &fileName, const TagList &hints=TagList())
 Initialize. See the constructor documentation. More...
 
const std::string & fileName () const
 Returns the file name. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 

Detailed Description

The importer class imports arrays from files or streams.

Constructor & Destructor Documentation

◆ Importer() [1/2]

TGD::Importer::Importer ( )

Constructor. This must be initialized with initialize().

◆ Importer() [2/2]

TGD::Importer::Importer ( const std::string &  fileName,
const TagList hints = TagList() 
)

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.

Member Function Documentation

◆ arrayCount()

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.

◆ checkAccess()

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.

◆ fileName()

const std::string & TGD::Importer::fileName ( ) const
inline

Returns the file name.

◆ hasMore()

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()

void TGD::Importer::initialize ( const std::string &  fileName,
const TagList hints = TagList() 
)

Initialize. See the constructor documentation.

◆ readArray()

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).


The documentation for this class was generated from the following file: