User Guide
file_library.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2023 Blue Brain Project, EPFL.
3  * See the top-level LICENSE file for details.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #pragma once
9 
10 #include <filesystem>
11 #include <string>
12 #include <vector>
13 
14 /**
15  *
16  * \dir
17  * \brief Utility classes and function
18  *
19  * \file
20  * \brief Manage search path.
21  */
22 
23 namespace nmodl {
24 
25 /**
26  * \brief Manage search path.
27  *
28  * Store search path used for handling paths when processing include NMODL directive
29  */
30 class FileLibrary {
31  public:
32  /// An empty library
33  FileLibrary() = default;
34  /**
35  * Initialize the library with the following path:
36  * - current working directory
37  * - paths in the NMODL_PATH environment variable
38  */
40 
41  /**
42  * \name Managing inclusion paths.
43  * \{
44  */
45  void append_env_var(const std::string& env_var);
46  /** \} */
47 
48  /**
49  * \name current directory
50  * \{
51  */
52  void push_current_directory(const std::filesystem::path& path);
53  void pop_current_directory();
54  /** \} */
55 
56  /**
57  * \brief Search a file.
58  * Determine real path of \a file
59  * \return Directory containing \a file, or "" if not found.
60  */
61  std::string find_file(const std::filesystem::path& file);
62 
63  private:
64  /// push the working directory in the directories stack
65  void push_cwd();
66 
67  /// inclusion path list
68  std::vector<std::filesystem::path> paths_;
69 };
70 
71 } // namespace nmodl
nmodl::FileLibrary::append_env_var
void append_env_var(const std::string &env_var)
Definition: file_library.cpp:28
nmodl::FileLibrary::find_file
std::string find_file(const std::filesystem::path &file)
Search a file.
Definition: file_library.cpp:54
nmodl::FileLibrary::push_current_directory
void push_current_directory(const std::filesystem::path &path)
Definition: file_library.cpp:39
nmodl::FileLibrary::paths_
std::vector< std::filesystem::path > paths_
inclusion path list
Definition: file_library.hpp:68
nmodl
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
nmodl::FileLibrary::FileLibrary
FileLibrary()=default
An empty library.
nmodl::FileLibrary::pop_current_directory
void pop_current_directory()
Definition: file_library.cpp:47
nmodl::FileLibrary::default_instance
static FileLibrary default_instance()
Initialize the library with the following path:
Definition: file_library.cpp:21
nmodl::FileLibrary
Manage search path.
Definition: file_library.hpp:30
nmodl::FileLibrary::push_cwd
void push_cwd()
push the working directory in the directories stack
Definition: file_library.cpp:43