pops-core  0.9
PoPS (Pest or Pathogen Spread) Model Core C++ library
Classes | Macros | Typedefs | Enumerations | Functions
utils.hpp File Reference
#include <algorithm>
#include <array>
#include <vector>
Include dependency graph for utils.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  BBox< Number >
 
struct  indices< Indices >
 
struct  build_indices< Size >
 
struct  build_indices< 0 >
 

Macros

#define UNUSED(expr)   (void)(expr)
 Macro to mark unused variables (including parameters) and silence the warning while documenting that it is intentionally unused. More...
 
#define M_PI   3.14159265358979323846
 
#define PI   M_PI
 

Typedefs

typedef std::tuple< int, int, int, int > BBoxInt
 
typedef std::tuple< double, double, double, double > BBoxFloat
 
typedef std::tuple< bool, bool, bool, bool > BBoxBool
 
template<typename T >
using Bare = typename std::remove_cv< typename std::remove_reference< T >::type >::type
 

Enumerations

enum  Direction {
  Direction::N = 0, Direction::NE = 45, Direction::E = 90, Direction::SE = 135,
  Direction::S = 180, Direction::SW = 225, Direction::W = 270, Direction::NW = 315,
  Direction::None
}
 Spread direction. More...
 

Functions

template<typename Container , typename Value >
bool container_contains (const Container &container, const Value &value)
 Return true if container contains value. More...
 
template<typename Container , typename Generator >
void shuffle_container (Container &container, Generator &generator)
 Reorder items in container. More...
 
template<typename Tuple >
constexpr build_indices< std::tuple_size< Bare< Tuple > >::value >::type make_indices ()
 
template<typename Tuple , int... Indices>
std::array< typename std::tuple_element< 0, Bare< Tuple > >::type, std::tuple_size< Bare< Tuple > >::value > to_array (Tuple &&tuple, indices< Indices... >)
 
template<typename Tuple >
auto to_array (Tuple &&tuple) -> decltype(to_array(std::declval< Tuple >(), make_indices< Tuple >()))
 
std::string quarantine_enum_to_string (Direction type)
 
template<typename RasterIndex , typename RasterType >
std::vector< std::vector< RasterIndex > > find_suitable_cells (const RasterType &raster)
 Create a list of suitable cells in from a host raster. More...
 

Macro Definition Documentation

◆ M_PI

#define M_PI   3.14159265358979323846

Definition at line 35 of file utils.hpp.

◆ PI

#define PI   M_PI

Definition at line 36 of file utils.hpp.

◆ UNUSED

#define UNUSED (   expr)    (void)(expr)

Macro to mark unused variables (including parameters) and silence the warning while documenting that it is intentionally unused.

It is recommended to also document why the variable is unused, but left in the code.

Usage:

UNUSED(variable_name); // Parameter needed for backwards compatibility.

To be replaced by [[maybe_unused]] once we migrate to C++17 or higher.

Definition at line 33 of file utils.hpp.

Typedef Documentation

◆ Bare

template<typename T >
using Bare = typename std::remove_cv<typename std::remove_reference<T>::type>::type

Definition at line 115 of file utils.hpp.

◆ BBoxBool

typedef std::tuple<bool, bool, bool, bool> BBoxBool

Definition at line 63 of file utils.hpp.

◆ BBoxFloat

typedef std::tuple<double, double, double, double> BBoxFloat

Definition at line 62 of file utils.hpp.

◆ BBoxInt

typedef std::tuple<int, int, int, int> BBoxInt

Definition at line 61 of file utils.hpp.

Enumeration Type Documentation

◆ Direction

enum Direction
strong

Spread direction.

Spread, typically wind, direction. Values are in degrees and are used in computations. None means that there is no wind.

Enumerator

North.

NE 

Northeast.

East.

SE 

Southeast.

South.

SW 

Southwest.

West.

NW 

Northwest.

None 

No direction (non-directional)

Definition at line 83 of file utils.hpp.

Function Documentation

◆ container_contains()

template<typename Container , typename Value >
bool container_contains ( const Container &  container,
const Value &  value 
)

Return true if container contains value.

Definition at line 46 of file utils.hpp.

Here is the caller graph for this function:

◆ find_suitable_cells()

template<typename RasterIndex , typename RasterType >
std::vector<std::vector<RasterIndex> > find_suitable_cells ( const RasterType &  raster)

Create a list of suitable cells in from a host raster.

Suitable cell is defined as cell with value higher than zero, i.e., there is at least one host.

Suitable cells datastructure is vector of vectors where the nested vector always has size equal to two and contains row and column index. The type was chosen to work well with Rcpp.

First template parameter is the index type for the resulting sutibale cell indices. Second template parameter is deduced automatically from the function parameter.

Definition at line 173 of file utils.hpp.

◆ make_indices()

template<typename Tuple >
constexpr build_indices<std::tuple_size<Bare<Tuple> >::value>::type make_indices ( )
constexpr

Definition at line 119 of file utils.hpp.

◆ quarantine_enum_to_string()

std::string quarantine_enum_to_string ( Direction  type)

Definition at line 141 of file utils.hpp.

◆ shuffle_container()

template<typename Container , typename Generator >
void shuffle_container ( Container &  container,
Generator &  generator 
)

Reorder items in container.

Definition at line 56 of file utils.hpp.

◆ to_array() [1/2]

template<typename Tuple >
auto to_array ( Tuple &&  tuple) -> decltype(to_array(std::declval<Tuple>(), make_indices<Tuple>()))

Definition at line 135 of file utils.hpp.

Here is the call graph for this function:

◆ to_array() [2/2]

template<typename Tuple , int... Indices>
std::array< typename std::tuple_element<0, Bare<Tuple> >::type, std::tuple_size<Bare<Tuple> >::value> to_array ( Tuple &&  tuple,
indices< Indices... >   
)

Definition at line 128 of file utils.hpp.

Here is the caller graph for this function:
UNUSED
#define UNUSED(expr)
Macro to mark unused variables (including parameters) and silence the warning while documenting that ...
Definition: utils.hpp:33