Sierra Toolkit Version of the Day
DataTraits.hpp
00001 /*------------------------------------------------------------------------*/
00002 /*                 Copyright 2010 Sandia Corporation.                     */
00003 /*  Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive   */
00004 /*  license for use of this work by or on behalf of the U.S. Government.  */
00005 /*  Export of this program may require a license from the                 */
00006 /*  United States Government.                                             */
00007 /*------------------------------------------------------------------------*/
00008 
00009 
00010 #ifndef STK_MESH_DATA_TRAITS_HPP
00011 #define STK_MESH_DATA_TRAITS_HPP
00012 
00013 #include <cstddef>
00014 #include <iosfwd>
00015 #include <typeinfo>
00016 #include <vector>
00017 #include <string>
00018 #include <complex>
00019 
00020 #include <stk_util/parallel/ParallelComm.hpp>
00021 
00022 namespace stk {
00023 namespace mesh {
00024 
00025 class DataTraits ;
00026 
00027 //----------------------------------------------------------------------
00029 template< typename T > const DataTraits & data_traits();
00030  
00032 template< typename T >
00033 inline
00034 const DataTraits & data_traits( const T & ) { return data_traits<T>(); }
00035 
00036 //----------------------------------------------------------------------
00037 // Data traits for the fundamental computational data types:
00038 
00039 template<> const DataTraits & data_traits< void >();
00040 template<> const DataTraits & data_traits< signed   char >();
00041 template<> const DataTraits & data_traits< unsigned char >();
00042 template<> const DataTraits & data_traits< signed   short >();
00043 template<> const DataTraits & data_traits< unsigned short >();
00044 template<> const DataTraits & data_traits< signed   int >();
00045 template<> const DataTraits & data_traits< unsigned int >();
00046 template<> const DataTraits & data_traits< signed   long >();
00047 template<> const DataTraits & data_traits< unsigned long >();
00048 template<> const DataTraits & data_traits< float >();
00049 template<> const DataTraits & data_traits< double >();
00050 template<> const DataTraits & data_traits< std::complex<float> >();
00051 template<> const DataTraits & data_traits< std::complex<double> >();
00052 
00053 template<> const DataTraits & data_traits< void * >();
00054 template<> const DataTraits & data_traits< signed   char * >();
00055 template<> const DataTraits & data_traits< unsigned char * >();
00056 template<> const DataTraits & data_traits< signed   short * >();
00057 template<> const DataTraits & data_traits< unsigned short * >();
00058 template<> const DataTraits & data_traits< signed   int * >();
00059 template<> const DataTraits & data_traits< unsigned int * >();
00060 template<> const DataTraits & data_traits< signed   long * >();
00061 template<> const DataTraits & data_traits< unsigned long * >();
00062 template<> const DataTraits & data_traits< float * >();
00063 template<> const DataTraits & data_traits< double * >();
00064 template<> const DataTraits & data_traits< std::complex<float> * >();
00065 template<> const DataTraits & data_traits< std::complex<double> * >();
00066 
00067 //----------------------------------------------------------------------
00068 
00069 class DataTraits {
00070 public:
00071   //------------------------------
00072   // Standard properties:
00073   const std::type_info & type_info ;
00074   std::size_t            size_of ;
00075  
00076   //------------------------------
00077   // TR1 primary type categories:
00078   bool         is_void ;
00079   bool         is_integral ;
00080   bool         is_floating_point ;
00081   bool         is_array ;
00082   bool         is_pointer ;
00083   bool         is_enum ;
00084   bool         is_class ;
00085 
00086   // TR1 type properties:
00087   bool         is_pod ;
00088   bool         is_signed ;     // only if 'is_integral'
00089   bool         is_unsigned ;   // only if 'is_integral'
00090   std::size_t  alignment_of ;
00091 
00092   // For memory management contiguous arrays of data:
00093   // Array must start aligned with 'alignment_of' and
00094   // stride by 'stride_of'.
00095   std::size_t  stride_of ;
00096 
00097   // TR1 type manipulators:
00098   const DataTraits * remove_pointer ; // if 'is_pointer'
00099  
00100   //------------------------------
00102   std::string  name ;
00103  
00104   //------------------------------
00105   // Only If 'is_enum'
00106   struct EnumMember {
00107     std::string  name ;
00108     long         value ;
00109   };
00110   std::vector< EnumMember > enum_info ;
00111  
00112   //------------------------------
00113   // Only If 'is_class':
00114   struct ClassMember {
00115     std::string        name ;
00116     const DataTraits * traits ;
00117     std::size_t        offset ;
00118   };
00119   std::vector< ClassMember > class_info ;
00120  
00121   //------------------------------
00122   // Functions required for all field data:
00123 
00124   virtual void construct( void * , std::size_t ) const  = 0 ;
00125   virtual void destroy(   void * , std::size_t ) const  = 0 ;
00126   virtual void copy( void * , const void * , std::size_t ) const  = 0 ;
00127   virtual void pack(   CommBuffer & , const void * , std::size_t ) const  = 0 ;
00128   virtual void unpack( CommBuffer & ,       void * , std::size_t ) const  = 0 ;
00129   virtual void print( std::ostream & , const void * , std::size_t ) const  = 0 ;
00130 
00131   //------------------------------
00132   // Commutative and associative ops
00133   // required for is_integral and is_floating_point data.
00134   // In-place reduction: x[0..(n-1)] op= y[0..(n-1)]
00135   virtual void sum( void * x , const void * y , std::size_t n ) const = 0 ;
00136   virtual void max( void * x , const void * y , std::size_t n ) const = 0 ;
00137   virtual void min( void * x , const void * y , std::size_t n ) const = 0 ;
00138 
00139   // Commutative and associative ops
00140   // required for is_integral data.
00141   // In-place reduction: x[0..(n-1)] op= y[0..(n-1)]
00142   virtual void bit_and( void * x , const void * y, std::size_t n ) const = 0 ;
00143   virtual void bit_or(  void * x , const void * y, std::size_t n ) const = 0 ;
00144   virtual void bit_xor( void * x , const void * y, std::size_t n ) const = 0 ;
00145 
00146   //------------------------------
00147 
00148 protected:
00149 
00150   //------------------------------
00152   DataTraits( const std::type_info & arg_type ,
00153               const char * const     arg_name ,
00154               const std::size_t      arg_size ,
00155               const std::size_t      arg_align );
00156  
00158   DataTraits( const std::type_info & arg_type , const DataTraits & );
00159 
00160   virtual ~DataTraits();
00161 private:
00162   DataTraits();
00163   DataTraits( const DataTraits & );
00164   DataTraits & operator = ( const DataTraits & );
00165 };
00166 
00167 } // namespace mesh
00168 } // namespace stk
00169 
00170 #endif
00171 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends