include/lwpr_xml.h File Reference

Prototypes for XML related LWPR subroutines. More...

#include <stdio.h>

Go to the source code of this file.

Data Structures

struct  LWPR_ParserData
 Data structure used for parsing an LWPR model from an XML file. More...

Functions

int lwpr_write_xml (const LWPR_Model *model, const char *filename)
 Writes an LWPR model to an XML file.
void lwpr_write_xml_fp (const LWPR_Model *model, FILE *fp)
 Writes an LWPR model to an XML file.
int lwpr_read_xml (LWPR_Model *model, const char *filename, int *numWarnings)
 Parse an LWPR model from an XML file.
void lwpr_xml_write_matrix (FILE *fp, int level, const char *name, int M, int Ms, int N, const double *val)
 Writes a matrix as an XML tag into a file.
void lwpr_xml_write_vector (FILE *fp, int level, const char *name, int N, const double *val)
 Writes a vector as an XML tag into a file.
void lwpr_xml_write_int (FILE *fp, int level, const char *name, int val)
 Writes an interger as an XML tag into a file.
void lwpr_xml_write_scalar (FILE *fp, int level, const char *name, double val)
 Writes a scalar (double) as an XML tag into a file.
void lwpr_xml_write_rf (FILE *fp, const LWPR_ReceptiveField *RF)
 Writes a receptive field structure as XML tags into a file.
int lwpr_xml_parse_scalar (const char **atts, const char **fieldName)
 Checks whether an XML tag describes a valid scalar (int or double).
int lwpr_xml_parse_vector (const char **atts, const char **fieldName, int *N)
 Checks whether an XML tag describes a valid vector.
int lwpr_xml_parse_matrix (const char **atts, const char **fieldName, int *M, int *N)
 Checks whether an XML tag describes a valid matrix.
void lwpr_xml_error (LWPR_ParserData *ud, const char *msg)
 Auxiliary routine to report a parsing error.
void lwpr_xml_dim_error (LWPR_ParserData *ud, const char *fieldname, int wishM, int wishN)
 Auxiliary routine to report a "bad dimensionality" parsing error.
void lwpr_xml_report_unknown (LWPR_ParserData *ud, const char *fieldname)
 Auxiliary routine to report an "unknown element" warning.
void lwpr_xml_start_element (void *userData, const char *name, const char **atts)
 Callback for EXPAT parser, start of a new element.
void lwpr_xml_end_element (void *userData, const char *name)
 Callback for EXPAT parser, element finished.
void lwpr_xml_handle_data (void *userData, const char *s, int len)
 Callback for EXPAT parser, for data between enclosing tags.
int lwpr_xml_read_file_into_buffer (const char *filename, char **buffer)
 Reads a file into memory.

Detailed Description

Prototypes for XML related LWPR subroutines.

This header file describes routines for writing LWPR models to XML files, and parsing LWPR models from XML files, if EXPAT is available.

An XML document type definition (DTD) is provided in the file "include/lwpr_xml.dtd".


Function Documentation

void lwpr_xml_dim_error ( LWPR_ParserData ud,
const char *  fieldname,
int  wishM,
int  wishN 
)

Auxiliary routine to report a "bad dimensionality" parsing error.

Parameters:
[in] ud Pointer to parser data structure (including LWPR model etc.)
[in] fieldname Name of variable where error occured
[in] wishM Number of desired rows, or 1 in case of scalars / vectors
[in] wishN Number of desired columns, or elements in case of vectors
void lwpr_xml_error ( LWPR_ParserData ud,
const char *  msg 
)

Auxiliary routine to report a parsing error.

Parameters:
[in] ud Pointer to parser data structure (including LWPR model etc.)
[in] msg Error message
int lwpr_xml_parse_matrix ( const char **  atts,
const char **  fieldName,
int *  M,
int *  N 
)

Checks whether an XML tag describes a valid matrix.

Parameters:
[in] atts Array of XML attributes
[out] fieldName The name of the matrix, or NULL if unsuccessful
[out] M Number of rows of the matrix
[out] N Number of columns of the matrix
Returns:
  • 1 in case of success
  • 0 in case of failure
int lwpr_xml_parse_scalar ( const char **  atts,
const char **  fieldName 
)

Checks whether an XML tag describes a valid scalar (int or double).

Parameters:
[in] atts Array of XML attributes
[out] fieldName The name of the variable, or NULL if unsuccessful
Returns:
  • 1 in case of success
  • 0 in case of failure
int lwpr_xml_parse_vector ( const char **  atts,
const char **  fieldName,
int *  N 
)

Checks whether an XML tag describes a valid vector.

Parameters:
[in] atts Array of XML attributes
[out] fieldName The name of the vector, or NULL if unsuccessful
[out] N Number of elements of the vector
Returns:
  • 1 in case of success
  • 0 in case of failure
int lwpr_xml_read_file_into_buffer ( const char *  filename,
char **  buffer 
)

Reads a file into memory.

Parameters:
[in] filename Name of the XML file
[out] buffer On return, the pointer to the contents of the file
Returns:
The number of bytes read from the file, or -1 in case of failure.

Note that the allocated memory has to be disposed using LWPR_FREE() afterwards.

void lwpr_xml_report_unknown ( LWPR_ParserData ud,
const char *  fieldname 
)

Auxiliary routine to report an "unknown element" warning.

Parameters:
[in] ud Pointer to parser data structure (including LWPR model etc.)
[in] fieldname Name of variable
void lwpr_xml_write_int ( FILE *  fp,
int  level,
const char *  name,
int  val 
)

Writes an interger as an XML tag into a file.

Parameters:
[in] fp File descriptor
[in] level Indicates global (0), model (1), submodel (2) or receptive field (3)
[in] name Name of the variable
[in] val Integer value
void lwpr_xml_write_matrix ( FILE *  fp,
int  level,
const char *  name,
int  M,
int  Ms,
int  N,
const double *  val 
)

Writes a matrix as an XML tag into a file.

Parameters:
[in] fp File descriptor
[in] level Indicates global (0), model (1), submodel (2) or receptive field (3)
[in] name Name of the matrix
[in] M Number of rows
[in] Ms Stride parameter (offset between adjacent columns)
[in] N Number of columns
[in] val Pointer to the elements of the matrix
void lwpr_xml_write_rf ( FILE *  fp,
const LWPR_ReceptiveField RF 
)

Writes a receptive field structure as XML tags into a file.

Parameters:
[in] fp File descriptor
[in] RF Pointer to a receptive field structure
void lwpr_xml_write_scalar ( FILE *  fp,
int  level,
const char *  name,
double  val 
)

Writes a scalar (double) as an XML tag into a file.

Parameters:
[in] fp File descriptor
[in] level Indicates global (0), model (1), submodel (2) or receptive field (3)
[in] name Name of the variable
[in] val Scalar value
void lwpr_xml_write_vector ( FILE *  fp,
int  level,
const char *  name,
int  N,
const double *  val 
)

Writes a vector as an XML tag into a file.

Parameters:
[in] fp File descriptor
[in] level Indicates global (0), model (1), submodel (2) or receptive field (3)
[in] name Name of the vector
[in] N Number of elements
[in] val Pointer to the elements of the matrix
Generated on Thu Feb 9 08:18:35 2012 for LWPR Library by  doxygen 1.6.3