OpenFPM_data  0.1.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Namespaces Functions Variables Typedefs Friends
grid_key_expression.hpp
1 #ifndef GRID_KEY_EXPRESSION
2 #define GRID_KEY_EXPRESSION
3 
4 #include "util/common.hpp"
5 
6 template<unsigned int dim> class grid_key_dx;
7 template<int dim, typename exp1, typename exp2> class grid_key_dx_sum;
8 template<int dim, typename exp1, typename exp2> class grid_key_dx_sub;
9 
10 
21 template<unsigned int dim, typename exp>
23 {
24 public:
25 
26  mem_id value(int i) const
27  {
28  return static_cast<const exp &>(*this).value(i);
29  }
30 
31  /* \brief subtract this expression with another expression
32  *
33  * \param key to subtract
34  *
35  * \return a grid_key_dx_expression that encapsulate the expression
36  *
37  */
39  {
41 
42  return exp_sum;
43  }
44 
45  /* \brief subtract this expression a grid key
46  *
47  * \param key to subtract
48  *
49  * \return a grid_key_dx_expression that encapsulate the expression
50  *
51  */
53  {
55 
56  return exp_sum;
57  }
58 };
59 
60 
68 template<int dim, typename exp1, typename exp2>
69 class grid_key_dx_sum : public grid_key_dx_expression<dim,grid_key_dx_sum<dim,exp1,exp2>>
70 {
71  const exp1 & e1;
72  const exp2 & e2;
73 
74 public:
75 
76  grid_key_dx_sum(const exp1 & ex1, const exp2 & ex2)
77  :e1(ex1),e2(ex2)
78  {}
79 
80  mem_id value(int i) const
81  {
82  return e1.value(i) + e2.value(i);
83  }
84 };
85 
93 template<int dim, typename exp1, typename exp2>
94 class grid_key_dx_sub : public grid_key_dx_expression<dim,grid_key_dx_sub<dim,exp1,exp2>>
95 {
96  const exp1 & e1;
97  const exp2 & e2;
98 
99 public:
100 
101  grid_key_dx_sub(const exp1 & ex1, const exp2 & ex2)
102  :e1(ex1),e2(ex2)
103  {}
104 
105  mem_id value(int i) const
106  {
107  return e1.value(i) - e2.value(i);
108  }
109 };
110 
111 #endif
Main class that encapsulate a sub expression.
grid_key_dx is the key to access any element in the grid
Definition: grid_key.hpp:18
Expression template for grid_key_dx.
This class is a trick to indicate the compiler a specific specialization pattern. ...
Definition: memory_c.hpp:202
Main class that encapsulate a sum expression.