Molecular Dynamics Simulation  1.0
FileReader.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <optional>
4 #include <string>
5 #include <tuple>
6 #include <vector>
7 
8 #include "particles/Particle.h"
10 
14 class FileReader {
15  public:
19  virtual ~FileReader() = default;
20 
25  [[nodiscard]] virtual std::tuple<std::vector<Particle>, std::optional<SimulationParams>> readFile(
26  const std::filesystem::path& filepath) const = 0;
27 
31  class FileFormatException : public std::exception {
32  public:
33  explicit FileFormatException(std::string message) : message_(std::move(message)) {}
34 
35  [[nodiscard]] const char* what() const noexcept override { return message_.c_str(); }
36 
37  private:
38  std::string message_;
39  };
40 };
Exception to be thrown when the file format is invalid.
Definition: FileReader.h:31
FileFormatException(std::string message)
Definition: FileReader.h:33
const char * what() const noexcept override
Definition: FileReader.h:35
Abstract base class for all custom file readers.
Definition: FileReader.h:14
virtual std::tuple< std::vector< Particle >, std::optional< SimulationParams > > readFile(const std::filesystem::path &filepath) const =0
Reads the file with the given path and returns a vector of particles.
virtual ~FileReader()=default
virtual destructor for correct cleanup of derived classes