dune-grid  2.11
filereader.hh
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
2 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3 
4 #ifndef DUNE_GRID_IO_FILE_GMSH_FILEREADER_HH
5 #define DUNE_GRID_IO_FILE_GMSH_FILEREADER_HH
6 
7 #include <memory>
8 #include <string>
9 #include <utility>
10 
11 #include <dune/common/exceptions.hh>
13 
14 namespace Dune::Impl::Gmsh
15 {
16  template <class Grid, class FilerReaderImp>
17  class FileReader
18  {
19  private:
20  // type of underlying implementation, for internal use only
21  using Implementation = FilerReaderImp;
22 
24  struct Accessor : public Implementation
25  {
26  template <class ... Args>
27  static std::unique_ptr<Grid> createGridFromFileImpl (Args&&... args)
28  {
29  return Implementation::createGridFromFileImpl(std::forward<Args>(args)...);
30  }
31 
32  template <class ... Args>
33  static void fillFactoryImpl (Args&&... args)
34  {
35  return Implementation::fillFactoryImpl(std::forward<Args>(args)...);
36  }
37  };
38 
39  public:
42  template <class ... Args>
43  static std::unique_ptr<Grid> createGridFromFile (const std::string &filename, Args&&... args)
44  {
45  return Accessor::createGridFromFileImpl(filename, std::forward<Args>(args)...);
46  }
47 
50  template <class ... Args>
51  static void fillFactory (GridFactory<Grid> &factory, const std::string &filename, Args&&... args)
52  {
53  Accessor::fillFactoryImpl(factory, filename, std::forward<Args>(args)...);
54  }
55 
56  protected: // default implementations
57 
58  // Default implementation, redirects to factory read implementation.
59  template <class ... Args>
60  static std::unique_ptr<Grid> createGridFromFileImpl (const std::string &filename, Args&&... args)
61  {
62  GridFactory<Grid> factory;
63  fillFactory(factory, filename, std::forward<Args>(args)...);
64 
65  return std::unique_ptr<Grid>{ factory.createGrid() };
66  }
67 
68  // Default implementation for reading into grid-factory: produces a runtime-error.
69  template <class ... Args>
70  static void fillFactoryImpl (GridFactory<Grid> & /*factory*/, const std::string & /*filename*/,
71  Args&&... /*args*/)
72  {
73  DUNE_THROW(NotImplemented,
74  "GridReader using a factory argument not implemented for concrete reader implementation.");
75  }
76  };
77 
78 } // end namespace Dune::Impl::Gmsh
79 
80 #endif
Provide a generic factory class for unstructured grids.
Definition: filereader.hh:14