libpniio
Data Structures | Typedefs | Functions | Variables
XML utilities
Collaboration diagram for XML utilities:

Data Structures

struct  pni::io::nx::xml::attribute
 read and write attributes More...
 
class  pni::io::nx::xml::data_node
 node IO More...
 
struct  pni::io::nx::xml::write_no_data
 default data predicate More...
 
class  pni::io::nx::xml::dimensions
 reading and writing dimensions More...
 
struct  pni::io::nx::xml::field
 read and write field data More...
 
struct  pni::io::nx::xml::group
 read and write groups More...
 
struct  pni::io::nx::xml::io_node
 general IO objects More...
 
class  pni::io::nx::xml::link
 manages links in XML More...
 

Typedefs

typedef boost::mpl::map
< boost::mpl::pair
< pni::core::uint8,
pni::core::uint64 >
, boost::mpl::pair
< pni::core::uint16,
pni::core::uint64 >
, boost::mpl::pair
< pni::core::uint32,
pni::core::uint64 >
, boost::mpl::pair
< pni::core::uint64,
pni::core::uint64 >
, boost::mpl::pair
< pni::core::int8,
pni::core::int64 >
, boost::mpl::pair
< pni::core::int16,
pni::core::int64 >
, boost::mpl::pair
< pni::core::int32,
pni::core::int64 >
, boost::mpl::pair
< pni::core::int64,
pni::core::int64 >
, boost::mpl::pair
< pni::core::float32,
pni::core::float128 >
, boost::mpl::pair
< pni::core::float64,
pni::core::float128 >
, boost::mpl::pair
< pni::core::float128,
pni::core::float128 >
, boost::mpl::pair
< pni::core::complex32,
pni::core::complex128 >
, boost::mpl::pair
< pni::core::complex64,
pni::core::complex128 >
, boost::mpl::pair
< pni::core::complex128,
pni::core::complex128 > > 
pni::io::nx::xml::max_type_map
 maximum type maps More...
 
typedef std::pair< size_t, size_t > pni::io::nx::xml::index_value_type
 index-value type More...
 
using pni::io::nx::xml::node = boost::property_tree::ptree
 alias for ptree More...
 

Functions

template<typename ATYPE >
ATYPE pni::io::nx::xml::make_array (const node &data)
 generate an array More...
 
template<>
pni::core::array pni::io::nx::xml::make_array (const node &data)
 generate an array type erasure More...
 
bool pni::io::nx::xml::operator< (const index_value_type &lhs, const index_value_type &rhs)
 comparison operator for index_value_type More...
 
template<typename T , typename OTYPE >
void pni::io::nx::xml::write_object_data (OTYPE &o, node &n)
 write data from Nexus to XML More...
 
template<typename OTYPE >
void pni::io::nx::xml::write_object_data (OTYPE &p, node &n)
 write data from a Nexus object to XML More...
 
template<typename OTYPE , typename PTYPE >
void pni::io::nx::xml::append_attributes (const OTYPE &parent, node &p, PTYPE &write_predicate)
 append attributes from a nexus type to XML More...
 
template<typename GTYPE , typename FTYPE , typename ATYPE , typename LTYPE , typename PTYPE >
void pni::io::nx::xml::nexus_to_xml (nxobject< GTYPE, FTYPE, ATYPE, LTYPE > &p, node &n, PTYPE write_predicate)
 nexus to XML conversion More...
 
template<template< nximp_code > class OTYPE, nximp_code IMPID, typename PTYPE >
void pni::io::nx::xml::nexus_to_xml (OTYPE< IMPID > &o, node &n, PTYPE write_predicate)
 nexus to XML conversion More...
 
template<typename GTYPE , typename FTYPE , typename ATYPE , typename LTYPE >
void pni::io::nx::xml::nexus_to_xml (nxobject< GTYPE, FTYPE, ATYPE, LTYPE > &p, node &n)
 nexus to XML conversion More...
 
node pni::io::nx::xml::create_from_string (const pni::core::string &s)
 create xml node from string More...
 
node pni::io::nx::xml::create_from_file (const pni::core::string &s)
 create xml node from file More...
 
pni::core::string pni::io::nx::xml::attribute_path (const pni::core::string &name)
 create an attribute path More...
 
node pni::io::nx::xml::get_attribute (const node &parent, const pni::core::string &name)
 get attribute node More...
 
bool pni::io::nx::xml::has_attribute (const node &parent, const pni::core::string &name)
 check for attribute existence More...
 
pni::core::string pni::io::nx::xml::get_name (const node &n)
 get name of a node More...
 
std::ostream & pni::io::nx::xml::operator<< (std::ostream &o, const node &n)
 XML stream output. More...
 
template<typename T , typename OTYPE >
void pni::io::nx::xml::write_node_data (const OTYPE &object, const node &n)
 write data from buffer More...
 
template<typename OTYPE >
void pni::io::nx::xml::write_node_data (const OTYPE &object, const node &n)
 write node data More...
 
template<typename GTYPE , typename FTYPE , typename ATYPE , typename LTYPE , typename PTYPE >
void pni::io::nx::xml::xml_to_nexus (const node &t, const nxobject< GTYPE, FTYPE, ATYPE, LTYPE > &parent, PTYPE write_data)
 create objects from XML More...
 
template<typename GTYPE , typename FTYPE , typename ATYPE , typename LTYPE >
void pni::io::nx::xml::xml_to_nexus (const node &t, const nxobject< GTYPE, FTYPE, ATYPE, LTYPE > &parent)
 create objects from XML More...
 
template<template< pni::io::nx::nximp_code > class OTYPE, pni::io::nx::nximp_code IMPID, typename PTYPE >
void pni::io::nx::xml::xml_to_nexus (const node &t, const OTYPE< IMPID > &group, PTYPE write_data)
 create objects from XML More...
 
template<template< pni::io::nx::nximp_code > class OTYPE, pni::io::nx::nximp_code IMPID>
void pni::io::nx::xml::xml_to_nexus (const node &t, const OTYPE< IMPID > &group)
 create objects from XML More...
 

Variables

static const std::map
< pni::core::string, bool > 
pni::io::nx::xml::bool_string_map {"1",true}
 bool representation map More...
 

Detailed Description

Creating the structure of a Nexus file can be rather tedious when coded statically. Additionally such an approach is usually rather inflexible and thus should be avoided at all. libpniio provides utility functions to create Nexus objects using XML templates. Fortunately, Nexus comes with its own XML dialect called NXDL which already defines the XML vocabulary necessary to describie Nexus files with XML.

Using NXDL makes programs much more flexible and gives users the possibility to customize the layout of a Nexus file without rewriting code.

Under the hood the XML/NXDL facility provided here is based on BOOST::property_tree providing a non-validating XML parser. However, for our purpose validation is not really required.

Typedef Documentation

typedef std::pair<size_t,size_t> pni::io::nx::xml::index_value_type

This type describes an index value pair used in NXDL to describe a single dimension. The first component is the index of the particular dimensions while the second one denotes the number of elements along this dimension.

typedef boost::mpl::map< boost::mpl::pair<pni::core::uint8,pni::core::uint64>, boost::mpl::pair<pni::core::uint16,pni::core::uint64>, boost::mpl::pair<pni::core::uint32,pni::core::uint64>, boost::mpl::pair<pni::core::uint64,pni::core::uint64>, boost::mpl::pair<pni::core::int8,pni::core::int64>, boost::mpl::pair<pni::core::int16,pni::core::int64>, boost::mpl::pair<pni::core::int32,pni::core::int64>, boost::mpl::pair<pni::core::int64,pni::core::int64>, boost::mpl::pair<pni::core::float32,pni::core::float128>, boost::mpl::pair<pni::core::float64,pni::core::float128>, boost::mpl::pair<pni::core::float128,pni::core::float128>, boost::mpl::pair<pni::core::complex32,pni::core::complex128>, boost::mpl::pair<pni::core::complex64,pni::core::complex128>, boost::mpl::pair<pni::core::complex128,pni::core::complex128> > pni::io::nx::xml::max_type_map

This map defines the maximum type for every numeric type provided by pnicore. It is used when reading data from an attribute or node.

using pni::io::nx::xml::node = typedef boost::property_tree::ptree

This alias creates the new type name node which can be used within the xml namespace instead of boost::property_tree::ptree;

Function Documentation

template<typename OTYPE , typename PTYPE >
void pni::io::nx::xml::append_attributes ( const OTYPE &  parent,
node &  p,
PTYPE &  write_predicate 
)

Reads all attribtues from a Nexus node and append them to an XML node. There are several attribute which are omitted as they are part of the XML tag

  • NX_class whose content is written in the type attribute
  • units which goes to the units attribute
  • long_name which goes to the long_name tag attribute

Whether or not data form the Nexus object is written to the XML output depends on the write_predicate. This is a callable which takes the Nexus object as its only argument and returns true if the data should be written or false otherwise.

Template Parameters
OTYPENexus object type
PTYPEwrite predicate type
Parameters
parentthe object with the attributes
pXML node to which attribute tags should be appended
write_predicatefunction object determinig when to write data to the XML output
pni::core::string pni::io::nx::xml::attribute_path ( const pni::core::string &  name)

This function is intended for internal use only. It creates a valid attribute path from an attribute name.

Parameters
namethe name of the attribute
Returns
a valid property tree attribute path
node pni::io::nx::xml::create_from_file ( const pni::core::string &  s)

Reads XML data from a file and returns an XML node refering to the root element of the XML tree.

Exceptions
pni::io::parser_errorin case of parsing issues
file_errorin case of problems opening the file
Parameters
sname of the file
Returns
node instance
node pni::io::nx::xml::create_from_string ( const pni::core::string &  s)

Parses a string provided by the user and returns an XML node from it.

Exceptions
parser_errorin case of parsing problems
Parameters
sstring from which to read the data
Returns
node instance
node pni::io::nx::xml::get_attribute ( const node &  parent,
const pni::core::string &  name 
)

Returns an attribute node from its parent node.

Exceptions
key_errorif the attribute does not exist
parser_errorin case of any other error
Parameters
parentthe node from which to retrieve the attribute
namethe name of the attribute
Returns
node representing the attribute
string pni::io::nx::xml::get_name ( const node &  n)

Return the name of a node as determined by the content of its name attribute. This is a convenience function. If the node does not have a name attribute an empty string is returned.

Parameters
nnode with name attribute
Returns
content of the name attribute of a tag
bool pni::io::nx::xml::has_attribute ( const node &  parent,
const pni::core::string &  name 
)

Returns true if the node parent has a an attribute name attached to it. Otherwise false is returned.

Parameters
parentreference to the parent node
namethe attributes name
Returns
true if the attribute exists, false otherwise
template<typename ATYPE >
pni::core::array pni::io::nx::xml::make_array ( const node &  data)

generate an array type erasure

This function template generates an instance of an mdarray from a data node and stores the data in this array. The data type is determined by the user and must match the data type stored in the array.

Parameters
datathe XML node holding the daata
Returns
instance of ATYPE with the data
template<>
pni::core::array pni::io::nx::xml::make_array ( const node &  data)

This specialization of the make_array function template returns an array type erasure. This function is particularly useful in situations where we only need to transfer data and the data type is of no further important.

Parameters
datathe XML node with data
Returns
instance of array with the data

generate an array type erasure

This function template generates an instance of an mdarray from a data node and stores the data in this array. The data type is determined by the user and must match the data type stored in the array.

Parameters
datathe XML node holding the daata
Returns
instance of ATYPE with the data
template<typename GTYPE , typename FTYPE , typename ATYPE , typename LTYPE , typename PTYPE >
void pni::io::nx::xml::nexus_to_xml ( nxobject< GTYPE, FTYPE, ATYPE, LTYPE > &  p,
node &  n,
PTYPE  write_predicate 
)

Converts the structure of a Nexus tree stored below p into an XML tree below n. The Nexus parent object p is provided as an instance of nxobject. Which data from the Nexus file goes to the XML output is determined by the write_predicate, a functor taking a single Nexus object as its argument and returns true if the data should be written and false otherwise.

Template Parameters
GTYPENexus group type
FTYPENexus field type
ATYPENexus attribute type
LTYPElink type
PTYPEwrite predicate type
Parameters
pparent object
nXML node
write_datafunctor determining which data to write
template<template< nximp_code > class OTYPE, nximp_code IMPID, typename PTYPE >
void pni::io::nx::xml::nexus_to_xml ( OTYPE< IMPID > &  o,
node &  n,
PTYPE  write_predicate 
)

Converts the content of Nexus object to XML. Here the Nexus object is is passed as an instance of nxattribute, nxgroup, or nxfield. The write_predicate functor determines which data is written to the XML output.

Template Parameters
OTYPENexus object type
IMPIDimplementation ID
PTYPEpredicate type
Parameters
oparent object
nXML node
write_predicatethe functor determining which data to write
template<typename GTYPE , typename FTYPE , typename ATYPE , typename LTYPE >
void pni::io::nx::xml::nexus_to_xml ( nxobject< GTYPE, FTYPE, ATYPE, LTYPE > &  p,
node &  n 
)

Converts the structure of a Nexus tree stored below p into an XML tree below n. The Nexus parent object p is provided as an instance of nxobject. This template function takes no write predicate and thus no data from the Nexus file is written to the XML output.

Template Parameters
GTYPENexus group type
FTYPENexus field type
ATYPENexus attribute type
LTYPElink type
Parameters
pparent object
nXML node
bool pni::io::nx::xml::operator< ( const index_value_type &  lhs,
const index_value_type &  rhs 
)

Operator required to sort containers using index_value_type as their element type. index-value pairs are ordered by their dimension index. This operator returns true if the index component of the LHS is smaller than the index component of the RHS.

Parameters
lhsleft handside of the operator
rhsright handside of the operator
Returns
true if index of lhs is small than that of rhs, false otherwise
std::ostream & pni::io::nx::xml::operator<< ( std::ostream &  o,
const node &  n 
)

Write property tree structure as XML to an output stream.

Parameters
oreference output stream
nnode to write to the output stream
Returns
modified output stream
template<typename T , typename OTYPE >
void pni::io::nx::xml::write_node_data ( const OTYPE &  object,
const node &  n 
)

Read data from the CDATA section of an XML tag and store it in an NeXus object. The data type used for reading the data is determined by the user supplied template parameter.

Exceptions
type_errorif the data type cannot be read or handled by the write function
parser_errorif the data could not be read from the CDATA section of the tag
invalid_object_errorif the target object is not valid
io_errorif writing the data fails
size_mismatch_errorif the amount of data read from CDATA does not match the size of the NeXus object
object_errorin case of any other error
Template Parameters
Tdata type to use for writing
OTYPEobject type to which to write the data
Parameters
objectthe object instance to which to write the data
nthe node holding the data
template<typename OTYPE >
void pni::io::nx::xml::write_node_data ( const OTYPE &  object,
const node &  n 
)

Write the data stored in an XML tag to a NeXus object. This is a utilty function which calles an appropriate instantiation of the write_node_data function template for every particular data type.

Exceptions
type_errorif the data type cannot be read or handled by the write function
parser_errorif the data could not be read from the CDATA section of the tag
invalid_object_errorif the target object is not valid
io_errorif writing the data fails
size_mismatch_errorif the amount of data read from CDATA does not match the size of the NeXus object
object_errorin case of any other error
Template Parameters
OTYPEobject type to which to write the data
Parameters
objectthe object instance to which to write the data
nthe node holding the data
template<typename T , typename OTYPE >
void pni::io::nx::xml::write_object_data ( OTYPE &  o,
node &  n 
)

This function template writes data from a Nexus object to the CDATA section of an XML tag.

Template Parameters
Tdata type to use
OTYPENexus object type
Parameters
oNexus object from which to read the data
nXML tag where to store the data
template<typename OTYPE >
void pni::io::nx::xml::write_object_data ( OTYPE &  p,
node &  n 
)

Read data from a Nexus object and store it to the CDATA section of an XML tag. This function template only does type dispatching.

Template Parameters
OTYPENexus object type
Parameters
pthe Nexus object from which to read the data
nthe XML node where to store the data
template<typename GTYPE , typename FTYPE , typename ATYPE , typename LTYPE , typename PTYPE >
void pni::io::nx::xml::xml_to_nexus ( const node &  t,
const nxobject< GTYPE, FTYPE, ATYPE, LTYPE > &  parent,
PTYPE  write_data 
)

Recursively creates the objects as described in the XML file below parent. The parent is passed as a reference to an instance of nxobject.

Exceptions
parser_errorin case of XML parsing problems
invalid_object_errorif the parent object is not valid
io_errorif data or metadata write failed
type_errorif a data type is involved that cannot be handled
object_errorin case of any other error
Template Parameters
GTYPEgroup type
FTYPEfield type
ATYPEattribute type
LTYPElink type
Parameters
tptree instance with the XML data
parentinstance of nxobject
write_datapredicate function determining when data should be written
template<typename GTYPE , typename FTYPE , typename ATYPE , typename LTYPE >
void pni::io::nx::xml::xml_to_nexus ( const node &  t,
const nxobject< GTYPE, FTYPE, ATYPE, LTYPE > &  parent 
)

A version of xml_to_nexus where no data is written to the file at all. The parent is passed as a reference to nxobject.

Exceptions
parser_errorin case of XML parsing problems
invalid_object_errorif the parent object is not valid
io_errorif data or metadata write failed
type_errorif a data type is involved that cannot be handled
object_errorin case of any other error
Template Parameters
GTYPEgroup type
FTYPEfield type
ATYPEattribute type
LTYPElink type
Parameters
tptree instance with the XML data
parentinstance of nxobject
template<template< pni::io::nx::nximp_code > class OTYPE, pni::io::nx::nximp_code IMPID, typename PTYPE >
void pni::io::nx::xml::xml_to_nexus ( const node &  t,
const OTYPE< IMPID > &  group,
PTYPE  write_data 
)

An overload of the xml_to_nexus function template where the parent is passed as an instance of nxgroup.

Exceptions
parser_errorin case of XML parsing problems
invalid_object_errorif the parent object is not valid
io_errorif data or metadata write failed
type_errorif a data type is involved that cannot be handled
object_errorin case of any other error
Template Parameters
OTYPEparent template
IMPIDimplementation ID
PTYPEdata writer predicate
Parameters
tXML node from which to construct the Nexus structure
groupthe parent group below which the structure should be generated
write_datapredicate to determine whether or tag data should be written to the file
template<template< pni::io::nx::nximp_code > class OTYPE, pni::io::nx::nximp_code IMPID>
void pni::io::nx::xml::xml_to_nexus ( const node &  t,
const OTYPE< IMPID > &  group 
)

An overload of the xml_to_nexus function template where the parent is passed as an instance of nxgroup.

Exceptions
parser_errorin case of XML parsing problems
invalid_object_errorif the parent object is not valid
io_errorif data or metadata write failed
type_errorif a data type is involved that cannot be handled
object_errorin case of any other error
Template Parameters
OTYPEparent template
IMPIDimplementation ID
PTYPEdata writer predicate
Parameters
tXML node from which to construct the Nexus structure
groupthe parent group below which the structure should be generated
write_datapredicate to determine whether or tag data should be written to the file

Variable Documentation

const std::map<pni::core::string,bool> pni::io::nx::xml::bool_string_map {"1",true}
static

A static map with all valid representations of boolean values.