Dune Core Modules (2.9.0)

datahandleif.hh
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
2 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 // vi: set et ts=4 sw=2 sts=2:
5 #ifndef DUNE_GRID_COMMON_DATAHANDLEIF_HH
6 #define DUNE_GRID_COMMON_DATAHANDLEIF_HH
7 
15 
16 namespace Dune
17 {
18 
31  template <class MessageBufferImp>
33  {
34  MessageBufferImp & buff_;
35  public:
37  MessageBufferIF(MessageBufferImp & buff) : buff_(buff) {}
38 
44  template <class T>
45  void write(const T & val)
46  {
47  buff_.write(val);
48  }
49 
58  template <class T>
59  void read(T & val)
60  {
61  buff_.read(val);
62  }
63  }; // end class MessageBufferIF
64 
65 
76  template <class DataHandleImp, class DataTypeImp>
78  {
79  template <class M>
80  class CheckFixedSizeMethod
81  {
82  // check for old signature of deprecated fixedsize method.
83  template <class T>
84  static std::true_type testSignature(bool (T::*)(int, int) const);
85 
86  template <class T>
87  static decltype(testSignature(&T::fixedsize)) test(std::nullptr_t);
88 
89  template <class T>
90  static std::false_type test(...);
91 
92  using type = decltype(test<M>(nullptr));
93  public:
94  static const bool value = type::value;
95  };
96 
97 
98  template <class DH, bool>
99  struct CallFixedSize
100  {
101  static bool fixedSize( const DH& dh, int dim, int codim )
102  {
103  return dh.fixedSize( dim, codim );
104  }
105  };
106 
107  // old, deprecated implementation
108  template <class DH>
109  struct CallFixedSize< DH, true >
110  {
111  static bool fixedSize( const DH& dh, int dim, int codim )
112  {
113  return dh.overloaded_deprecated_fixedsize( dim, codim );
114  }
115  };
116 
117  public:
119  typedef DataTypeImp DataType;
120 
121  protected:
122  // one should not create an explicit instance of this interface object
123  CommDataHandleIF() {}
124 
125  public:
131  bool contains (int dim, int codim) const
132  {
133  CHECK_INTERFACE_IMPLEMENTATION((asImp().contains(dim,codim)));
134  return asImp().contains(dim,codim);
135  }
136 
147  [[deprecated("fixedsize (lower case s) will be removed after release 2.8. Implement and call fixedSize (camelCase) instead!")]]
148  int fixedsize (int dim, int codim) const
149  {
150  return int(fixedSize( dim, codim ));
151  }
152 
153  // if this deprecation appears then the DataHandle implementation
154  // is overloaded in the old 'fixedsize' method but not the new 'fixedSize'
155  // method.
156  [[deprecated("fixedsize (lower case s) will be removed after release 2.8. Implement and call fixedSize (camelCase) instead!")]]
157  bool overloaded_deprecated_fixedsize( int dim, int codim ) const
158  {
159  return asImp().fixedsize( dim, codim );
160  }
161 
169  bool fixedSize (int dim, int codim) const
170  {
171  // this should be enabled once the old fixedsize is removed
172  //CHECK_INTERFACE_IMPLEMENTATION((asImp().fixedSize(dim,codim)));
173  return CallFixedSize< DataHandleImp,
174  CheckFixedSizeMethod< DataHandleImp >::value >::fixedSize( asImp(), dim, codim );
175  }
176 
181  template<class EntityType>
182  size_t size (const EntityType& e) const
183  {
184  CHECK_INTERFACE_IMPLEMENTATION((asImp().size(e)));
185  return asImp().size(e);
186  }
187 
192  template<class MessageBufferImp, class EntityType>
193  void gather (MessageBufferImp& buff, const EntityType& e) const
194  {
196  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION((asImp().gather(buffIF,e)));
197  }
198 
206  template<class MessageBufferImp, class EntityType>
207  void scatter (MessageBufferImp& buff, const EntityType& e, size_t n)
208  {
210  CHECK_AND_CALL_INTERFACE_IMPLEMENTATION((asImp().scatter(buffIF,e,n)));
211  }
212 
213  private:
215  DataHandleImp& asImp () {return static_cast<DataHandleImp &> (*this);}
217  const DataHandleImp& asImp () const
218  {
219  return static_cast<const DataHandleImp &>(*this);
220  }
221  }; // end class CommDataHandleIF
222 
223 #undef CHECK_INTERFACE_IMPLEMENTATION
224 #undef CHECK_AND_CALL_INTERFACE_IMPLEMENTATION
225 
226 } // end namespace Dune
227 #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:61
CommDataHandleIF describes the features of a data handle for communication in parallel runs using the...
Definition: datahandleif.hh:78
void scatter(MessageBufferImp &buff, const EntityType &e, size_t n)
unpack data from message buffer to user.
Definition: datahandleif.hh:207
int 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:148
bool contains(int dim, int codim) const
returns true if data for given valid codim should be communicated
Definition: datahandleif.hh:131
size_t size(const EntityType &e) const
how many objects of type DataType have to be sent for a given entity
Definition: datahandleif.hh:182
void gather(MessageBufferImp &buff, const EntityType &e) const
pack data from user to message buffer
Definition: datahandleif.hh:193
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:169
DataTypeImp DataType
data type of data to communicate
Definition: datahandleif.hh:119
Communication message buffer interface. This class describes the interface for reading and writing da...
Definition: datahandleif.hh:33
MessageBufferIF(MessageBufferImp &buff)
stores reference to original buffer buff
Definition: datahandleif.hh:37
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:45
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:59
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 5, 22:29, 2024)