TECA
The Toolkit for Extreme Climate Analysis
teca_variant_array.h File Reference
#include <vector>
#include <string>
#include <sstream>
#include <exception>
#include <typeinfo>
#include <iterator>
#include <algorithm>
#include <type_traits>
#include <utility>
#include "teca_common.h"
#include "teca_binary_stream.h"
#include "teca_bad_cast.h"
#include "teca_shared_object.h"
Include dependency graph for teca_variant_array.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  teca_variant_array_impl< T >
 The concrete implementation of our type agnostic container for contiguous arrays. More...
 
class  teca_variant_array
 A type agnostic container for array based data. More...
 
class  teca_variant_array_impl< T >
 The concrete implementation of our type agnostic container for contiguous arrays. More...
 
struct  teca_variant_array_factory
 Creates an instance of teca_variant_array_impl<T> where T is determined from the type code. More...
 

Macros

#define TECA_VARIANT_ARRAY_STATIC_NEW(T, t)
 
#define TEMPLATE_DISPATCH_CASE(tt, nt, p, body)
 
#define NESTED_TEMPLATE_DISPATCH_CASE(tt, nt, p, i, body)
 
#define TEMPLATE_DISPATCH_FP(t, p, body)
 Executes the code in body if p is a t<nt> where nt is a floating point type. More...
 
#define TEMPLATE_DISPATCH_SI(t, p, body)
 Executes the code in body if p is a t<nt> where nt is a signed inetegral type. More...
 
#define TEMPLATE_DISPATCH_FP_SI(t, p, body)
 Executes the code in body if p is a t<nt> where nt is either a signed integral or floating point type. More...
 
#define TEMPLATE_DISPATCH_I(t, p, body)
 Executes the code in body if p is a t<nt> where nt is an integral type. More...
 
#define TEMPLATE_DISPATCH(t, p, body)
 
#define NESTED_TEMPLATE_DISPATCH_FP(t, p, i, body)
 
#define NESTED_TEMPLATE_DISPATCH_I(t, p, i, body)
 
#define NESTED_TEMPLATE_DISPATCH(t, p, i, body)
 
#define STR_DELIM(_a, _b)   (std::is_same<T, std::string>::value ? _a : _b)
 

Typedefs

using p_teca_variant_array = std::shared_ptr< teca_variant_array >
 
using const_p_teca_variant_array = std::shared_ptr< const teca_variant_array >
 
template<typename T >
using p_teca_variant_array_impl = std::shared_ptr< teca_variant_array_impl< T > >
 
template<typename T >
using const_p_teca_variant_array_impl = std::shared_ptr< const teca_variant_array_impl< T > >
 
using teca_string_array = teca_variant_array_impl< std::string >
 
using p_teca_string_array = std::shared_ptr< teca_variant_array_impl< std::string > >
 
using const_p_teca_string_array = std::shared_ptr< const teca_variant_array_impl< std::string > >
 
using teca_float_array = teca_variant_array_impl< float >
 
using p_teca_float_array = std::shared_ptr< teca_variant_array_impl< float > >
 
using const_p_teca_float_array = std::shared_ptr< const teca_variant_array_impl< float > >
 
using teca_double_array = teca_variant_array_impl< double >
 
using p_teca_double_array = std::shared_ptr< teca_variant_array_impl< double > >
 
using const_p_teca_double_array = std::shared_ptr< const teca_variant_array_impl< double > >
 
using teca_char_array = teca_variant_array_impl< char >
 
using p_teca_char_array = std::shared_ptr< teca_variant_array_impl< char > >
 
using const_p_teca_char_array = std::shared_ptr< const teca_variant_array_impl< char > >
 
using teca_unsigned_char_array = teca_variant_array_impl< unsigned char >
 
using p_teca_unsigned_char_array = std::shared_ptr< teca_variant_array_impl< unsigned char > >
 
using const_p_teca_unsigned_char_array = std::shared_ptr< const teca_variant_array_impl< unsigned char > >
 
using teca_short_array = teca_variant_array_impl< short >
 
using p_teca_short_array = std::shared_ptr< teca_variant_array_impl< short > >
 
using const_p_teca_short_array = std::shared_ptr< const teca_variant_array_impl< short > >
 
using teca_unsigned_short_array = teca_variant_array_impl< unsigned short >
 
using p_teca_unsigned_short_array = std::shared_ptr< teca_variant_array_impl< unsigned short > >
 
using const_p_teca_unsigned_short_array = std::shared_ptr< const teca_variant_array_impl< unsigned short > >
 
using teca_int_array = teca_variant_array_impl< int >
 
using p_teca_int_array = std::shared_ptr< teca_variant_array_impl< int > >
 
using const_p_teca_int_array = std::shared_ptr< const teca_variant_array_impl< int > >
 
using teca_unsigned_int_array = teca_variant_array_impl< unsigned int >
 
using p_teca_unsigned_int_array = std::shared_ptr< teca_variant_array_impl< unsigned int > >
 
using const_p_teca_unsigned_int_array = std::shared_ptr< const teca_variant_array_impl< unsigned int > >
 
using teca_long_array = teca_variant_array_impl< long >
 
using p_teca_long_array = std::shared_ptr< teca_variant_array_impl< long > >
 
using const_p_teca_long_array = std::shared_ptr< const teca_variant_array_impl< long > >
 
using teca_unsigned_long_array = teca_variant_array_impl< unsigned long >
 
using p_teca_unsigned_long_array = std::shared_ptr< teca_variant_array_impl< unsigned long > >
 
using const_p_teca_unsigned_long_array = std::shared_ptr< const teca_variant_array_impl< unsigned long > >
 
using teca_long_long_array = teca_variant_array_impl< long long >
 
using p_teca_long_long_array = std::shared_ptr< teca_variant_array_impl< long long > >
 
using const_p_teca_long_long_array = std::shared_ptr< const teca_variant_array_impl< long long > >
 
using teca_unsigned_long_long_array = teca_variant_array_impl< unsigned long long >
 
using p_teca_unsigned_long_long_array = std::shared_ptr< teca_variant_array_impl< unsigned long long > >
 
using const_p_teca_unsigned_long_long_array = std::shared_ptr< const teca_variant_array_impl< unsigned long long > >
 
using teca_size_t_array = teca_variant_array_impl< size_t >
 
using p_teca_size_t_array = std::shared_ptr< teca_variant_array_impl< size_t > >
 
using const_p_teca_size_t_array = std::shared_ptr< const teca_variant_array_impl< size_t > >
 

Functions

template<typename num_t >
num_t min (const const_p_teca_variant_array_impl< num_t > &a)
 
template<typename num_t >
num_t min (const p_teca_variant_array_impl< num_t > &a)
 
template<typename num_t >
num_t max (const const_p_teca_variant_array_impl< num_t > &a)
 
template<typename num_t >
num_t max (const p_teca_variant_array_impl< num_t > &a)
 

Macro Definition Documentation

◆ NESTED_TEMPLATE_DISPATCH

#define NESTED_TEMPLATE_DISPATCH (   t,
  p,
  i,
  body 
)
Value:
NESTED_TEMPLATE_DISPATCH_FP(t, p, i, body) \
else NESTED_TEMPLATE_DISPATCH_I(t, p, i, body)

A macro for accessing the typed contents of a teca_variant_array

Parameters
tcontainer type
ppointer to an instance to match on
ian indentifier to use with type aliases
bodycode to execute on match

See NESTED_TEMPLATE_DISPATCH_CASE for details.

◆ NESTED_TEMPLATE_DISPATCH_CASE

#define NESTED_TEMPLATE_DISPATCH_CASE (   tt,
  nt,
  p,
  i,
  body 
)
Value:
if (dynamic_cast<tt<nt>*>(p)) \
{ \
using TT##i = tt<nt>; \
using NT##i = nt; \
body \
}

Executes the code in body if p is a tt<nt> an idnetifier disambiguates type aliases when nested

Parameters
ttderived container
ntcontained type
pbase class pointer
iidentifier
bodythe code to execute if the type matches

The following aliases are provided to know the type within the code to execute.

using TT##i = tt<nt>;
using NT##i = nt;

◆ NESTED_TEMPLATE_DISPATCH_FP

#define NESTED_TEMPLATE_DISPATCH_FP (   t,
  p,
  i,
  body 
)
Value:
NESTED_TEMPLATE_DISPATCH_CASE(t, float, p, i, body) \
else NESTED_TEMPLATE_DISPATCH_CASE(t, double, p, i, body)

A macro for accessing the floating point typed contents of a teca_variant_array

Parameters
tcontainer type
ppointer to an instance to match on
ian indentifier to use with type aliases
bodycode to execute on match

See NESTED_TEMPLATE_DISPATCH_CASE for details.

◆ NESTED_TEMPLATE_DISPATCH_I

#define NESTED_TEMPLATE_DISPATCH_I (   t,
  p,
  i,
  body 
)
Value:
NESTED_TEMPLATE_DISPATCH_CASE(t, long long, p, i, body) \
else NESTED_TEMPLATE_DISPATCH_CASE(t, unsigned long long, p, i, body) \
else NESTED_TEMPLATE_DISPATCH_CASE(t, long, p, i, body) \
else NESTED_TEMPLATE_DISPATCH_CASE(t, int, p, i, body) \
else NESTED_TEMPLATE_DISPATCH_CASE(t, unsigned int, p, i, body) \
else NESTED_TEMPLATE_DISPATCH_CASE(t, unsigned long, p, i, body) \
else NESTED_TEMPLATE_DISPATCH_CASE(t, short int, p, i, body) \
else NESTED_TEMPLATE_DISPATCH_CASE(t, short unsigned int, p, i, body) \
else NESTED_TEMPLATE_DISPATCH_CASE(t, char, p, i, body) \
else NESTED_TEMPLATE_DISPATCH_CASE(t, unsigned char, p, i, body)

A macro for accessing the inetgral typed contents of a teca_variant_array

Parameters
tcontainer type
ppointer to an instance to match on
ian indentifier to use with type aliases
bodycode to execute on match

See NESTED_TEMPLATE_DISPATCH_CASE for details.

◆ TECA_VARIANT_ARRAY_STATIC_NEW

#define TECA_VARIANT_ARRAY_STATIC_NEW (   T,
 
)
Value:
\
/** Allocate a T<t> */ \
static std::shared_ptr<T<t>> New() \
{ \
return std::shared_ptr<T<t>>(new T<t>); \
} \
\
/** Allocate a T<t> of size n */ \
static std::shared_ptr<T<t>> New(size_t n) \
{ \
return std::shared_ptr<T<t>>(new T<t>(n)); \
} \
\
/** Allocate a T<t> of size n initialized with v */ \
static std::shared_ptr<T<t>> New(size_t n, const t &v) \
{ \
return std::shared_ptr<T<t>>(new T<t>(n, v)); \
} \
\
/** Allocate a T<t> initialized with n values from vals */ \
static std::shared_ptr<T<t>> New(const t *vals, size_t n) \
{ \
return std::shared_ptr<T<t>>(new T<t>(vals, n)); \
} \
\
using teca_variant_array::shared_from_this; \
\
std::shared_ptr<T> shared_from_this() \
{ \
return std::static_pointer_cast<T>(shared_from_this()); \
} \
\
std::shared_ptr<T const> shared_from_this() const \
{ \
return std::static_pointer_cast<T const>(shared_from_this()); \
}

this is a convenience macro to be used to declare a static New method that will be used to construct new objects in shared_ptr's. This manages the details of interoperability with std C++11 shared pointer

◆ TEMPLATE_DISPATCH

#define TEMPLATE_DISPATCH (   t,
  p,
  body 
)
Value:
TEMPLATE_DISPATCH_FP(t, p, body) \
else TEMPLATE_DISPATCH_I(t, p, body)

A macro for accessing the typed contents of a teca_variant_array

Parameters
tcontainer type
ppointer to an instance to match on
bodycode to execute on match

See TEMPLATE_DISPATCH_CASE for details.

◆ TEMPLATE_DISPATCH_CASE

#define TEMPLATE_DISPATCH_CASE (   tt,
  nt,
  p,
  body 
)
Value:
if (dynamic_cast<tt<nt>*>(p)) \
{ \
using TT = tt<nt>; \
using NT = nt; \
body \
}

Executes the code in body if p is a tt<nt>

Parameters
ttderived container
ntcontained type
pbase class pointer
bodythe code to execute if the type matches

The following aliases are provided to know the type within the code to execute.

using TT = tt<nt>;
using NT = nt;

◆ TEMPLATE_DISPATCH_FP

#define TEMPLATE_DISPATCH_FP (   t,
  p,
  body 
)
Value:
TEMPLATE_DISPATCH_CASE(t, float, p, body) \
else TEMPLATE_DISPATCH_CASE(t, double, p, body)

Executes the code in body if p is a t<nt> where nt is a floating point type.

◆ TEMPLATE_DISPATCH_FP_SI

#define TEMPLATE_DISPATCH_FP_SI (   t,
  p,
  body 
)
Value:
TEMPLATE_DISPATCH_CASE(t, float, p, body) \
else TEMPLATE_DISPATCH_CASE(t, double, p, body) \
else TEMPLATE_DISPATCH_SI(t, p, body)

Executes the code in body if p is a t<nt> where nt is either a signed integral or floating point type.

◆ TEMPLATE_DISPATCH_I

#define TEMPLATE_DISPATCH_I (   t,
  p,
  body 
)
Value:
TEMPLATE_DISPATCH_CASE(t, long long, p, body) \
else TEMPLATE_DISPATCH_CASE(t, unsigned long long, p, body) \
else TEMPLATE_DISPATCH_CASE(t, long, p, body) \
else TEMPLATE_DISPATCH_CASE(t, int, p, body) \
else TEMPLATE_DISPATCH_CASE(t, unsigned int, p, body) \
else TEMPLATE_DISPATCH_CASE(t, unsigned long, p, body) \
else TEMPLATE_DISPATCH_CASE(t, short int, p, body) \
else TEMPLATE_DISPATCH_CASE(t, short unsigned int, p, body) \
else TEMPLATE_DISPATCH_CASE(t, char, p, body) \
else TEMPLATE_DISPATCH_CASE(t, unsigned char, p, body)

Executes the code in body if p is a t<nt> where nt is an integral type.

◆ TEMPLATE_DISPATCH_SI

#define TEMPLATE_DISPATCH_SI (   t,
  p,
  body 
)
Value:
TEMPLATE_DISPATCH_CASE(t, long long, p, body) \
else TEMPLATE_DISPATCH_CASE(t, long, p, body) \
else TEMPLATE_DISPATCH_CASE(t, int, p, body) \
else TEMPLATE_DISPATCH_CASE(t, short int, p, body) \
else TEMPLATE_DISPATCH_CASE(t, char, p, body)

Executes the code in body if p is a t<nt> where nt is a signed inetegral type.

Typedef Documentation

◆ const_p_teca_variant_array

using const_p_teca_variant_array = std::shared_ptr<const teca_variant_array >

A shared pointer to a const instance of teca_variant_array

◆ const_p_teca_variant_array_impl

template<typename T >
using const_p_teca_variant_array_impl = std::shared_ptr<const teca_variant_array_impl <T> >

A shared pointer to a const instance of teca_variant_array_impl

◆ p_teca_variant_array

using p_teca_variant_array = std::shared_ptr< teca_variant_array >

a shared pointer to an instance of teca_variant_array

◆ p_teca_variant_array_impl

template<typename T >
using p_teca_variant_array_impl = std::shared_ptr< teca_variant_array_impl <T> >

a shared pointer to an instance of teca_variant_array_impl

TEMPLATE_DISPATCH_SI
#define TEMPLATE_DISPATCH_SI(t, p, body)
Executes the code in body if p is a t<nt> where nt is a signed inetegral type.
Definition: teca_variant_array.h:198
NESTED_TEMPLATE_DISPATCH_FP
#define NESTED_TEMPLATE_DISPATCH_FP(t, p, i, body)
Definition: teca_variant_array.h:243
TEMPLATE_DISPATCH_I
#define TEMPLATE_DISPATCH_I(t, p, body)
Executes the code in body if p is a t<nt> where nt is an integral type.
Definition: teca_variant_array.h:212
NESTED_TEMPLATE_DISPATCH_I
#define NESTED_TEMPLATE_DISPATCH_I(t, p, i, body)
Definition: teca_variant_array.h:255
TEMPLATE_DISPATCH_FP
#define TEMPLATE_DISPATCH_FP(t, p, body)
Executes the code in body if p is a t<nt> where nt is a floating point type.
Definition: teca_variant_array.h:193
TEMPLATE_DISPATCH_CASE
#define TEMPLATE_DISPATCH_CASE(tt, nt, p, body)
Definition: teca_variant_array.h:161
NESTED_TEMPLATE_DISPATCH_CASE
#define NESTED_TEMPLATE_DISPATCH_CASE(tt, nt, p, i, body)
Definition: teca_variant_array.h:184