Dune Core Modules (2.6.0)

datahandleif.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_DATAHANDLEIF_HH
4 #define DUNE_DATAHANDLEIF_HH
5 
13 
14 namespace Dune
15 {
16 
29  template <class MessageBufferImp>
31  {
32  MessageBufferImp & buff_;
33  public:
35  MessageBufferIF(MessageBufferImp & buff) : buff_(buff) {}
36 
42  template <class T>
43  void write(const T & val)
44  {
45  buff_.write(val);
46  }
47 
56  template <class T>
57  void read(T & val)
58  {
59  buff_.read(val);
60  }
61  }; // end class MessageBufferIF
62 
63 
74  template <class DataHandleImp, class DataTypeImp>
76  {
77  public:
79  typedef DataTypeImp DataType;
80 
81  protected:
82  // one should not create an explicit instance of this interface object
83  CommDataHandleIF() {}
84 
85  public:
91  bool contains (int dim, int codim) const
92  {
93  CHECK_INTERFACE_IMPLEMENTATION((asImp().contains(dim,codim)));
94  return asImp().contains(dim,codim);
95  }
96 
107  bool fixedsize (int dim, int codim) const
108  {
110  auto derPtr = &DataHandleImp::fixedSize;
111  bool hasOverwrittenFixedSize = basePtr != derPtr;
112  if (hasOverwrittenFixedSize)
113  return asImp().fixedSize(dim,codim);
114  else
115  return asImp().fixedsize(dim,codim);
116  }
117 
126  bool fixedSize (int dim, int codim) const
127  {
129  auto derPtr = &DataHandleImp::fixedSize;
130  bool hasOverwrittenFixedSize = basePtr != derPtr;
131  if (hasOverwrittenFixedSize)
132  return asImp().fixedSize(dim,codim);
133  else
134  return asImp().fixedsize(dim,codim);
135  }
136 
141  template<class EntityType>
142  size_t size (const EntityType& e) const
143  {
144  CHECK_INTERFACE_IMPLEMENTATION((asImp().size(e)));
145  return asImp().size(e);
146  }
147 
152  template<class MessageBufferImp, class EntityType>
153  void gather (MessageBufferImp& buff, const EntityType& e) const
154  {
156  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION((asImp().gather(buffIF,e)));
157  }
158 
166  template<class MessageBufferImp, class EntityType>
167  void scatter (MessageBufferImp& buff, const EntityType& e, size_t n)
168  {
170  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION((asImp().scatter(buffIF,e,n)));
171  }
172 
173  private:
175  DataHandleImp& asImp () {return static_cast<DataHandleImp &> (*this);}
177  const DataHandleImp& asImp () const
178  {
179  return static_cast<const DataHandleImp &>(*this);
180  }
181  }; // end class CommDataHandleIF
182 
183 #undef CHECK_INTERFACE_IMPLEMENTATION
184 #undef CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
185 
186 } // end namespace Dune
187 #endif
Provides check for implementation of interface methods when using static polymorphism,...
#define CHECK_AND_CALL_INTERFACE_IMPLEMENTATION(__interface_method_to_call__)
Definition: bartonnackmanifcheck.hh:59
CommDataHandleIF describes the features of a data handle for communication in parallel runs using the...
Definition: datahandleif.hh:76
bool fixedsize(int dim, int codim) const
returns true if size of data per entity of given dim and codim is a constant
Definition: datahandleif.hh:107
void scatter(MessageBufferImp &buff, const EntityType &e, size_t n)
unpack data from message buffer to user.
Definition: datahandleif.hh:167
bool contains(int dim, int codim) const
returns true if data for given valid codim should be communicated
Definition: datahandleif.hh:91
size_t size(const EntityType &e) const
how many objects of type DataType have to be sent for a given entity
Definition: datahandleif.hh:142
void gather(MessageBufferImp &buff, const EntityType &e) const
pack data from user to message buffer
Definition: datahandleif.hh:153
bool fixedSize(int dim, int codim) const
returns true if size of data per entity of given dim and codim is a constant
Definition: datahandleif.hh:126
DataTypeImp DataType
data type of data to communicate
Definition: datahandleif.hh:79
Communication message buffer interface. This class describes the interface for reading and writing da...
Definition: datahandleif.hh:31
MessageBufferIF(MessageBufferImp &buff)
stores reference to original buffer buff
Definition: datahandleif.hh:35
void write(const T &val)
just wraps the call of the internal buffer method write which writes the data of type T from the buff...
Definition: datahandleif.hh:43
void read(T &val)
just wraps the call of the internal buffer method read which reads the data of type T from the buffer...
Definition: datahandleif.hh:57
Dune namespace.
Definition: alignedallocator.hh:10
std::size_t fixedSize
The number of data items per index if it is fixed, 0 otherwise.
Definition: variablesizecommunicator.hh:245
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (Apr 19, 22:31, 2024)