MARLEY (Model of Argon Reaction Low Energy Yields)  v1.2.0
A Monte Carlo event generator for tens-of-MeV neutrino interactions
FileManager.hh
1 //
5 // This file is part of MARLEY (Model of Argon Reaction Low Energy Yields)
6 //
7 // MARLEY is free software: you can redistribute it and/or modify it under the
8 // terms of version 3 of the GNU General Public License as published by the
9 // Free Software Foundation.
10 //
11 // For the full text of the license please see COPYING or
12 // visit http://opensource.org/licenses/GPL-3.0
13 //
14 // Please respect the MCnet academic usage guidelines. See GUIDELINES
15 // or visit https://www.montecarlonet.org/GUIDELINES for details.
16 
17 #pragma once
18 #include <functional>
19 #include <string>
20 #include <vector>
21 
22 namespace marley {
23 
25  class FileManager {
26 
27  public:
28 
30  FileManager(const FileManager&) = delete;
31 
33  FileManager(FileManager&&) = delete;
34 
36  FileManager& operator=(const FileManager&) = delete;
37 
40 
43  static const FileManager& Instance();
44 
51  static std::vector<std::string> search_path_to_dir_vector(
52  const std::string& search_path = FileManager::default_search_path_);
53 
63  std::string find_file(const std::string& base_name,
64  const std::vector<std::string>& search_dirs) const;
65 
75  std::string find_file(const std::string& base_name,
76  const std::string& search_path
78 
87  std::vector<std::string> list_all_files(
88  const std::vector<std::string>& search_dirs) const;
89 
98  std::vector<std::string> list_all_files(
99  const std::string& search_path
101 
103  inline std::string marley_dir() const { return marley_dir_; }
104 
105  protected:
106 
108  FileManager();
109 
121  static bool dir_iterate(const std::string& dir_name,
122  const std::function<bool(const std::string&, const std::string&)>& func);
123 
125  static std::string default_search_path_;
126 
129  std::string marley_dir_;
130  };
131 
132 }
Singleton class that handles file searches.
Definition: FileManager.hh:25
std::string marley_dir() const
Returns the path to the root MARLEY folder.
Definition: FileManager.hh:103
std::string marley_dir_
Stores the value of the MARLEY environment variable (which points to the root folder of the source co...
Definition: FileManager.hh:129
FileManager()
Create the singleton FileManager object.
Definition: FileManager.cc:52
std::vector< std::string > list_all_files(const std::vector< std::string > &search_dirs) const
Get a vector of full paths for all regular files in the requested directories.
Definition: FileManager.cc:146
FileManager(FileManager &&)=delete
Deleted move constructor.
static std::string default_search_path_
By default, use this search path when looking for files.
Definition: FileManager.hh:125
FileManager(const FileManager &)=delete
Deleted copy constructor.
static std::vector< std::string > search_path_to_dir_vector(const std::string &search_path=FileManager::default_search_path_)
Converts a ':'-delimited search path (given as a single string) into a vector of directory names.
Definition: FileManager.cc:87
static bool dir_iterate(const std::string &dir_name, const std::function< bool(const std::string &, const std::string &)> &func)
Helper function that executes a std::function on the name of each regular file found while scanning t...
Definition: FileManager.cc:173
FileManager & operator=(FileManager &&)=delete
Deleted move assignment operator.
static const FileManager & Instance()
Get a const reference to the singleton instance of the FileManager.
Definition: FileManager.cc:76
FileManager & operator=(const FileManager &)=delete
Deleted copy assignment operator.
std::string find_file(const std::string &base_name, const std::vector< std::string > &search_dirs) const
Searches for a file in the given directories.
Definition: FileManager.cc:102