10 #ifndef _ZOLTAN2_TPLTRAITS_HPP_
11 #define _ZOLTAN2_TPLTRAITS_HPP_
13 #include <Teuchos_RCP.hpp>
14 #include <Teuchos_ArrayView.hpp>
15 #include <Teuchos_as.hpp>
19 #include <zoltan_types.h>
33 template <
typename first_t,
typename second_t>
39 return ((
sizeof(first_t) ==
sizeof(second_t)) &&
40 (std::numeric_limits<first_t>::is_signed ==
41 std::numeric_limits<second_t>::is_signed));
44 static inline void ASSIGN(first_t &a, second_t b)
48 a = Teuchos::asSafe<first_t, second_t>(b);
50 catch (std::exception &) {
51 throw std::runtime_error(
52 "TPL_Traits: Value too large for TPL index type. "
53 "Rebuild TPL with larger index type or rebuild without the TPL.");
57 static inline void ASSIGN_ARRAY(first_t **a, ArrayView<second_t> &b)
60 size_t size = b.size();
62 *a =
new first_t[size];
63 for (
size_t i = 0; i < size; i++)
ASSIGN((*a)[i], b[i]);
83 first_t *tmp =
new first_t[size];
84 for (
size_t i = 0; i < size; i++)
ASSIGN(tmp[i], b[i]);
85 *a = arcp(tmp, 0, size,
true);
104 template <
typename first_t>
109 static inline void ASSIGN(first_t &a, first_t b) { a = b; }
129 *a = arcp(b, 0, size,
true);
141 template <
typename second_t>
150 static const int NUM_ID = ((
sizeof(second_t) /
sizeof(ZOLTAN_ID_TYPE) > 0)
151 ? (
sizeof(second_t) /
sizeof(ZOLTAN_ID_TYPE))
163 static inline void ASSIGN(ZOLTAN_ID_PTR &a, second_t b)
167 a[0] =
static_cast<ZOLTAN_ID_TYPE
>(b);
170 ZOLTAN_ID_TYPE *ptr = (ZOLTAN_ID_TYPE *)(&b);
176 ZOLTAN_ID_TYPE *ptr = (ZOLTAN_ID_TYPE *)(&b);
177 for (
int i = 0; i < NUM_ID; i++) a[i] = ptr[i];
182 static inline void ASSIGN_ARRAY(ZOLTAN_ID_PTR *a, ArrayView<second_t> &b)
185 size_t size = b.size();
189 *a =
reinterpret_cast<ZOLTAN_ID_PTR
> (b.getRawPtr());
192 *a =
new ZOLTAN_ID_TYPE[size*NUM_ID];
193 for (
size_t i = 0; i < size; i++) {
194 ZOLTAN_ID_PTR tmp = &((*a)[i*NUM_ID]);
207 throw std::runtime_error(
208 "TPL_Traits::SAVE_ARRAYRCP<ZOLTAN_ID_PTR,second_t> "
209 "is not implemented.");
224 template <
typename first_t>
240 static inline void ASSIGN(first_t &a, ZOLTAN_ID_PTR b)
244 a =
static_cast<first_t
>(b[0]);
247 first_t *tmp = (first_t *) b;
252 static inline void ASSIGN_ARRAY(first_t *a, ArrayView<ZOLTAN_ID_PTR> &b)
254 throw std::runtime_error(
255 "TPL_Traits::ASSIGN_ARRAY<first_t,ZOLTAN_ID_PTR> "
256 "is not implemented.");
267 *a = arcp(b, 0, size,
true);
269 first_t *tmp =
new first_t[size];
270 for (
size_t i = 0; i < size; i++)
ASSIGN(tmp[i], &(b[i*NUM_ID]));
271 *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)