libpniio
Public Types | Public Member Functions | Private Member Functions | Private Attributes
pni::io::nx::flat_group< GTYPE > Class Template Reference

flat group adapter More...

#include <flat_group.hpp>

Collaboration diagram for pni::io::nx::flat_group< GTYPE >:
Collaboration graph
[legend]

Public Types

typedef GTYPE group_type
 the group type More...
 
typedef nxobject_trait
< nximp_code_map< group_type >
::icode >::object_type 
value_type
 nxobject is the value type of the flat_group container More...
 
typedef std::vector< value_typecontainer_type
 the internal container type More...
 
typedef container_type::iterator iterator
 the iterator type More...
 
typedef
container_type::const_iterator 
const_iterator
 the constant interator type More...
 

Public Member Functions

 flat_group (const group_type &parent)
 constructor More...
 
value_type operator[] (size_t index) const noexcept
 get element More...
 
value_typeoperator[] (size_t index) noexcept
 get element reference More...
 
size_t size () const noexcept
 get size More...
 
iterator begin () noexcept
 get iterator to first More...
 
iterator end () noexcept
 get iterator to last+1 More...
 
const_iterator begin () const noexcept
 get iterator to first More...
 
const_iterator end () const noexcept
 get iterator to last+1 More...
 

Private Member Functions

void append_children (const group_type &parent)
 append children to container More...
 

Private Attributes

container_type _container
 internal container holding the objects More...
 

Detailed Description

template<typename GTYPE>
class pni::io::nx::flat_group< GTYPE >

The flat_group adapter provides a recursive view on a group and all its children. It is typically constructed with the utility function make_flat and can be used to iterate recursively over all child nodes below a group.

A typical example would be to list the path of every object stored below a particular group

auto group = get_object(file.root(),"/:NXentry");
auto flat = make_flat(group);
for(auto child: flat)
std::cout<<get_path(child)<<std::endl;

Providing an STL compliant container interface it can be used to do all kind of search operations. For instance consider the case where we would like to find all instances of NXdetector in an entry:

std::vector<nxgroup> detector;
auto entry = get_object(file.root(),"/:NXentry");
for(auto e: entry)
if(is_class(e,"NXdetector")) detector.push_back(e);
Template Parameters
GTYPEgroup type

Member Typedef Documentation

template<typename GTYPE >
typedef container_type::const_iterator pni::io::nx::flat_group< GTYPE >::const_iterator
template<typename GTYPE >
typedef std::vector<value_type> pni::io::nx::flat_group< GTYPE >::container_type
template<typename GTYPE >
typedef GTYPE pni::io::nx::flat_group< GTYPE >::group_type
template<typename GTYPE >
typedef container_type::iterator pni::io::nx::flat_group< GTYPE >::iterator
template<typename GTYPE >
typedef nxobject_trait<nximp_code_map<group_type>::icode>::object_type pni::io::nx::flat_group< GTYPE >::value_type

Constructor & Destructor Documentation

template<typename GTYPE >
pni::io::nx::flat_group< GTYPE >::flat_group ( const group_type parent)
inlineexplicit
Exceptions
invalid_object_errorif parent is not valid
type_errorif group conversion fails
object_errorin case of any other error
Parameters
parentthe parent group from which all elements should be gahtered

Member Function Documentation

template<typename GTYPE >
void pni::io::nx::flat_group< GTYPE >::append_children ( const group_type parent)
inlineprivate

Function appending all children of a parent to the internal container. If a child is a group instance this function is called recursively.

Exceptions
invalid_object_errorif parent is not valid
type_errorif group conversion fails
object_errorin case of any other error
Parameters
parentthe parent group whose children are appended
template<typename GTYPE >
iterator pni::io::nx::flat_group< GTYPE >::begin ( )
inlinenoexcept

Return a non const iterator to the first element in the group

Returns
interator to first element
template<typename GTYPE >
const_iterator pni::io::nx::flat_group< GTYPE >::begin ( ) const
inlinenoexcept

Return a const iterator to the first element in the group

Returns
const interator to first element
template<typename GTYPE >
iterator pni::io::nx::flat_group< GTYPE >::end ( )
inlinenoexcept

Return a non const iterator to the last+1 element in the group.

Returns
iterator to the last+1 element
template<typename GTYPE >
const_iterator pni::io::nx::flat_group< GTYPE >::end ( ) const
inlinenoexcept

Return a const iterator to the last+1 element in the group.

Returns
const iterator to the last+1 element
template<typename GTYPE >
value_type pni::io::nx::flat_group< GTYPE >::operator[] ( size_t  index) const
inlinenoexcept

Return the element with index from the group.

Parameters
indexthe index of the child in the recursive group
Returns
copy of the child stored at index
template<typename GTYPE >
value_type& pni::io::nx::flat_group< GTYPE >::operator[] ( size_t  index)
inlinenoexcept

Return a reference to the element addressed by index in the recursive group.

Parameters
indexthe index of the child
Returns
reference to the child
template<typename GTYPE >
size_t pni::io::nx::flat_group< GTYPE >::size ( ) const
inlinenoexcept

Return the total number of elements attached (recursively) below this group.

Returns
number of children (direct or indirect)

Field Documentation

template<typename GTYPE >
container_type pni::io::nx::flat_group< GTYPE >::_container
private

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