1/*
2 * meta_compare.hpp
3 *
4 * Created on: Oct 31, 2015
5 * Author: i-bird
6 */
7
8#ifndef OPENFPM_DATA_SRC_UTIL_META_COMPARE_HPP_
9#define OPENFPM_DATA_SRC_UTIL_META_COMPARE_HPP_
10
11#include "compare_general.hpp"
12
13/*! \brief This class compare general objects
14 *
15 * this function is a general function to compare
16 *
17 * * primitives
18 * * array of primitives
19 * * complex objects
20 * * aggregates
21 *
22 * ### Usage of meta copy and compare for primitives
23 * \snippet meta_cc_unit_tests.hpp Usage of meta copy and compare for primitives
24 * ### Usage of meta copy and compare for array of primitives
25 * \snippet meta_cc_unit_tests.hpp Usage of meta copy and compare for array of primitives
26 * ### Usage of meta copy and compare for openfpm aggregates
27 * \snippet meta_cc_unit_tests.hpp Usage of meta copy and compare for openfpm aggregates
28 * ### Usage of meta copy and compare for complex object
29 * \snippet meta_cc_unit_tests.hpp Usage of meta copy and compare for complex object
30 * ### Usage of meta copy and compare for complex aggregates object
31 * \snippet meta_cc_unit_tests.hpp Usage of meta copy and compare for complex aggregates object
32 * ### Usage of meta copy and compare for Point_test
33 * \snippet meta_cc_unit_tests.hpp Usage of meta copy and compare for Point_test
34 *
35 */
36template<typename T>
37struct meta_compare
38{
39 static inline bool meta_compare_f(const T & src, const T & dst)
40 {
41 return compare_general<T>::compare_general_f(src,dst);
42 }
43};
44
45//! Partial specialization for N=1 1D-Array
46template<typename T,size_t N1>
47struct meta_compare<T[N1]>
48{
49 static inline bool meta_compare_f(const T (& src)[N1], const T (& dst)[N1])
50 {
51 for (size_t i1 = 0 ; i1 < N1 ; i1++)
52 {
53 if (compare_general<T>::compare_general_f(src[i1],dst[i1]) == false)
54 return false;
55 }
56
57 return true;
58 }
59};
60
61//! Partial specialization for N=2 2D-Array
62template<typename T,size_t N1,size_t N2>
63struct meta_compare<T[N1][N2]>
64{
65 static inline bool meta_compare_f(const T (& src)[N1][N2], const T (& dst)[N1][N2])
66 {
67 for (size_t i1 = 0 ; i1 < N1 ; i1++)
68 {
69 for (size_t i2 = 0 ; i2 < N2 ; i2++)
70 {
71 if (compare_general<T>::compare_general_f(src[i1][i2],dst[i1][i2]) == false)
72 return false;
73 }
74 }
75
76 return true;
77 }
78};
79
80//! Partial specialization for N=3
81template<typename T,size_t N1,size_t N2,size_t N3>
82struct meta_compare<T[N1][N2][N3]>
83{
84 static inline bool meta_compare_f(const T (& src)[N1][N2][N3], const T (& dst)[N1][N2][N3])
85 {
86 for (size_t i1 = 0 ; i1 < N1 ; i1++)
87 {
88 for (size_t i2 = 0 ; i2 < N2 ; i2++)
89 {
90 for (size_t i3 = 0 ; i3 < N3 ; i3++)
91 {
92 if (compare_general<T>::compare_general_f(src[i1][i2][i3],dst[i1][i2][i3]) == false)
93 return false;
94 }
95 }
96 }
97
98 return true;
99 }
100};
101
102
103
104
105#endif /* OPENFPM_DATA_SRC_UTIL_META_COMPARE_HPP_ */
106