dune-vtk  0.2
filereader.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <string>
5 #include <utility>
6 
7 #include <dune/common/exceptions.hh>
8 #include <dune/grid/common/gridfactory.hh>
9 
10 namespace Dune
11 {
12  namespace Vtk
13  {
14  template <class Grid, class FilerReaderImp>
15  class FileReader
16  {
17  private:
18  // type of underlying implementation, for internal use only
19  using Implementation = FilerReaderImp;
20 
22  struct Accessor : public Implementation
23  {
24  template <class... Args>
25  static std::unique_ptr<Grid> createGridFromFileImpl (Args&&... args)
26  {
27  return Implementation::createGridFromFileImpl(std::forward<Args>(args)...);
28  }
29 
30  template <class... Args>
31  static void fillFactoryImpl (Args&&... args)
32  {
33  return Implementation::fillFactoryImpl(std::forward<Args>(args)...);
34  }
35  };
36 
37  public:
40  template <class... Args>
41  static std::unique_ptr<Grid> createGridFromFile (const std::string &filename, Args&&... args)
42  {
43  return Accessor::createGridFromFileImpl(filename, std::forward<Args>(args)...);
44  }
45 
48  template <class... Args>
49  static void fillFactory (GridFactory<Grid> &factory,
50  const std::string &filename,
51  Args&&... args)
52  {
53  Accessor::fillFactoryImpl(factory, filename, std::forward<Args>(args)...);
54  }
55 
56  protected: // default implementations
57 
58  // Default implementation, redirects to fillFactory implementation.
59  template <class... Args>
60  static std::unique_ptr<Grid> createGridFromFileImpl (const std::string &filename,
61  Args&&... args)
62  {
63  GridFactory<Grid> factory;
64  fillFactory(factory, filename, std::forward<Args>(args)...);
65 
66  return std::unique_ptr<Grid>{ factory.createGrid() };
67  }
68 
69  // Default implementation for reading into grid-factory: produces a runtime-error.
70  template <class... Args>
71  static void fillFactoryImpl (GridFactory<Grid> &/*factory*/,
72  const std::string &/*filename*/,
73  Args&&... /*args*/)
74  {
75  DUNE_THROW(NotImplemented,
76  "GridReader using a factory argument not implemented for concrete reader implementation.");
77  }
78  };
79 
80  } // end namespace Vtk
81 } // end namespace Dune
Definition: datacollectorinterface.hh:9
Definition: filereader.hh:16
static void fillFactoryImpl(GridFactory< Grid > &, const std::string &, Args &&...)
Definition: filereader.hh:71
static std::unique_ptr< Grid > createGridFromFileImpl(const std::string &filename, Args &&... args)
Definition: filereader.hh:60
static void fillFactory(GridFactory< Grid > &factory, const std::string &filename, Args &&... args)
Definition: filereader.hh:49
static std::unique_ptr< Grid > createGridFromFile(const std::string &filename, Args &&... args)
Definition: filereader.hh:41