casadi_os.hpp
1 /*
2  * This file is part of CasADi.
3  *
4  * CasADi -- A symbolic framework for dynamic optimization.
5  * Copyright (C) 2010 by Joel Andersson, Moritz Diehl, K.U.Leuven. All rights reserved.
6  *
7  * CasADi is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 3 of the License, or (at your option) any later version.
11  *
12  * CasADi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with CasADi; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  */
22 
23 #ifndef CASADI_CASADI_OS_HPP
24 #define CASADI_CASADI_OS_HPP
25 
26 #include <casadi/core/casadi_export.h>
27 #include <casadi/core/casadi_meta.hpp>
28 #include <vector>
29 #include <string>
30 #include <fstream>
31 #include <memory>
32 
34 
35 
36 // For dynamic loading
37 #ifdef WITH_DL
38 #ifdef _WIN32 // also for 64-bit
39 #ifndef NOMINMAX
40 #define NOMINMAX
41 #endif
42 #ifndef _WIN32_WINNT
43 #define _WIN32_WINNT 0x0502
44 #endif
45 #include <windows.h>
46 // Avoid IN/OUT macros that may interfere with CasADi code
47 #ifdef IN
48 #undef IN
49 #endif
50 #ifdef OUT
51 #undef OUT
52 #endif
53 #ifdef interface
54 #undef interface
55 #endif
56 #else // _WIN32
57 #include <dlfcn.h>
58 #endif // _WIN32
59 
60 // Set default shared library prefix
61 #ifndef SHARED_LIBRARY_PREFIX
62 #define SHARED_LIBRARY_PREFIX CasadiMeta::shared_library_prefix()
63 #endif // SHARED_LIBRARY_PREFIX
64 
65 
66 // Set default shared library suffix
67 #ifndef SHARED_LIBRARY_SUFFIX
68 #define SHARED_LIBRARY_SUFFIX CasadiMeta::shared_library_suffix()
69 #endif // SHARED_LIBRARY_SUFFIX
70 #endif // WITH_DL
71 
72 namespace casadi {
73 
74 CASADI_EXPORT std::vector<std::string> get_search_paths();
75 
76 /* \brief Get the file separator (: or ;)
77  */
78 CASADI_EXPORT char pathsep();
79 /* \brief Get the file separator (/ or \‍)
80  */
81 CASADI_EXPORT std::string filesep();
82 
83 // For dynamic loading
84 #ifdef WITH_DL
85 
86 #ifdef _WIN32
87  typedef HINSTANCE handle_t;
88 #else // _WIN32
89  typedef void* handle_t;
90 #endif
91 
92 CASADI_EXPORT handle_t open_shared_library(const std::string& lib,
93  const std::vector<std::string> &search_paths,
94  std::string &resultpath,
95  const std::string& caller, bool global=false);
96 
97 CASADI_EXPORT handle_t open_shared_library(const std::string& lib,
98  const std::vector<std::string> &search_paths,
99  const std::string& caller, bool global=false);
100 
106 CASADI_EXPORT int close_shared_library(handle_t handle);
107 
108 #else // WITH_DL
109  typedef void* handle_t;
110 #endif // WITH_DL
111 
112 
113 CASADI_EXPORT std::unique_ptr<std::istream> ifstream_compat(const std::string& utf8_path,
114  std::ios::openmode mode = std::ios::in);
115 
116 CASADI_EXPORT std::ifstream* new_ifstream_compat(const std::string& utf8_path,
117  std::ios::openmode mode = std::ios::in);
118 
119 CASADI_EXPORT std::unique_ptr<std::ostream> ofstream_compat(const std::string& utf8_path,
120  std::ios::openmode mode = std::ios::out);
121 
122 } // namespace casadi
123 
125 
126 #endif // CASADI_SHARED_LIBRARIES_HPP
The casadi namespace.
Definition: archiver.hpp:32