ghc.cpp
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 #include "ghc.hpp"
27 #include <ghc/filesystem.hpp>
28 
29 namespace casadi {
30 
31  bool is_directory(const std::string& path) {
32  return ghc::filesystem::is_directory(path);
33  }
34 
35  bool create_directories(const std::string& path) {
36  return ghc::filesystem::create_directories(path);
37  }
38 
39  std::vector<std::string> iterate_directory_names(const std::string& path) {
40  std::vector<std::string> ret;
41  for (const auto& entry : ghc::filesystem::directory_iterator(path)) {
42  ret.push_back(entry.path().string());
43  }
44  return ret;
45  }
46 
47  bool remove(const std::string& path) {
48  return ghc::filesystem::remove(path);
49  }
50 
51  casadi_int remove_all(const std::string& path) {
52  return ghc::filesystem::remove_all(path);
53  }
54 
55  std::string filename(const std::string& path) {
56  return ghc::filesystem::path(path).filename().string();
57  }
58 
59  std::string absolute(const std::string& path) {
60  return ghc::filesystem::absolute(ghc::filesystem::path(path)).string();
61  }
62 
63  std::string parent_path(const std::string& path) {
64  return ghc::filesystem::path(path).parent_path().string();
65  }
66 
67  bool has_parent_path(const std::string& path) {
68  return ghc::filesystem::path(path).has_parent_path();
69  }
70 
71  extern "C"
72  int CASADI_FILESYSTEM_GHC_EXPORT
73  casadi_register_filesystem_ghc(Filesystem::Plugin* plugin) {
74  plugin->name = "ghc";
75  plugin->doc = Ghc::meta_doc.c_str();
76  plugin->version = CASADI_VERSION;
77  plugin->exposed.is_directory = &is_directory;
78  plugin->exposed.create_directories = &create_directories;
79  plugin->exposed.remove = &remove;
80  plugin->exposed.remove_all = &remove_all;
81  plugin->exposed.filename = &filename;
82  plugin->exposed.has_parent_path = &has_parent_path;
83  plugin->exposed.parent_path = &parent_path;
84  plugin->exposed.iterate_directory_names = &iterate_directory_names;
85  plugin->exposed.absolute = &absolute;
86  return 0;
87  }
88 
89  extern "C"
90  void CASADI_FILESYSTEM_GHC_EXPORT casadi_load_filesystem_ghc() {
92  }
93 
94 
95 } // namespace casadi
static const std::string meta_doc
A documentation string.
Definition: ghc.hpp:54
static void registerPlugin(const Plugin &plugin, bool needs_lock=true)
Register an integrator in the factory.
The casadi namespace.
Definition: archiver.cpp:28
int CASADI_FILESYSTEM_GHC_EXPORT casadi_register_filesystem_ghc(Filesystem::Plugin *plugin)
Definition: ghc.cpp:73
std::string parent_path(const std::string &path)
Definition: ghc.cpp:63
std::vector< std::string > iterate_directory_names(const std::string &path)
Definition: ghc.cpp:39
void CASADI_FILESYSTEM_GHC_EXPORT casadi_load_filesystem_ghc()
Definition: ghc.cpp:90
std::string absolute(const std::string &path)
Definition: ghc.cpp:59
bool create_directories(const std::string &path)
Definition: ghc.cpp:35
bool has_parent_path(const std::string &path)
Definition: ghc.cpp:67
casadi_int remove_all(const std::string &path)
Definition: ghc.cpp:51
bool remove(const std::string &path)
Definition: ghc.cpp:47
std::vector< casadi_int > path(const std::vector< casadi_int > &map, casadi_int i_start)
bool is_directory(const std::string &path)
Definition: ghc.cpp:31
std::string filename(const std::string &path)
Definition: ghc.cpp:55