13 #include <stk_util/environment/ReportHandler.hpp> 15 #include <stk_mesh/base/DataTraits.hpp> 16 #include <stk_mesh/base/DataTraitsEnum.hpp> 17 #include <stk_mesh/base/DataTraitsClass.hpp> 26 std::size_t stride( std::size_t size , std::size_t align )
28 if ( align && size % align ) { size += align - size % align ; }
34 DataTraits::DataTraits(
const std::type_info & arg_type ,
35 const char *
const arg_name ,
36 std::size_t arg_size ,
37 std::size_t arg_align )
38 : type_info( arg_type ),
42 is_floating_point( false ),
49 alignment_of( arg_align ),
50 stride_of( stride( arg_size , arg_align ) ),
51 remove_pointer( NULL ),
57 DataTraits::DataTraits(
const std::type_info & arg_type ,
58 const DataTraits & arg_traits )
59 : type_info( arg_type ),
60 size_of( sizeof(void*) ),
63 is_floating_point( false ),
70 alignment_of( sizeof(void*) ),
71 stride_of( sizeof(void*) ),
72 remove_pointer( & arg_traits ),
77 name.assign( arg_traits.name ).append(
"*");
84 class DataTraitsVoid :
public DataTraits {
88 : DataTraits( typeid(void) ,
"void" , 0 , 0 )
91 void construct(
void * , std::size_t )
const 92 { ThrowErrorMsg(
"not supported" ); }
94 void destroy(
void * , std::size_t )
const 95 { ThrowErrorMsg(
"not supported" ); }
97 void pack( CommBuffer & ,
const void * , std::size_t )
const 98 { ThrowErrorMsg(
"not supported" ); }
100 void unpack( CommBuffer & ,
void * , std::size_t )
const 101 { ThrowErrorMsg(
"not supported" ); }
103 void print( std::ostream & ,
const void * , std::size_t )
const 104 { ThrowErrorMsg(
"not supported" ); }
106 void copy(
void * ,
const void * , std::size_t )
const 107 { ThrowErrorMsg(
"not supported" ); }
109 void sum(
void * ,
const void * , std::size_t )
const 110 { ThrowErrorMsg(
"not supported" ); }
112 void max(
void * ,
const void * , std::size_t )
const 113 { ThrowErrorMsg(
"not supported" ); }
115 void min(
void * ,
const void * , std::size_t )
const 116 { ThrowErrorMsg(
"not supported" ); }
118 virtual void bit_and(
void * ,
const void * , std::size_t )
const 119 { ThrowErrorMsg(
"not supported" ); }
121 virtual void bit_or(
void * ,
const void * , std::size_t )
const 122 { ThrowErrorMsg(
"not supported" ); }
124 virtual void bit_xor(
void * ,
const void * , std::size_t )
const 125 { ThrowErrorMsg(
"not supported" ); }
130 template<>
const DataTraits & data_traits<void>()
131 {
static const DataTraitsVoid traits ;
return traits ; }
137 template<
typename A ,
typename B >
138 struct IsSameType {
enum { value =
false }; };
140 template<
typename A >
141 struct IsSameType<A,A> {
enum { value =
true }; };
144 template<
typename T >
145 class DataTraitsCommon :
public DataTraits {
148 explicit DataTraitsCommon(
const char * arg_name )
149 : DataTraits( typeid(T) , arg_name , sizeof(T) , sizeof(T) )
153 is_integral = IsSameType<T,char>::value ||
154 IsSameType<T,unsigned char>::value ||
155 IsSameType<T,short>::value ||
156 IsSameType<T,unsigned short>::value ||
157 IsSameType<T,int>::value ||
158 IsSameType<T,unsigned int>::value ||
159 IsSameType<T,long>::value ||
160 IsSameType<T,unsigned long>::value ;
162 is_signed = IsSameType<T,char>::value ||
163 IsSameType<T,short>::value ||
164 IsSameType<T,int>::value ||
165 IsSameType<T,long>::value ;
167 is_unsigned = IsSameType<T,unsigned char>::value ||
168 IsSameType<T,unsigned short>::value ||
169 IsSameType<T,unsigned int>::value ||
170 IsSameType<T,unsigned long>::value ;
172 is_floating_point = IsSameType<T,double>::value ||
173 IsSameType<T,float>::value ;
176 void construct(
void * v , std::size_t n )
const 178 T * x =
reinterpret_cast<T*
>( v );
179 T *
const x_end = x + n ;
180 while ( x_end != x ) { *x++ = 0 ; }
183 void destroy(
void * v , std::size_t n )
const {}
185 void pack( CommBuffer & buf ,
const void * v , std::size_t n )
const 187 const T * x =
reinterpret_cast<const T*
>( v );
188 buf.pack<T>( x , n );
191 void unpack( CommBuffer & buf ,
void * v , std::size_t n )
const 193 T * x =
reinterpret_cast<T*
>( v );
194 buf.unpack<T>( x , n );
197 void copy(
void * vx ,
const void * vy , std::size_t n )
const 199 const T * y =
reinterpret_cast<const T*
>( vy );
200 T * x =
reinterpret_cast<T*
>( vx );
201 T *
const x_end = x + n ;
202 while ( x_end != x ) { *x++ = *y++ ; };
205 void sum(
void * vx ,
const void * vy , std::size_t n )
const 207 const T * y =
reinterpret_cast<const T*
>( vy );
208 T * x =
reinterpret_cast<T*
>( vx );
209 T *
const x_end = x + n ;
210 while ( x_end != x ) { *x++ += *y++ ; };
213 virtual void print( std::ostream & s ,
const void * v , std::size_t n )
const 216 const T * x =
reinterpret_cast<const T*
>( v );
217 const T *
const x_end = x + n ;
219 while ( x_end != x ) { s <<
" " << *x++ ; }
223 virtual void max(
void * vx ,
const void * vy , std::size_t n )
const 224 { ThrowErrorMsg(
"not supported" ); }
226 virtual void min(
void * vx ,
const void * vy , std::size_t n )
const 227 { ThrowErrorMsg(
"not supported" ); }
229 virtual void bit_and(
void * ,
const void * , std::size_t )
const 230 { ThrowErrorMsg(
"not supported" ); }
232 virtual void bit_or(
void * ,
const void * , std::size_t )
const 233 { ThrowErrorMsg(
"not supported" ); }
235 virtual void bit_xor(
void * ,
const void * , std::size_t )
const 236 { ThrowErrorMsg(
"not supported" ); }
239 template<
typename T >
240 class DataTraitsNumeric :
public DataTraitsCommon<T> {
243 explicit DataTraitsNumeric(
const char * arg_name )
244 : DataTraitsCommon<T>( arg_name ) {}
246 virtual void max(
void * vx ,
const void * vy , std::size_t n )
const 248 const T * y =
reinterpret_cast<const T*
>( vy );
249 T * x =
reinterpret_cast<T*
>( vx );
250 T *
const x_end = x + n ;
251 for ( ; x_end != x ; ++x , ++y ) {
if ( *x < *y ) { *x = *y ; } }
254 virtual void min(
void * vx ,
const void * vy , std::size_t n )
const 256 const T * y =
reinterpret_cast<const T*
>( vy );
257 T * x =
reinterpret_cast<T*
>( vx );
258 T *
const x_end = x + n ;
259 for ( ; x_end != x ; ++x , ++y ) {
if ( *x > *y ) { *x = *y ; } }
263 template<
typename T >
264 class DataTraitsComplex :
public DataTraitsCommon<T> {
267 explicit DataTraitsComplex(
const char * arg_name )
268 : DataTraitsCommon<T>( arg_name ) {}
271 template<
typename T >
272 class DataTraitsIntegral :
public DataTraitsNumeric<T> {
274 DataTraitsIntegral(
const char * name ) : DataTraitsNumeric<T>( name ) {}
276 virtual void bit_and(
void * vx ,
const void * vy , std::size_t n )
const 278 const T * y =
reinterpret_cast<const T*
>( vy );
279 T * x =
reinterpret_cast<T*
>( vx );
280 T *
const x_end = x + n ;
281 while ( x_end != x ) { *x++ &= *y++ ; }
284 virtual void bit_or(
void * vx ,
const void * vy , std::size_t n )
const 286 const T * y =
reinterpret_cast<const T*
>( vy );
287 T * x =
reinterpret_cast<T*
>( vx );
288 T *
const x_end = x + n ;
289 while ( x_end != x ) { *x++ |= *y++ ; }
292 virtual void bit_xor(
void * vx ,
const void * vy , std::size_t n )
const 294 const T * y =
reinterpret_cast<const T*
>( vy );
295 T * x =
reinterpret_cast<T*
>( vx );
296 T *
const x_end = x + n ;
297 while ( x_end != x ) { *x++ ^= *y++ ; }
301 class DataTraitsChar :
public DataTraitsIntegral<char> {
303 DataTraitsChar() : DataTraitsIntegral<char>(
"char" ) {}
305 virtual void print( std::ostream & s ,
const void * v , std::size_t n )
const 308 const char * x =
reinterpret_cast<const char*
>( v );
309 const char *
const x_end = x + n ;
311 while ( x_end != x ) { s <<
" " << int(*x++) ; }
316 class DataTraitsUnsignedChar :
public DataTraitsIntegral<unsigned char> {
318 DataTraitsUnsignedChar()
319 : DataTraitsIntegral<unsigned char>(
"unsigned char" ) {}
321 virtual void print( std::ostream & s ,
const void * v , std::size_t n )
const 324 const unsigned char * x =
reinterpret_cast<const unsigned char*
>( v );
325 const unsigned char *
const x_end = x + n ;
326 s << unsigned(*x++) ;
327 while ( x_end != x ) { s <<
" " << unsigned(*x++) ; }
334 #define DATA_TRAITS_NUMERIC( T ) \ 336 const DataTraits & data_traits<T>() \ 337 { static const DataTraitsNumeric<T> traits( #T ); return traits ; } 339 #define DATA_TRAITS_COMPLEX( T ) \ 341 const DataTraits & data_traits<T>() \ 342 { static const DataTraitsComplex<T> traits( #T ); return traits ; } 344 #define DATA_TRAITS_INTEGRAL( T ) \ 346 const DataTraits & data_traits<T>() \ 347 { static const DataTraitsIntegral<T> traits( #T ); return traits ; } 350 const DataTraits & data_traits<char>()
351 {
static const DataTraitsChar traits ;
return traits ; }
354 const DataTraits & data_traits<unsigned char>()
355 {
static const DataTraitsUnsignedChar traits ;
return traits ; }
357 DATA_TRAITS_INTEGRAL(
short )
358 DATA_TRAITS_INTEGRAL(
unsigned short )
359 DATA_TRAITS_INTEGRAL(
int )
360 DATA_TRAITS_INTEGRAL(
unsigned int )
361 DATA_TRAITS_INTEGRAL(
long )
362 DATA_TRAITS_INTEGRAL(
unsigned long )
363 DATA_TRAITS_NUMERIC(
float )
364 DATA_TRAITS_NUMERIC(
double )
365 DATA_TRAITS_COMPLEX( std::complex<float> )
366 DATA_TRAITS_COMPLEX( std::complex<double> )
373 template<
typename T >
374 class DataTraitsPointerToFundamental :
public DataTraits {
377 DataTraitsPointerToFundamental()
378 : DataTraits( typeid(T*) , data_traits<T>() ) {}
380 void construct(
void * v , std::size_t n )
const 382 void ** x =
reinterpret_cast<void**
>(v);
383 void **
const x_end = x + n ;
384 while ( x_end != x ) { *x++ = NULL ; }
387 void destroy(
void * v , std::size_t n )
const 389 void ** x =
reinterpret_cast<void**
>(v);
390 void **
const x_end = x + n ;
391 while ( x_end != x ) { *x++ = NULL ; }
394 void copy(
void * vx ,
const void * vy , std::size_t n )
const 396 void *
const * y =
reinterpret_cast<void*
const *
>(vy);
397 void ** x =
reinterpret_cast<void**
>(vx);
398 void **
const x_end = x + n ;
399 while ( x_end != x ) { *x++ = *y++ ; }
402 void pack( CommBuffer & ,
const void * , std::size_t )
const 403 { ThrowErrorMsg(
"not supported" ); }
405 void unpack( CommBuffer & ,
void * , std::size_t )
const 406 { ThrowErrorMsg(
"not supported" ); }
408 void print( std::ostream & ,
const void * , std::size_t )
const 409 { ThrowErrorMsg(
"not supported" ); }
411 void sum(
void * ,
const void * , std::size_t )
const 412 { ThrowErrorMsg(
"not supported" ); }
414 void max(
void * ,
const void * , std::size_t )
const 415 { ThrowErrorMsg(
"not supported" ); }
417 void min(
void * ,
const void * , std::size_t )
const 418 { ThrowErrorMsg(
"not supported" ); }
420 virtual void bit_and(
void * ,
const void * , std::size_t )
const 421 { ThrowErrorMsg(
"not supported" ); }
423 virtual void bit_or(
void * ,
const void * , std::size_t )
const 424 { ThrowErrorMsg(
"not supported" ); }
426 virtual void bit_xor(
void * ,
const void * , std::size_t )
const 427 { ThrowErrorMsg(
"not supported" ); }
432 #define DATA_TRAITS_POINTER( T ) \ 433 template<> const DataTraits & data_traits<T*>() \ 434 { static const DataTraitsPointerToFundamental<T> traits ; return traits ; } 436 DATA_TRAITS_POINTER(
char )
437 DATA_TRAITS_POINTER(
unsigned char )
438 DATA_TRAITS_POINTER(
short )
439 DATA_TRAITS_POINTER(
unsigned short )
440 DATA_TRAITS_POINTER(
int )
441 DATA_TRAITS_POINTER(
unsigned int )
442 DATA_TRAITS_POINTER(
long )
443 DATA_TRAITS_POINTER(
unsigned long )
444 DATA_TRAITS_POINTER(
float )
445 DATA_TRAITS_POINTER(
double )
446 DATA_TRAITS_POINTER(
void )
447 DATA_TRAITS_POINTER( std::complex<float> )
448 DATA_TRAITS_POINTER( std::complex<double> )
std::ostream & print(std::ostream &os, const std::string &indent, const Bucket &bucket)
Print the parts and entities of this bucket.
OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result)