TECA
The Toolkit for Extreme Climate Analysis
teca_variant_array Class Referenceabstract

A type erasure for array based data. More...

#include <teca_variant_array.h>

Inheritance diagram for teca_variant_array:
[legend]
Collaboration diagram for teca_variant_array:
[legend]

Public Types

using allocator = hamr::buffer_allocator
 allocator types More...
 

Public Member Functions

 teca_variant_array (const teca_variant_array &other)=delete
 
 teca_variant_array (teca_variant_array &&other)=delete
 
teca_variant_arrayoperator= (teca_variant_array &other)=delete
 
teca_variant_arrayoperator= (teca_variant_array &&other)=delete
 
p_teca_variant_array new_instance () const
 
p_teca_variant_array new_instance (size_t n) const
 
virtual p_teca_variant_array new_instance (allocator alloc) const =0
 
virtual p_teca_variant_array new_instance (size_t n, allocator alloc) const =0
 
virtual p_teca_variant_array new_copy (allocator alloc) const =0
 
p_teca_variant_array new_copy () const
 
virtual p_teca_variant_array new_copy (size_t src_start, size_t n_elem, allocator alloc) const =0
 
p_teca_variant_array new_copy (size_t src_start, size_t n_elem) const
 
virtual int set_allocator (allocator alloc)=0
 
virtual std::string get_class_name () const =0
 return the name of the class in a human readable form More...
 
virtual void initialize ()=0
 initialize the elements using the default constructor More...
 
virtual unsigned long size () const noexcept=0
 get the number of elements in the array More...
 
virtual void resize (unsigned long i)=0
 resize. allocates new storage and copies in existing values More...
 
virtual void reserve (unsigned long i)=0
 
virtual void clear () noexcept=0
 free all the internal data More...
 
virtual void swap (const p_teca_variant_array &other)=0
 
virtual bool equal (const const_p_teca_variant_array &other) const =0
 compare the two arrays element wize for equality More...
 
virtual int to_stream (teca_binary_stream &s) const =0
 serrialize to the binary stream in the internal format More...
 
virtual int from_stream (teca_binary_stream &s)=0
 derrialize from the binary stream More...
 
virtual int to_stream (std::ostream &s) const =0
 serrialize to the stream in a human readable format More...
 
virtual int from_stream (std::ostream &s)=0
 derrialize from the human readable stream More...
 
virtual unsigned int type_code () const noexcept=0
 a code for the contained data type used for serialization More...
 
virtual int host_accessible () const noexcept=0
 
virtual int cuda_accessible () const noexcept=0
 
virtual void synchronize () const =0
 synchronize on the associated stream More...
 
get

Copy the contest of this array to the passed instance. The desitination must be large enough to hold the results. These calls could throw std::bad_cast if the passed in type is not castable to the internal type.

virtual void get (const p_teca_variant_array &dest) const =0
 
virtual void get (size_t src_start, const p_teca_variant_array &dest, size_t dest_start, size_t n_elem) const =0
 
template<typename T >
void get (unsigned long i, T &val) const
 get a single value More...
 
template<typename T >
get (unsigned long i) const
 get a single value More...
 
template<typename T >
void get (std::vector< T > &vals) const
 get the contents into the passed vector. The vector is resized as needed. More...
 
template<typename T >
void get (size_t src_start, T *dest, size_t dest_start, size_t n_elem) const
 get a subset of the contents into the passed in array. More...
 
set

Assign values to this array form another. This array must already be large enough to hold the result. If automatic resizing is desired use copy instead. These calls could throw std::bad_cast if the passed in type is not castable to the internal type.

virtual void set (const const_p_teca_variant_array &src)=0
 
virtual void set (const p_teca_variant_array &src)
 Set from the other array. More...
 
virtual void set (size_t dest_start, const const_p_teca_variant_array &src, size_t src_start, size_t n_elem)=0
 
virtual void set (size_t dest_start, const p_teca_variant_array &src, size_t src_start, size_t n_elem)
 
template<typename T >
void set (unsigned long i, const T &val)
 set a single value More...
 
template<typename T >
void set (const std::vector< T > &src)
 set the contents from a vector of values. this array is not resized. More...
 
template<typename T >
void set (size_t dest_start, const T *src, size_t src_start, size_t n_elem)
 set a subset of the array from a passed array. this array is not resized. More...
 
assign

assign the contents of the passed array to this array. This array will be resized to hold the results. These calls could throw std::bad_cast if the passed in type is not castable to the internal type.

virtual void assign (const const_p_teca_variant_array &src)=0
 
virtual void assign (const p_teca_variant_array &src)
 assign the contents from the other array. More...
 
virtual void assign (const const_p_teca_variant_array &src, size_t src_start, size_t n_elem)=0
 assign a subset of the other array More...
 
virtual void assign (const p_teca_variant_array &src, size_t src_start, size_t n_elem)
 assign a subset of the other array More...
 
template<typename T >
void assign (const std::vector< T > &src)
 assign the contents from a vector of values. this array is resized as needed. More...
 
template<typename T >
void assign (const T *src, size_t src_start, size_t n_elem)
 assign the contents from a passed array. this array is resized as needed. More...
 
virtual void copy (const const_p_teca_variant_array &src)
 copy the contents from the other array. More...
 
virtual void copy (const p_teca_variant_array &src)
 copy the contents from the other array. More...
 
void copy (const const_p_teca_variant_array &src, size_t src_start, size_t n_elem)
 copy a subset of the other array More...
 
append

Append data at the back of the array. These calls could throw std::bad_cast if the passed in type is not castable to the internal type.

virtual void append (const const_p_teca_variant_array &src)=0
 
virtual void append (const p_teca_variant_array &src)
 append the passed array. More...
 
virtual void append (const const_p_teca_variant_array &src, size_t src_start, size_t n_elem)=0
 append a subset of the passed array More...
 
virtual void append (const p_teca_variant_array &src, size_t src_start, size_t n_elem)
 append a subset of the passed array More...
 
template<typename T >
void append (const T &val)
 append a single value. this array is extended as needed. More...
 
template<typename T >
void append (const std::vector< T > &src)
 
template<typename T >
void append (const T *src, size_t src_start, size_t n_elem)
 

Detailed Description

A type erasure for array based data.

The variant array supports: set, get, assign, and append. The elements of the array can be stored on different accelerator devices using different technologies and accessed seamless from other accelerator devices and technologies.

Use the type erasure (this class) to implement collections of arrays and public API. Use the concrete implementation (teca_variant_array_impl) for direct access to the typed data.

See VARIANT_ARRAY_DISPATCH and NESTED_VARIANT_ARRAY_DISPATCH for details on how to apply type specific code to an instance of teca_variant_array.

Member Typedef Documentation

◆ allocator

using teca_variant_array::allocator = hamr::buffer_allocator

allocator types

Member Function Documentation

◆ append() [1/7]

virtual void teca_variant_array::append ( const const_p_teca_variant_array src)
pure virtual

append the passed array.

Implemented in teca_variant_array_impl< T >.

◆ append() [2/7]

virtual void teca_variant_array::append ( const const_p_teca_variant_array src,
size_t  src_start,
size_t  n_elem 
)
pure virtual

append a subset of the passed array

Implemented in teca_variant_array_impl< T >.

◆ append() [3/7]

virtual void teca_variant_array::append ( const p_teca_variant_array src)
inlinevirtual

append the passed array.

◆ append() [4/7]

virtual void teca_variant_array::append ( const p_teca_variant_array src,
size_t  src_start,
size_t  n_elem 
)
inlinevirtual

append a subset of the passed array

◆ append() [5/7]

template<typename T >
void teca_variant_array::append ( const std::vector< T > &  src)

Append the contents from a vector of values. this array is extended as needed.

◆ append() [6/7]

template<typename T >
void teca_variant_array::append ( const T &  val)

append a single value. this array is extended as needed.

◆ append() [7/7]

template<typename T >
void teca_variant_array::append ( const T *  src,
size_t  src_start,
size_t  n_elem 
)

Append the contents from a passed array. this array is extended as needed.

◆ assign() [1/6]

virtual void teca_variant_array::assign ( const const_p_teca_variant_array src)
pure virtual

assign the contents from the other array.

Implemented in teca_variant_array_impl< T >.

◆ assign() [2/6]

virtual void teca_variant_array::assign ( const const_p_teca_variant_array src,
size_t  src_start,
size_t  n_elem 
)
pure virtual

assign a subset of the other array

Implemented in teca_variant_array_impl< T >.

◆ assign() [3/6]

virtual void teca_variant_array::assign ( const p_teca_variant_array src)
inlinevirtual

assign the contents from the other array.

◆ assign() [4/6]

virtual void teca_variant_array::assign ( const p_teca_variant_array src,
size_t  src_start,
size_t  n_elem 
)
inlinevirtual

assign a subset of the other array

◆ assign() [5/6]

template<typename T >
void teca_variant_array::assign ( const std::vector< T > &  src)

assign the contents from a vector of values. this array is resized as needed.

◆ assign() [6/6]

template<typename T >
void teca_variant_array::assign ( const T *  src,
size_t  src_start,
size_t  n_elem 
)

assign the contents from a passed array. this array is resized as needed.

◆ clear()

virtual void teca_variant_array::clear ( )
pure virtualnoexcept

free all the internal data

Implemented in teca_variant_array_impl< T >.

◆ copy() [1/3]

virtual void teca_variant_array::copy ( const const_p_teca_variant_array src)
inlinevirtual

copy the contents from the other array.

◆ copy() [2/3]

void teca_variant_array::copy ( const const_p_teca_variant_array src,
size_t  src_start,
size_t  n_elem 
)
inline

copy a subset of the other array

◆ copy() [3/3]

virtual void teca_variant_array::copy ( const p_teca_variant_array src)
inlinevirtual

copy the contents from the other array.

◆ cuda_accessible()

virtual int teca_variant_array::cuda_accessible ( ) const
pure virtualnoexcept
Returns
true if the contents are accesisble from CUDA

Implemented in teca_variant_array_impl< T >.

◆ equal()

virtual bool teca_variant_array::equal ( const const_p_teca_variant_array other) const
pure virtual

compare the two arrays element wize for equality

Implemented in teca_variant_array_impl< T >.

◆ from_stream() [1/2]

virtual int teca_variant_array::from_stream ( std::ostream &  s)
pure virtual

derrialize from the human readable stream

Implemented in teca_variant_array_impl< T >.

◆ from_stream() [2/2]

virtual int teca_variant_array::from_stream ( teca_binary_stream s)
pure virtual

derrialize from the binary stream

Implemented in teca_variant_array_impl< T >.

◆ get() [1/6]

virtual void teca_variant_array::get ( const p_teca_variant_array dest) const
pure virtual

get the contents into the other array.

Implemented in teca_variant_array_impl< T >.

◆ get() [2/6]

virtual void teca_variant_array::get ( size_t  src_start,
const p_teca_variant_array dest,
size_t  dest_start,
size_t  n_elem 
) const
pure virtual

get a subset of the contents into a subset of the other array

Parameters
[in]dest_startthe first location to assign to
[in]srcthe array to copy values from
[in]src_startthe first location to copy from
[in]n_elemthe number of elements to copy

Implemented in teca_variant_array_impl< T >.

◆ get() [3/6]

template<typename T >
void teca_variant_array::get ( size_t  src_start,
T *  dest,
size_t  dest_start,
size_t  n_elem 
) const

get a subset of the contents into the passed in array.

◆ get() [4/6]

template<typename T >
void teca_variant_array::get ( std::vector< T > &  vals) const

get the contents into the passed vector. The vector is resized as needed.

◆ get() [5/6]

template<typename T >
T teca_variant_array::get ( unsigned long  i) const

get a single value

◆ get() [6/6]

template<typename T >
void teca_variant_array::get ( unsigned long  i,
T &  val 
) const

get a single value

◆ get_class_name()

virtual std::string teca_variant_array::get_class_name ( ) const
pure virtual

return the name of the class in a human readable form

Implemented in teca_variant_array_impl< T >.

◆ host_accessible()

virtual int teca_variant_array::host_accessible ( ) const
pure virtualnoexcept
Returns
true if the contents are accesisble from the CPU

Implemented in teca_variant_array_impl< T >.

◆ initialize()

virtual void teca_variant_array::initialize ( )
pure virtual

initialize the elements using the default constructor

Implemented in teca_variant_array_impl< T >.

◆ new_copy() [1/4]

p_teca_variant_array teca_variant_array::new_copy ( ) const
inline

return a newly allocated object, initialized copy from this. The default allocator will be used.

◆ new_copy() [2/4]

virtual p_teca_variant_array teca_variant_array::new_copy ( allocator  alloc) const
pure virtual

return a newly allocated object, initialized copy from this.

Parameters
[in]allocselects the allocator to use (See ::allocator)

Implemented in teca_variant_array_impl< T >.

◆ new_copy() [3/4]

p_teca_variant_array teca_variant_array::new_copy ( size_t  src_start,
size_t  n_elem 
) const
inline

return a newly allocated object, initialized copy from a subset of this. The default allocator will be used.

Parameters
[in[src_start the first element to copy
[in]n_elemthe number of elements to copy

◆ new_copy() [4/4]

virtual p_teca_variant_array teca_variant_array::new_copy ( size_t  src_start,
size_t  n_elem,
allocator  alloc 
) const
pure virtual

return a newly allocated object, initialized copy from a subset of this.

Parameters
[in[src_start the first element to copy
[in]n_elemthe number of elements to copy
[in]allocselects the allocator to use (See ::allocator)

Implemented in teca_variant_array_impl< T >.

◆ new_instance() [1/4]

p_teca_variant_array teca_variant_array::new_instance ( ) const
inline

return a newly allocated empty object of the same type. The default allocator will be used.

◆ new_instance() [2/4]

virtual p_teca_variant_array teca_variant_array::new_instance ( allocator  alloc) const
pure virtual
Returns
a newly allocated empty object of the same type.
Parameters
[in]allocselects the allocator to use (See ::allocator)

Implemented in teca_variant_array_impl< T >.

◆ new_instance() [3/4]

p_teca_variant_array teca_variant_array::new_instance ( size_t  n) const
inline

returns a newly allocated object of the same type will n_elem elements allocated. The default allocator will be used.

Parameters
[in]n_elemthe number of elements to allocate.

◆ new_instance() [4/4]

virtual p_teca_variant_array teca_variant_array::new_instance ( size_t  n,
allocator  alloc 
) const
pure virtual

returns a newly allocated object of the same type will n_elem elements allocated.

Parameters
[in]n_elemthe number of elements to allocate.
[in[alloc selects the allocator to use (See ::allocator)

Implemented in teca_variant_array_impl< T >.

◆ reserve()

virtual void teca_variant_array::reserve ( unsigned long  i)
pure virtual

reserve. reserves the requested amount of space with out constructing elements

Implemented in teca_variant_array_impl< T >.

◆ resize()

virtual void teca_variant_array::resize ( unsigned long  i)
pure virtual

resize. allocates new storage and copies in existing values

Implemented in teca_variant_array_impl< T >.

◆ set() [1/7]

virtual void teca_variant_array::set ( const const_p_teca_variant_array src)
pure virtual

Set from the other array

Implemented in teca_variant_array_impl< T >.

◆ set() [2/7]

virtual void teca_variant_array::set ( const p_teca_variant_array src)
inlinevirtual

Set from the other array.

◆ set() [3/7]

template<typename T >
void teca_variant_array::set ( const std::vector< T > &  src)

set the contents from a vector of values. this array is not resized.

◆ set() [4/7]

virtual void teca_variant_array::set ( size_t  dest_start,
const const_p_teca_variant_array src,
size_t  src_start,
size_t  n_elem 
)
pure virtual

Set a subset of this array from a subset opf the contents of the other array.

Parameters
[in]dest_startthe first location to assign to
[in]srcthe array to copy values from
[in]src_startthe first location to copy from
[in]n_elemthe number of elements to copy

Implemented in teca_variant_array_impl< T >.

◆ set() [5/7]

virtual void teca_variant_array::set ( size_t  dest_start,
const p_teca_variant_array src,
size_t  src_start,
size_t  n_elem 
)
inlinevirtual

Set a subset of this array from a subset opf the contents of the other array.

Parameters
[in]dest_startthe first location to assign to
[in]srcthe array to copy values from
[in]src_startthe first location to copy from
[in]n_elemthe number of elements to copy

◆ set() [6/7]

template<typename T >
void teca_variant_array::set ( size_t  dest_start,
const T *  src,
size_t  src_start,
size_t  n_elem 
)

set a subset of the array from a passed array. this array is not resized.

◆ set() [7/7]

template<typename T >
void teca_variant_array::set ( unsigned long  i,
const T &  val 
)

set a single value

◆ set_allocator()

virtual int teca_variant_array::set_allocator ( allocator  alloc)
pure virtual

Set the allocator. If the passed allocator is already in use this is a NOOP. Otherwise the contents of the variant array are reallocated and moved using a buffer allocated with the passed allocator. This can be used to explicitly move the data.

Parameters
[in]allocthe new ::allocator to use
Returns
0 if successful

Implemented in teca_variant_array_impl< T >.

◆ size()

virtual unsigned long teca_variant_array::size ( ) const
pure virtualnoexcept

get the number of elements in the array

Implemented in teca_variant_array_impl< T >.

◆ swap()

virtual void teca_variant_array::swap ( const p_teca_variant_array other)
pure virtual

swap the contents of this and the other object. an exception is thrown when no conversion between the two types exists.

Implemented in teca_variant_array_impl< T >.

◆ synchronize()

virtual void teca_variant_array::synchronize ( ) const
pure virtual

synchronize on the associated stream

Implemented in teca_variant_array_impl< T >.

◆ to_stream() [1/2]

virtual int teca_variant_array::to_stream ( std::ostream &  s) const
pure virtual

serrialize to the stream in a human readable format

Implemented in teca_variant_array_impl< T >.

◆ to_stream() [2/2]

virtual int teca_variant_array::to_stream ( teca_binary_stream s) const
pure virtual

serrialize to the binary stream in the internal format

Implemented in teca_variant_array_impl< T >.

◆ type_code()

virtual unsigned int teca_variant_array::type_code ( ) const
pure virtualnoexcept

a code for the contained data type used for serialization


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