Loading...
Searching...
No Matches
File.h
// Copyright (C) 2002-2012 Johan Hoffman, Anders Logg and Garth N. Wells
//
// This file is part of DOLFIN.
//
// DOLFIN is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// DOLFIN is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
#ifndef __FILE_H
#define __FILE_H
#include <memory>
#include <ostream>
#include <string>
#include <utility>
#include <dolfin/common/MPI.h>
#include "GenericFile.h"
namespace dolfin
{
class File
{
public:
enum class Type {x3d, xml, vtk, raw, xyz, binary, svg};
File(const std::string filename, std::string encoding="ascii");
File(MPI_Comm comm, const std::string filename,
std::string encoding="ascii");
File(const std::string filename, Type type, std::string encoding="ascii");
File(MPI_Comm comm, const std::string filename, Type type,
std::string encoding="ascii");
File(std::ostream& outstream);
~File();
template<typename T> void operator>>(T& t)
{
_file->_read();
_file->read(t);
}
template<typename T> void read(T& t)
{
_file->_read();
_file->read(t);
}
void operator<<(const std::pair<const Mesh*, double> mesh);
void operator<<(const std::pair<const MeshFunction<int>*, double> f);
void operator<<
(const std::pair<const MeshFunction<std::size_t>*, double> f);
void operator<< (const std::pair<const MeshFunction<double>*, double> f);
void operator<<(const std::pair<const MeshFunction<bool>*, double> f);
void operator<<(const std::pair<const Function*, double> u);
template<typename X>
void operator<<(const X& x)
{
_file->_write(_mpi_comm.rank());
_file->write(x);
}
template<typename X>
void write(const X& x)
{
_file->_write(_mpi_comm.rank());
_file->write(x);
}
template<typename X>
void write(const X& x, double time)
{
_file->_write(_mpi_comm.rank());
_file->write(x, time);
}
static bool exists(std::string filename);
// Create parent path for file if file has a parent path
static void create_parent_path(std::string filename);
private:
// Initialise GenericFile (using file extension to determine type)
void init(MPI_Comm comm, const std::string filename, std::string encoding);
// Initialise GenericFile (with specified type)
void init(MPI_Comm comm, const std::string filename, Type type,
std::string encoding);
// FIXME: Remove when GenericFile::write is cleaned up
// MPI communicator
dolfin::MPI::Comm _mpi_comm;
// Pointer to implementation (envelope-letter design)
std::unique_ptr<GenericFile> _file;
};
}
#endif
dolfin::File::write
void write(const X &x)
Write object to file.
Definition File.h:236
dolfin::File::read
void read(T &t)
Read from file.
Definition File.h:159
dolfin::File::create_parent_path
static void create_parent_path(std::string filename)
Definition File.cpp:121
dolfin::File::operator<<
void operator<<(const X &x)
Write object to file.
Definition File.h:228
dolfin::File::exists
static bool exists(std::string filename)
Definition File.cpp:109
dolfin::File::operator>>
void operator>>(T &t)
Read from file.
Definition File.h:152
dolfin::File::File
File(const std::string filename, std::string encoding="ascii")
Definition File.cpp:38
dolfin::File::write
void write(const X &x, double time)
Write object to file with time.
Definition File.h:244
dolfin::File::~File
~File()
Destructor.
Definition File.cpp:67
dolfin::File::operator<<
void operator<<(const std::pair< const Mesh *, double > mesh)
Definition File.cpp:72
dolfin::File::Type
Type
File formats.
Definition File.h:50
dolfin::MPI::Comm
Definition MPI.h:77
dolfin::MeshFunction
Definition MeshFunction.h:58
dolfin
Definition adapt.h:30
dolfin::time
double time()
Return wall time elapsed since some implementation dependent epoch.
Definition timing.cpp:48
dolfin::init
void init(int argc, char *argv[])
Definition init.cpp:27