46 #ifndef _ZOLTAN2_TPLTRAITS_HPP_
47 #define _ZOLTAN2_TPLTRAITS_HPP_
49 #include <Teuchos_RCP.hpp>
50 #include <Teuchos_ArrayView.hpp>
51 #include <Teuchos_as.hpp>
55 #include <zoltan_types.h>
69 template <
typename first_t,
typename second_t>
75 return ((
sizeof(first_t) ==
sizeof(second_t)) &&
76 (std::numeric_limits<first_t>::is_signed ==
77 std::numeric_limits<second_t>::is_signed));
80 static inline void ASSIGN(first_t &a, second_t b)
84 a = Teuchos::asSafe<first_t, second_t>(b);
86 catch (std::exception &e) {
87 throw std::runtime_error(
88 "TPL_Traits: Value too large for TPL index type. "
89 "Rebuild TPL with larger index type or rebuild without the TPL.");
93 static inline void ASSIGN_ARRAY(first_t **a, ArrayView<second_t> &b)
96 size_t size = b.size();
98 *a =
new first_t[size];
99 for (
size_t i = 0; i < size; i++)
ASSIGN((*a)[i], b[i]);
119 first_t *tmp =
new first_t[size];
120 for (
size_t i = 0; i < size; i++)
ASSIGN(tmp[i], b[i]);
121 *a = arcp(tmp, 0, size,
true);
140 template <
typename first_t>
145 static inline void ASSIGN(first_t &a, first_t b) { a = b; }
165 *a = arcp(b, 0, size,
true);
177 template <
typename second_t>
186 static const int NUM_ID = ((
sizeof(second_t) /
sizeof(ZOLTAN_ID_TYPE) > 0)
187 ? (
sizeof(second_t) /
sizeof(ZOLTAN_ID_TYPE))
199 static inline void ASSIGN(ZOLTAN_ID_PTR &a, second_t b)
203 a[0] =
static_cast<ZOLTAN_ID_TYPE
>(b);
206 ZOLTAN_ID_TYPE *ptr = (ZOLTAN_ID_TYPE *)(&b);
212 ZOLTAN_ID_TYPE *ptr = (ZOLTAN_ID_TYPE *)(&b);
213 for (
int i = 0; i < NUM_ID; i++) a[i] = ptr[i];
218 static inline void ASSIGN_ARRAY(ZOLTAN_ID_PTR *a, ArrayView<second_t> &b)
221 size_t size = b.size();
225 *a =
reinterpret_cast<ZOLTAN_ID_PTR
> (b.getRawPtr());
228 *a =
new ZOLTAN_ID_TYPE[size*NUM_ID];
229 for (
size_t i = 0; i < size; i++) {
230 ZOLTAN_ID_PTR tmp = &((*a)[i*NUM_ID]);
243 throw std::runtime_error(
244 "TPL_Traits::SAVE_ARRAYRCP<ZOLTAN_ID_PTR,second_t> "
245 "is not implemented.");
260 template <
typename first_t>
276 static inline void ASSIGN(first_t &a, ZOLTAN_ID_PTR b)
280 a =
static_cast<first_t
>(b[0]);
283 first_t *tmp = (first_t *) b;
288 static inline void ASSIGN_ARRAY(first_t *a, ArrayView<ZOLTAN_ID_PTR> &b)
290 throw std::runtime_error(
291 "TPL_Traits::ASSIGN_ARRAY<first_t,ZOLTAN_ID_PTR> "
292 "is not implemented.");
303 *a = arcp(b, 0, size,
true);
305 first_t *tmp =
new first_t[size];
306 for (
size_t i = 0; i < size; i++)
ASSIGN(tmp[i], &(b[i*NUM_ID]));
307 *a = arcp(tmp, 0, size,
true);
static void ASSIGN(ZOLTAN_ID_PTR &a, second_t b)
static void SAVE_ARRAYRCP(ArrayRCP< ZOLTAN_ID_PTR > *a, second_t *b, size_t size)
static void ASSIGN_ARRAY(first_t **a, ArrayView< first_t > &b)
static void SAVE_ARRAYRCP(ArrayRCP< first_t > *a, second_t *b, size_t size)
static void ASSIGN_ARRAY(first_t *a, ArrayView< ZOLTAN_ID_PTR > &b)
static void SAVE_ARRAYRCP(ArrayRCP< first_t > *a, first_t *b, size_t size)
static void DELETE_ARRAY(ZOLTAN_ID_PTR *a)
static void ASSIGN(first_t &a, second_t b)
static void ASSIGN(first_t &a, ZOLTAN_ID_PTR b)
static void ASSIGN_ARRAY(ZOLTAN_ID_PTR *a, ArrayView< second_t > &b)
Gathering definitions used in software development.
Defines the Environment class.
static void ASSIGN_ARRAY(first_t **a, ArrayView< second_t > &b)
static void DELETE_ARRAY(first_t **a)
static void SAVE_ARRAYRCP(ArrayRCP< first_t > *a, ZOLTAN_ID_PTR b, size_t size)
static void ASSIGN(first_t &a, first_t b)
static void DELETE_ARRAY(first_t **a)
static void DELETE_ARRAY(first_t **a)