dune-grid
2.1.1
|
00001 #ifndef DUNE_DATAHANDLEIF_HH 00002 #define DUNE_DATAHANDLEIF_HH 00003 00010 #include <dune/common/bartonnackmanifcheck.hh> 00011 00012 namespace Dune 00013 { 00014 00029 template <class MessageBufferImp> 00030 class MessageBufferIF 00031 { 00032 MessageBufferImp & buff_; 00033 public: 00035 MessageBufferIF(MessageBufferImp & buff) : buff_(buff) {} 00036 00042 template <class T> 00043 void write(const T & val) 00044 { 00045 buff_.write(val); 00046 } 00047 00053 template <class T> 00054 void read(T & val) const 00055 { 00056 buff_.read(val); 00057 } 00058 }; // end class MessageBufferIF 00059 00060 00071 template <class DataHandleImp, class DataTypeImp> 00072 class CommDataHandleIF 00073 { 00074 public: 00076 typedef DataTypeImp DataType; 00077 00078 protected: 00079 // one should not create an explicit instance of this inteface object 00080 CommDataHandleIF() {} 00081 00082 public: 00088 bool contains (int dim, int codim) const 00089 { 00090 CHECK_INTERFACE_IMPLEMENTATION((asImp().contains(dim,codim))); 00091 return asImp().contains(dim,codim); 00092 } 00093 00099 bool fixedsize (int dim, int codim) const 00100 { 00101 CHECK_INTERFACE_IMPLEMENTATION((asImp().fixedsize(dim,codim))); 00102 return asImp().fixedsize(dim,codim); 00103 } 00104 00109 template<class EntityType> 00110 size_t size (const EntityType& e) const 00111 { 00112 CHECK_INTERFACE_IMPLEMENTATION((asImp().size(e))); 00113 return asImp().size(e); 00114 } 00115 00120 template<class MessageBufferImp, class EntityType> 00121 void gather (MessageBufferImp& buff, const EntityType& e) const 00122 { 00123 MessageBufferIF<MessageBufferImp> buffIF(buff); 00124 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION((asImp().gather(buffIF,e))); 00125 } 00126 00133 template<class MessageBufferImp, class EntityType> 00134 void scatter (MessageBufferImp& buff, const EntityType& e, size_t n) 00135 { 00136 MessageBufferIF<MessageBufferImp> buffIF(buff); 00137 CHECK_AND_CALL_INTERFACE_IMPLEMENTATION((asImp().scatter(buffIF,e,n))); 00138 } 00139 00140 private: 00142 DataHandleImp& asImp () {return static_cast<DataHandleImp &> (*this);} 00144 const DataHandleImp& asImp () const 00145 { 00146 return static_cast<const DataHandleImp &>(*this); 00147 } 00148 }; // end class CommDataHandleIF 00149 00150 #undef CHECK_INTERFACE_IMPLEMENTATION 00151 #undef CHECK_AND_CALL_INTERFACE_IMPLEMENTATION 00152 00153 } // end namespace Dune 00154 #endif