/
boosty.h
141 lines (108 loc) · 2.99 KB
/
boosty.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// boosty.h by don bright 2012. Copyright assigned to Marius Kintel and
// Clifford Wolf 2012. Released under the GPL 2, or later, as described in
// the file named 'COPYING' in OpenSCAD's project root.
#pragma once
/*
boosty is a wrapper around boost so that OpenSCAD can work with old
versions of boost found on popular versions of linux, circa early 2012.
design
the boost filsystem changed around 1.46-1.48. we do a large #ifdef
based on boost version that wraps various functions appropriately.
in a few years, this file should be deleted as unnecessary.
see also
http://www.boost.org/doc/libs/1_48_0/libs/filesystem/v3/doc/index.htm
http://www.boost.org/doc/libs/1_45_0/libs/filesystem/v2/doc/index.htm
http://www.boost.org/doc/libs/1_42_0/libs/filesystem/doc/index.htm
http://www.boost.org/doc/libs/1_35_0/libs/filesystem/doc/index.htm
include/boost/wave/util/filesystem_compatability.hpp
*/
#include <string>
#include <boost/version.hpp>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
namespace fs = boost::filesystem;
#include "printutils.h"
namespace boosty {
#if BOOST_VERSION >= 104400 && BOOST_FILESYSTEM_VERSION >= 3
inline bool is_absolute( fs::path p )
{
return p.is_absolute();
}
inline fs::path absolute( fs::path p )
{
return fs::absolute( p );
}
inline std::string stringy( fs::path p )
{
return p.generic_string();
}
inline std::string extension_str( fs::path p)
{
return p.extension().generic_string();
}
#else
inline bool is_absolute( fs::path p )
{
return p.is_complete();
}
inline fs::path absolute( fs::path p )
{
return fs::complete(p, fs::current_path());
}
inline std::string stringy( fs::path p )
{
return p.string();
}
inline std::string extension_str( fs::path p)
{
return p.extension();
}
#endif
#if BOOST_VERSION >= 104800
inline fs::path canonical( fs::path p, fs::path p2 )
{
return fs::canonical( p, p2 );
}
inline fs::path canonical( fs::path p )
{
return fs::canonical( p );
}
#else
inline fs::path canonical( fs::path p, fs::path p2 )
{
#if defined (__WIN32__) || defined(__APPLE__)
#error you should be using a newer version of boost on win/mac
#endif
// based on the code in boost
fs::path result;
if (p=="") p=p2;
std::string result_s;
std::vector<std::string> resultv, pieces;
std::vector<std::string>::iterator pi;
std::string tmps = boosty::stringy( p );
boost::split( pieces, tmps, boost::is_any_of("/") );
for ( pi = pieces.begin(); pi != pieces.end(); ++pi )
{
if (*pi == "..")
resultv.erase( resultv.end() );
else
resultv.push_back( *pi );
}
for ( pi = resultv.begin(); pi != resultv.end(); ++pi )
{
if ((*pi).length()>0) result_s = result_s + "/" + *pi;
}
result = fs::path( result_s );
if (fs::is_symlink(result))
{
PRINT("WARNING: canonical() wrapper can't do symlinks. rebuild openscad with boost >=1.48");
PRINT("WARNING: or don't use symbolic links");
}
return result;
}
inline fs::path canonical( fs::path p )
{
return canonical( p, fs::current_path() );
}
#endif
} // namespace