filesystem_impl.hpp
1 /*
2  * This file is part of CasADi.
3  *
4  * CasADi -- A symbolic framework for dynamic optimization.
5  * Copyright (C) 2010-2023 Joel Andersson, Joris Gillis, Moritz Diehl,
6  * KU Leuven. All rights reserved.
7  * Copyright (C) 2011-2014 Greg Horn
8  *
9  * CasADi is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * CasADi is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with CasADi; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 
26 #ifndef CASADI_FILESYSTEM_IMPL_HPP
27 #define CASADI_FILESYSTEM_IMPL_HPP
28 
29 #include "filesystem.hpp"
30 #include "plugin_interface.hpp"
31 
33 namespace casadi {
34 
44  class CASADI_EXPORT
45  Filesystem : public PluginInterface<Filesystem> {
46  public:
47  typedef bool (* IsDirectory)(const std::string& path);
48  typedef bool (* CreateDirectories)(const std::string& path);
49  typedef bool (* Remove)(const std::string& path);
50  typedef casadi_int (* RemoveAll)(const std::string& path);
51  typedef std::string (* Filename)(const std::string& path);
52  typedef bool (* HasParentPath)(const std::string& path);
53  typedef std::string (* ParentPath)(const std::string& path);
54  typedef std::vector<std::string> (* IterateDirectoryNames)(const std::string& path);
55  typedef std::string (* Absolute)(const std::string& path);
56 
57  // Creator function for internal class
58  typedef Filesystem* (*Creator)();
59 
60  static const std::string meta_doc;
61 
62  // No static functions exposed
63  struct Exposed{
64  IsDirectory is_directory;
65  CreateDirectories create_directories;
66  Remove remove;
67  RemoveAll remove_all;
68  Filename filename;
69  HasParentPath has_parent_path;
70  ParentPath parent_path;
71  IterateDirectoryNames iterate_directory_names;
72  Absolute absolute;
73  };
74 
76  static std::map<std::string, Plugin> solvers_;
77 
78  static void assert_enabled();
79  static bool is_directory(const std::string& path);
80  static bool remove(const std::string& path);
81  static casadi_int remove_all(const std::string& path);
82  static std::string filename(const std::string& path);
83  static bool is_enabled();
84  static bool has_parent_path(const std::string& path);
85  static std::string parent_path(const std::string& path);
86  static std::string absolute(const std::string& path);
87  static bool ensure_directory_exists(const std::string& path);
88  static bool create_directories(const std::string& path);
89  static std::vector<std::string> iterate_directory_names(const std::string& path);
90 
91 
92  static void open(std::ofstream&, const std::string& path,
93  std::ios_base::openmode mode = std::ios_base::out);
94 
95  static std::ofstream* ofstream_ptr(const std::string& path,
96  std::ios_base::openmode mode = std::ios_base::out);
97 
98 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
99  static std::mutex mutex_solvers_;
100 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
101 
103  static const std::string infix_;
104  };
105 
106 } // namespace casadi
107 
109 
110 #endif // CASADI_FILESYSTEM_IMPL_HPP
The casadi namespace.
Definition: archiver.hpp:32