libNuML 1.1.1
Library for reading / writing NuML documents
NUMLReader.cpp File Reference
#include <sbml/xml/XMLError.h>
#include <sbml/xml/XMLErrorLog.h>
#include <sbml/xml/XMLInputStream.h>
#include <sbml/SBMLReader.h>
#include <numl/NUMLErrorLog.h>
#include <numl/NUMLVisitor.h>
#include <numl/NUMLDocument.h>
#include <numl/NUMLError.h>
#include <numl/NUMLReader.h>

Functions

static bool isCriticalError (const unsigned int errorId)
 
LIBNUML_EXTERN NUMLReader_tNUMLReader_create ()
 Creates a new NUMLReader and returns it. More...
 
LIBNUML_EXTERN void NUMLReader_free (NUMLReader_t *sr)
 Frees the given NUMLReader. More...
 
LIBNUML_EXTERN NUMLDocument_tNUMLReader_readNUML (NUMLReader_t *sr, const char *filename)
 Reads an NUML document from the given file. More...
 
LIBNUML_EXTERN NUMLDocument_tNUMLReader_readNUMLFromFile (NUMLReader_t *sr, const char *filename)
 Reads an NUML document from the given file. More...
 
LIBNUML_EXTERN NUMLDocument_tNUMLReader_readNUMLFromString (NUMLReader_t *sr, const char *xml)
 Reads an NUML document from the given XML string. More...
 
LIBNUML_EXTERN int NUMLReader_hasZlib ()
 Predicate returning non-zero or zero depending on whether underlying libNUML is linked with zlib at compile time. More...
 
LIBNUML_EXTERN int NUMLReader_hasBzip2 ()
 Predicate returning non-zero or zero depending on whether underlying libNUML is linked with bzip2 at compile time. More...
 
LIBNUML_EXTERN NUMLDocument_treadNUML (const char *filename)
 Reads an NUML document from the given file. More...
 
LIBNUML_EXTERN NUMLDocument_treadNUMLFromFile (const char *filename)
 Reads an NUML document from the given file. More...
 
LIBNUML_EXTERN NUMLDocument_treadNUMLFromString (const char *xml)
 Reads an NUML document from the given XML string. More...
 

Function Documentation

◆ isCriticalError()

static bool isCriticalError ( const unsigned int  errorId)
static

◆ NUMLReader_create()

LIBNUML_EXTERN NUMLReader_t * NUMLReader_create ( )

Creates a new NUMLReader and returns it.

◆ NUMLReader_free()

LIBNUML_EXTERN void NUMLReader_free ( NUMLReader_t sr)

Frees the given NUMLReader.

◆ NUMLReader_hasBzip2()

LIBNUML_EXTERN int NUMLReader_hasBzip2 ( )

Predicate returning non-zero or zero depending on whether underlying libNUML is linked with bzip2 at compile time.

Returns
non-zero if libNUML is linked with bzip2, zero otherwise.

◆ NUMLReader_hasZlib()

LIBNUML_EXTERN int NUMLReader_hasZlib ( )

Predicate returning non-zero or zero depending on whether underlying libNUML is linked with zlib at compile time.

Returns
non-zero if libNUML is linked with zlib, zero otherwise.

◆ NUMLReader_readNUML()

LIBNUML_EXTERN NUMLDocument_t * NUMLReader_readNUML ( NUMLReader_t sr,
const char *  filename 
)

Reads an NUML document from the given file.

If filename does not exist or is not an NUML file, an error will be logged. Errors can be identified by their unique ids, e.g.:

NUMLReader_t *sr;
NUMLDocument_t *d;

sr = NUMLReader_create();

d = NUMLReader_readNUML(reader, filename);

if (NUMLDocument_getNumErrors(d) > 0)
{
if (XMLError_getId(NUMLDocument_getError(d, 0)) == NUML_READ_ERROR_FILE_NOT_FOUND)
if (XMLError_getId(NUMLDocument_getError(d, 0)) == NUML_READ_ERROR_NOT_NUML)
}

Returns
a pointer to the NUMLDocument read.

◆ NUMLReader_readNUMLFromFile()

LIBNUML_EXTERN NUMLDocument_t * NUMLReader_readNUMLFromFile ( NUMLReader_t sr,
const char *  filename 
)

Reads an NUML document from the given file.

If filename does not exist or is not an NUML file, an error will be logged. Errors can be identified by their unique ids, e.g.:

NUMLReader_t *sr;
NUMLDocument_t *d;

sr = NUMLReader_create();

d = NUMLReader_readNUML(reader, filename);

if (NUMLDocument_getNumErrors(d) > 0)
{
if (XMLError_getId(NUMLDocument_getError(d, 0)) == NUML_READ_ERROR_FILE_NOT_FOUND)
if (XMLError_getId(NUMLDocument_getError(d, 0)) == NUML_READ_ERROR_NOT_NUML)
}

Returns
a pointer to the NUMLDocument read.

◆ NUMLReader_readNUMLFromString()

LIBNUML_EXTERN NUMLDocument_t * NUMLReader_readNUMLFromString ( NUMLReader_t sr,
const char *  xml 
)

Reads an NUML document from the given XML string.

If the string does not begin with XML declaration:

<?xml version='1.0' encoding='UTF-8'?>

it will be prepended.

This method will log a fatal error if the XML string is not NUML. See the method documentation for readNUML(filename) for example error checking code.

Returns
a pointer to the NUMLDocument read.

◆ readNUML()

LIBNUML_EXTERN NUMLDocument_t * readNUML ( const char *  filename)

Reads an NUML document from the given file.

Reads an NUML document from the given file filename.

If filename does not exist or is not an NUML file, an error will be logged. Errors can be identified by their unique ids, e.g.:

NUMLReader_t *sr;
NUMLDocument_t *d;

sr = NUMLReader_create();

d = NUMLReader_readNUML(reader, filename);

if (NUMLDocument_getNumErrors(d) > 0)
{
if (XMLError_getId(NUMLDocument_getError(d, 0)) == NUML_READ_ERROR_FILE_NOT_FOUND)
if (XMLError_getId(NUMLDocument_getError(d, 0)) == NUML_READ_ERROR_NOT_NUML)
}

If the filename ends with .gz, the file will be read as a gzip file. Similary, if the filename ends with .zip or .bz2, the file will be read as a zip or bzip2 file, respectively. Otherwise, the fill will be read as an uncompressed file. If the filename ends with .zip, only the first file in the archive will be read if the zip archive contains two or more files.

To read a gzip/zip file, underlying libNUML needs to be linked with zlib at compile time. Also, underlying libNUML needs to be linked with bzip2 to read a bzip2 file. File unreadable error will be logged if a compressed file name is given and underlying libNUML is not linked with the corresponding required library. NUMLReader_hasZlib() and NUMLReader_hasBzip2() can be used to check whether libNUML is linked with each library.

Returns
a pointer to the NUMLDocument read.

◆ readNUMLFromFile()

LIBNUML_EXTERN NUMLDocument_t * readNUMLFromFile ( const char *  filename)

Reads an NUML document from the given file.

If filename does not exist or is not an NUML file, an error will be logged. Errors can be identified by their unique ids, e.g.:

NUMLReader_t *sr;
NUMLDocument_t *d;

sr = NUMLReader_create();

d = NUMLReader_readNUML(reader, filename);

if (NUMLDocument_getNumErrors(d) > 0)
{
if (XMLError_getId(NUMLDocument_getError(d, 0)) == NUML_READ_ERROR_FILE_NOT_FOUND)
if (XMLError_getId(NUMLDocument_getError(d, 0)) == NUML_READ_ERROR_NOT_NUML)
}

If the filename ends with .gz, the file will be read as a gzip file. Similary, if the filename ends with .zip or .bz2, the file will be read as a zip or bzip2 file, respectively. Otherwise, the fill will be read as an uncompressed file. If the filename ends with .zip, only the first file in the archive will be read if the zip archive contains two or more files.

To read a gzip/zip file, underlying libNUML needs to be linked with zlib at compile time. Also, underlying libNUML needs to be linked with bzip2 to read a bzip2 file. File unreadable error will be logged if a compressed file name is given and underlying libNUML is not linked with the corresponding required library. NUMLReader_hasZlib() and NUMLReader_hasBzip2() can be used to check whether libNUML is linked with each library.

Returns
a pointer to the NUMLDocument read.

◆ readNUMLFromString()

LIBNUML_EXTERN NUMLDocument_t * readNUMLFromString ( const char *  xml)

Reads an NUML document from the given XML string.

Reads an NUML document from a string assumed to be in XML format.

If the string does not begin with XML declaration:

<?xml version='1.0' encoding='UTF-8'?>

it will be prepended.

This method will log a fatal error if the XML string is not NUML. See the method documentation for readNUML(filename) for example error checking code.

Returns
a pointer to the NUMLDocument read.