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 <vector>
28 #include <string>
29 #include <fstream>
30 #include <memory>
31 
33 
34 
35 // For dynamic loading
36 #ifdef WITH_DL
37 #ifdef _WIN32 // also for 64-bit
38 #ifndef NOMINMAX
39 #define NOMINMAX
40 #endif
41 #ifndef _WIN32_WINNT
42 #define _WIN32_WINNT 0x0502
43 #endif
44 #include <windows.h>
45 // Avoid IN/OUT macros that may interfere with CasADi code
46 #ifdef IN
47 #undef IN
48 #endif
49 #ifdef OUT
50 #undef OUT
51 #endif
52 #ifdef interface
53 #undef interface
54 #endif
55 #else // _WIN32
56 #include <dlfcn.h>
57 #endif // _WIN32
58 
59 // Set default shared library prefix
60 #ifndef SHARED_LIBRARY_PREFIX
61 #define SHARED_LIBRARY_PREFIX CASADI_SHARED_LIBRARY_PREFIX
62 #endif // SHARED_LIBRARY_PREFIX
63 
64 
65 // Set default shared library suffix
66 #ifndef SHARED_LIBRARY_SUFFIX
67 #define SHARED_LIBRARY_SUFFIX CASADI_SHARED_LIBRARY_SUFFIX
68 #endif // SHARED_LIBRARY_SUFFIX
69 #endif // WITH_DL
70 
71 namespace casadi {
72 
73 CASADI_EXPORT std::vector<std::string> get_search_paths();
74 
75 /* \brief Get the file separator (: or ;)
76  */
77 CASADI_EXPORT char pathsep();
78 /* \brief Get the file separator (/ or \‍)
79  */
80 CASADI_EXPORT std::string filesep();
81 
82 // For dynamic loading
83 #ifdef WITH_DL
84 
85 #ifdef _WIN32
86  typedef HINSTANCE handle_t;
87 #else // _WIN32
88  typedef void* handle_t;
89 #endif
90 
91 CASADI_EXPORT handle_t open_shared_library(const std::string& lib,
92  const std::vector<std::string> &search_paths,
93  std::string &resultpath,
94  const std::string& caller, bool global=false);
95 
96 CASADI_EXPORT handle_t open_shared_library(const std::string& lib,
97  const std::vector<std::string> &search_paths,
98  const std::string& caller, bool global=false);
99 
105 CASADI_EXPORT int close_shared_library(handle_t handle);
106 
107 #endif // WITH_DL
108 
109 
110 CASADI_EXPORT std::unique_ptr<std::istream> ifstream_compat(const std::string& utf8_path,
111  std::ios::openmode mode = std::ios::in);
112 
113 CASADI_EXPORT std::ifstream* new_ifstream_compat(const std::string& utf8_path,
114  std::ios::openmode mode = std::ios::in);
115 
116 CASADI_EXPORT std::unique_ptr<std::ostream> ofstream_compat(const std::string& utf8_path,
117  std::ios::openmode mode = std::ios::out);
118 
119 } // namespace casadi
120 
122 
123 #endif // CASADI_SHARED_LIBRARIES_HPP
The casadi namespace.
Definition: archiver.cpp:28
std::string filesep()
Definition: casadi_os.cpp:59
std::unique_ptr< std::istream > ifstream_compat(const std::string &utf8_path, std::ios::openmode mode)
Definition: casadi_os.cpp:380
std::unique_ptr< std::ostream > ofstream_compat(const std::string &utf8_path, std::ios::openmode mode)
Definition: casadi_os.cpp:410
std::vector< std::string > get_search_paths()
Definition: casadi_os.cpp:67
char pathsep()
Definition: casadi_os.cpp:52
CASADI_EXPORT std::ifstream * new_ifstream_compat(const std::string &utf8_path, std::ios::openmode mode=std::ios::in)