23
23
#pragma once
24
24
25
25
#include < algorithm>
26
+ #include < filesystem>
26
27
#include < map>
28
+ #include < mutex>
29
+ #include < shared_mutex>
27
30
#include < stdexcept>
28
31
#include < string>
29
32
#include < utility>
30
33
#include < vector>
31
34
32
- #include < boost/algorithm/string/predicate.hpp>
33
- #include < boost/filesystem/path.hpp>
34
- #include < boost/thread/locks.hpp>
35
- #include < boost/thread/shared_mutex.hpp>
36
-
37
35
namespace oak {
38
36
39
37
using Parameters = std::map<std::string, std::string>;
@@ -76,11 +74,11 @@ class Muxer {
76
74
*/
77
75
static std::string normalize (const std::string& route) {
78
76
std::string s = route.substr (0 , route.find (" ?" ));
79
- boost ::filesystem::path p (s);
77
+ std ::filesystem::path p (s);
80
78
if (!p.is_absolute ()) {
81
79
return " " ;
82
80
}
83
- s = p.normalize ().string ();
81
+ s = p.lexically_normal ().string ();
84
82
s = s.substr (0 , s.find_last_not_of (" /. \n\t\r " ) + 1 );
85
83
if (s.empty ()) {
86
84
return " /" ;
@@ -109,15 +107,18 @@ class Muxer {
109
107
*/
110
108
std::string resolve (const std::string& route) const {
111
109
auto key = normalize (route);
112
- boost ::shared_lock<boost::shared_mutex> read_lock (access_);
110
+ std ::shared_lock read_lock (access_);
113
111
if (!backtrack_) {
114
112
if (routes_.count (key)) {
115
113
return key;
116
114
}
117
115
return " " ;
118
116
} else {
119
- boost ::filesystem::path p (key);
117
+ std ::filesystem::path p (key);
120
118
while (!routes_.count (p.string ())) {
119
+ if (p.string () == " /" ) {
120
+ return " " ;
121
+ }
121
122
p = p.parent_path ();
122
123
}
123
124
return p.string ();
@@ -128,7 +129,7 @@ class Muxer {
128
129
* Set the backtracking behavior.
129
130
*/
130
131
void set_backtrack (bool enabled) {
131
- boost ::unique_lock<boost::shared_mutex> write_lock (access_);
132
+ std ::unique_lock write_lock (access_);
132
133
backtrack_ = enabled;
133
134
}
134
135
@@ -139,7 +140,7 @@ class Muxer {
139
140
140
141
std::vector<std::string> routes () const {
141
142
std::vector<std::string> vs;
142
- boost ::shared_lock<boost::shared_mutex> read_lock (access_);
143
+ std ::shared_lock read_lock (access_);
143
144
for (const auto & kv : routes_) {
144
145
if (kv.first .empty ()) {
145
146
continue ;
@@ -151,13 +152,13 @@ class Muxer {
151
152
152
153
bool has (const std::string& route) const {
153
154
auto key = normalize (route);
154
- boost ::shared_lock<boost::shared_mutex> read_lock (access_);
155
+ std ::shared_lock read_lock (access_);
155
156
return routes_.count (key) != 0 ;
156
157
}
157
158
158
159
void add (const std::string& route, T val) {
159
160
auto key = normalize (route);
160
- boost ::unique_lock<boost::shared_mutex> write_lock (access_);
161
+ std ::unique_lock write_lock (access_);
161
162
if (routes_.count (key)) {
162
163
throw std::runtime_error (" route already exists" );
163
164
}
@@ -166,7 +167,7 @@ class Muxer {
166
167
167
168
void set (const std::string& route, T val) {
168
169
auto key = normalize (route);
169
- boost ::unique_lock<boost::shared_mutex> write_lock (access_);
170
+ std ::unique_lock write_lock (access_);
170
171
routes_[key] = val;
171
172
}
172
173
@@ -179,18 +180,18 @@ class Muxer {
179
180
std::pair<T, Parameters> get (const std::string& route) const {
180
181
auto key = resolve (route);
181
182
Parameters p{};
182
- boost ::shared_lock<boost::shared_mutex> read_lock (access_);
183
+ std ::shared_lock read_lock (access_);
183
184
return std::make_pair (routes_.at (key), p);
184
185
}
185
186
186
187
void set_unsafe (const std::string& key, T val) {
187
- boost ::unique_lock<boost::shared_mutex> write_lock (access_);
188
+ std ::unique_lock write_lock (access_);
188
189
routes_[key] = val;
189
190
}
190
191
191
192
std::pair<T, Parameters> get_unsafe (const std::string& key) const {
192
193
Parameters p{};
193
- boost ::shared_lock<boost::shared_mutex> read_lock (access_);
194
+ std ::shared_lock read_lock (access_);
194
195
return std::make_pair (routes_.at (key), p);
195
196
}
196
197
@@ -200,7 +201,7 @@ class Muxer {
200
201
201
202
// State:
202
203
std::map<std::string, T> routes_;
203
- mutable boost ::shared_mutex access_;
204
+ mutable std ::shared_mutex access_;
204
205
};
205
206
206
207
} // namespace oak
0 commit comments