backuprestore.hh 2.61 KB
Newer Older
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_CRVSRF_BACKUPRESTORE_HH
#define DUNE_CRVSRF_BACKUPRESTORE_HH

#include <dune/grid/common/backuprestore.hh>

#include <dune/curvedsurfacegrid/capabilities.hh>

namespace Dune
{

  namespace crvsrf
  {

    // BackupRestoreFacilities
    // -----------------------

    template< class Grid, bool hasBackupRestoreFacilities = Capabilities::hasBackupRestoreFacilities< Grid > ::v >
    class BackupRestoreFacilities
    {};

    template< class Grid >
    class BackupRestoreFacilities< Grid, true >
    {
      typedef BackupRestoreFacilities< Grid, true > This;

    protected:
      BackupRestoreFacilities ()
      {}

    private:
      BackupRestoreFacilities ( const This & );
      This &operator= ( const This & );

    protected:
      const Grid &asImp () const
      {
        return static_cast< const Grid & >( *this );
      }

      Grid &asImp ()
      {
        return static_cast< Grid & >( *this );
      }
    };

  } // namespace crvsrf



  // BackupRestoreFacility for CurvedSurfaceGrid
  // -------------------------------------------

  template< class HostGrid, class CoordFunction, int order, class Allocator > //! $flo
  struct BackupRestoreFacility< CurvedSurfaceGrid< HostGrid, CoordFunction, order, Allocator > > //! $flo
  {
    typedef CurvedSurfaceGrid< HostGrid, CoordFunction, order, Allocator > Grid; //! $flo
    typedef BackupRestoreFacility< HostGrid > HostBackupRestoreFacility;

61
    static void backup ( const Grid &grid, const std::string &filename )
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
62
63
    {
      // notice: We should also backup the coordinate function
64
      HostBackupRestoreFacility::backup( grid.hostGrid(), filename );
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
65
66
67
68
69
70
71
72
    }

    static void backup ( const Grid &grid, const std::ostream &stream )
    {
      // notice: We should also backup the coordinate function
      HostBackupRestoreFacility::backup( grid.hostGrid(), stream );
    }

73
    static Grid *restore ( const std::string &filename )
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
74
75
    {
      // notice: We should also restore the coordinate function
76
      HostGrid *hostGrid = HostBackupRestoreFacility::restore( filename );
Stenger, Florian's avatar
v0.1.0  
Stenger, Florian committed
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
      CoordFunction *coordFunction = new CoordFunction();
      return new Grid( hostGrid, coordFunction );
    }

    static Grid *restore ( const std::istream &stream )
    {
      // notice: We should also restore the coordinate function
      HostGrid *hostGrid = HostBackupRestoreFacility::restore( stream );
      CoordFunction *coordFunction = new CoordFunction();
      return new Grid( hostGrid, coordFunction );
    }
  };

} // namespace Dune

#endif // #ifndef DUNE_CRVSRF_BACKUPRESTORE_HH