Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / include / xbt / file.hpp
1 /* Copyright (c) 2017-2023. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef XBT_FILE_HPP
7 #define XBT_FILE_HPP
8
9 #include <string>
10 #include <vector>
11 #include <xbt/base.h>
12
13 namespace simgrid::xbt {
14
15 void path_push(std::string const& str);
16 void path_pop();
17 FILE* path_fopen(const std::string& name, const char* mode);
18 std::ifstream* path_ifsopen(const std::string& name);
19 std::string path_to_string();
20
21 class Path {
22 public:
23   /** Build a path from the current working directory (CWD) */
24   explicit Path();
25   /** Build a path from the provided parameter */
26   explicit Path(const char* path): path_(path) {}
27   /** Build a path from the provided parameter */
28   explicit Path(const std::string& path) : path_(path) {}
29
30   /** @brief Returns the full path name */
31   const std::string& get_name() const { return path_; }
32   /** @brief Returns the directory component of a path (reimplementation of POSIX dirname) */
33   std::string get_dir_name() const;
34   /** @brief Returns the file component of a path (reimplementation of POSIX basename) */
35   std::string get_base_name() const;
36
37 private:
38   std::string path_;
39 };
40 } // namespace simgrid::xbt
41
42 #endif                          /* XBT_FILE_HPP */