GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
IOManager.hpp
Go to the documentation of this file.
1 // This file is part of GranOO, a workbench for DEM simulation.
2 //
3 // Author(s) : - Damien Andre IRCER/UNILIM, Limoges France
4 // <damien.andre@unilim.fr>
5 // - Jean-luc Charles Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
6 // <jean-luc.charles@ensam.eu>
7 // - Jeremie Girardot Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
8 // <jeremie.girardot@ensam.eu>
9 // - Cedric Hubert LAMIH/UPHF, Valenciennes France
10 // <cedric.hubert@uphf.fr>
11 // - Ivan Iordanoff Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
12 // <ivan.iordanoff@ensam.eu>
13 // - Lucas Teixeira, RHI Magnesita, 8700 Leoben, Autriche
14 // <lucas.teixeira@rhimagnesita.com>
15 //
16 // Copyright (C) 2008-2022 D. Andre, JL. Charles, J. Girardot, C. Hubert, I. Iordanoff, L. Teixeira
17 //
18 // This program is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 // This program is distributed in the hope that it will be useful,
24 // but WITHOUT ANY WARRANTY; without even the implied warranty of
25 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 // GNU General Public License for more details.
27 //
28 // You should have received a copy of the GNU General Public License
29 // along with this program. If not, see <http://www.gnu.org/licenses/>.
30 
31 
32 #ifndef _libCore_IOManager_hpp_
33 #define _libCore_IOManager_hpp_
34 
35 
36 #include <iostream>
37 #include <string>
38 #include <map>
39 #include <vector>
40 
41 #include <boost/filesystem/path.hpp>
42 
43 namespace fs = boost::filesystem;
44 
45 //TODO define if the options will be passed at the creation of the problem or
46 //in the run method
47 //noNewDir and backupExecutableFile
48 namespace GranOO3
49 {
50  namespace Core
51  {
52 
53  class IOManager{
54  public:
55  static void fix_file_extension(std::string&, const std::string&);
56  static bool check_file_extension(const std::string&, const std::string&);
57  static void check_file_extension(std::string&, const std::string&, bool, bool);
58  static void convert_to_absolute_path(fs::path& path);
59  static void assert_file_exist(const fs::path&);
60  static void assert_directory_exist(const fs::path&);
61 
62 
63  public:
64  IOManager();
65 
66  // Input related methods
67  fs::path & get_input_file_path();
68  const std::string & get_input_file_name();
69  const std::string & get_input_file_content() const;
70  const std::string & get_input_file_extension() const;
71 
72  void set_input_file_path(std::string);
73  void set_input_file_substitution_pattern(const std::vector<std::string>&, const std::vector<std::string>&);
74  void set_input_file_content(const std::string&);
76 
77  // Output related methods
78  const fs::path & get_output_directory() const;
79  void set_output_directory(std::string& path);
80  void set_verbose(bool);
81  const bool get_verbose() const;
82  void set_backup_executable_file(bool);
83  const bool get_backup_executable_file() const;
84 
85  // Backup related methods
86  void make_backup(const std::string&);
87  void set_no_new_dir(bool);
88 
89  private:
90  void set_executable_filename(const std::string&);
92  void copy_input_file();
93  void copy_executable();
94  void assert_can_create_directory(const std::string&);
95 
96  private:
97  // Input file related variables
98  fs::path _inputFilePath;
99  std::string _inputFileName;
100  std::string _inputFileContent;
101  std::map<std::string, std::string> _inputFileSubstitutionPattern;
102  const std::string _inputFileExtension= ".inp";
103  const std::string _backupDirName = "backup";
104 
105  // Output file related variables
106  std::ofstream* _outputFile;
107  fs::path _outputFilePath;
109  bool _noNewDir;
111  bool _verbose;
112 
113  // Backup related variables
114  fs::path _executable;
116  std::vector<fs::path> _sampleFiles;
117 
118  };
119 
120  inline fs::path&
122  return _inputFilePath;
123  }
124 
125  inline const std::string&
127  return _inputFilePath.string();
128  }
129 
130  inline const std::string&
132  return _inputFileExtension;
133  }
134 
135  inline const std::string&
137  return _inputFileContent;
138  }
139 
140  inline const fs::path&
142  return _outputDirectory;
143  }
144 
145  inline const bool IOManager::get_verbose() const{
146  return _verbose;
147  }
148 
149  inline const bool
151  return _backupExecutableFile;
152  }
153  }
154 }
155 
156 
157 
158 #endif
Definition: IOManager.hpp:53
std::map< std::string, std::string > _inputFileSubstitutionPattern
Definition: IOManager.hpp:101
fs::path & get_input_file_path()
Definition: IOManager.hpp:121
void make_backup(const std::string &)
Definition: IOManager.cpp:140
std::string _inputFileName
Definition: IOManager.hpp:99
static bool check_file_extension(const std::string &, const std::string &)
Definition: IOManager.cpp:159
void set_backup_executable_file(bool)
Definition: IOManager.cpp:240
void apply_input_file_substitution_pattern()
Definition: IOManager.cpp:96
fs::path _backUpDirectory
Definition: IOManager.hpp:115
void set_no_new_dir(bool)
Definition: IOManager.cpp:148
fs::path _executable
Definition: IOManager.hpp:114
bool _backupExecutableFile
Definition: IOManager.hpp:110
const std::string & get_input_file_name()
Definition: IOManager.hpp:126
bool _noNewDir
Definition: IOManager.hpp:109
const fs::path & get_output_directory() const
Definition: IOManager.hpp:141
static void convert_to_absolute_path(fs::path &path)
Definition: IOManager.cpp:178
void set_executable_filename(const std::string &)
Definition: IOManager.cpp:208
void set_output_directory(std::string &path)
Definition: IOManager.cpp:112
const std::string & get_input_file_content() const
Definition: IOManager.hpp:136
const std::string & get_input_file_extension() const
Definition: IOManager.hpp:131
void set_input_file_content(const std::string &)
Definition: IOManager.cpp:69
void copy_executable()
Definition: IOManager.cpp:229
fs::path _outputFilePath
Definition: IOManager.hpp:107
std::string _inputFileContent
Definition: IOManager.hpp:100
void set_input_file_path(std::string)
Definition: IOManager.cpp:61
fs::path _inputFilePath
Definition: IOManager.hpp:98
const bool get_backup_executable_file() const
Definition: IOManager.hpp:150
static void assert_directory_exist(const fs::path &)
Definition: IOManager.cpp:191
void assert_can_create_directory(const std::string &)
Definition: IOManager.cpp:198
static void fix_file_extension(std::string &, const std::string &)
Definition: IOManager.cpp:153
const std::string _backupDirName
Definition: IOManager.hpp:103
void set_input_file_substitution_pattern(const std::vector< std::string > &, const std::vector< std::string > &)
Definition: IOManager.cpp:79
const bool get_verbose() const
Definition: IOManager.hpp:145
std::vector< fs::path > _sampleFiles
Definition: IOManager.hpp:116
fs::path _outputDirectory
Definition: IOManager.hpp:108
IOManager()
Definition: IOManager.cpp:51
bool _verbose
Definition: IOManager.hpp:111
void set_verbose(bool)
Definition: IOManager.cpp:235
std::ofstream * _outputFile
Definition: IOManager.hpp:106
void copy_input_file()
Definition: IOManager.cpp:221
void create_backup_directory()
Definition: IOManager.cpp:213
const std::string _inputFileExtension
Definition: IOManager.hpp:102
static void assert_file_exist(const fs::path &)
Definition: IOManager.cpp:184
Definition: Common.hpp:198