Line |
Branch |
Exec |
Source |
1 |
|
|
// |
2 |
|
|
// Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com) |
3 |
|
|
// |
4 |
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying |
5 |
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
6 |
|
|
// |
7 |
|
|
// Official repository: https://github.com/boostorg/url |
8 |
|
|
// |
9 |
|
|
|
10 |
|
|
#ifndef BOOST_URL_MATCHES_HPP |
11 |
|
|
#define BOOST_URL_MATCHES_HPP |
12 |
|
|
|
13 |
|
|
#include <boost/url/detail/config.hpp> |
14 |
|
|
#include <boost/url/string_view.hpp> |
15 |
|
|
|
16 |
|
|
namespace boost { |
17 |
|
|
namespace urls { |
18 |
|
|
|
19 |
|
|
// Base route match results |
20 |
|
|
class matches_base |
21 |
|
|
{ |
22 |
|
|
public: |
23 |
|
|
using iterator = core::string_view*; |
24 |
|
|
using const_iterator = core::string_view const*; |
25 |
|
|
using size_type = std::size_t; |
26 |
|
|
using difference_type = std::ptrdiff_t; |
27 |
|
|
using reference = core::string_view&; |
28 |
|
|
using const_reference = core::string_view const&; |
29 |
|
|
using pointer = core::string_view*; |
30 |
|
|
using const_pointer = core::string_view const*; |
31 |
|
|
|
32 |
|
93 |
matches_base() = default; |
33 |
|
|
|
34 |
|
186 |
virtual ~matches_base() = default; |
35 |
|
|
|
36 |
|
|
virtual |
37 |
|
|
core::string_view const* |
38 |
|
|
matches() const = 0; |
39 |
|
|
|
40 |
|
|
virtual |
41 |
|
|
core::string_view const* |
42 |
|
|
ids() const = 0; |
43 |
|
|
|
44 |
|
|
virtual |
45 |
|
|
core::string_view* |
46 |
|
|
matches() = 0; |
47 |
|
|
|
48 |
|
|
virtual |
49 |
|
|
core::string_view* |
50 |
|
|
ids() = 0; |
51 |
|
|
|
52 |
|
|
virtual |
53 |
|
|
std::size_t |
54 |
|
|
size() const = 0; |
55 |
|
|
|
56 |
|
|
virtual |
57 |
|
|
void |
58 |
|
|
resize(std::size_t) = 0; |
59 |
|
|
|
60 |
|
|
const_reference |
61 |
|
|
at( size_type pos ) const; |
62 |
|
|
|
63 |
|
|
const_reference |
64 |
|
|
at( core::string_view id ) const; |
65 |
|
|
|
66 |
|
|
const_reference |
67 |
|
|
operator[]( size_type pos ) const; |
68 |
|
|
|
69 |
|
|
const_reference |
70 |
|
|
operator[]( core::string_view id ) const; |
71 |
|
|
|
72 |
|
|
const_iterator |
73 |
|
|
find( core::string_view id ) const; |
74 |
|
|
|
75 |
|
|
const_iterator |
76 |
|
|
begin() const; |
77 |
|
|
|
78 |
|
|
const_iterator |
79 |
|
|
end() const; |
80 |
|
|
|
81 |
|
|
bool |
82 |
|
|
empty() const noexcept; |
83 |
|
|
}; |
84 |
|
|
|
85 |
|
|
/// A range type with the match results |
86 |
|
|
template <std::size_t N = 20> |
87 |
|
|
class matches_storage |
88 |
|
|
: public matches_base |
89 |
|
|
{ |
90 |
|
|
core::string_view matches_storage_[N]; |
91 |
|
|
core::string_view ids_storage_[N]; |
92 |
|
|
std::size_t size_; |
93 |
|
|
|
94 |
|
|
matches_storage( |
95 |
|
|
core::string_view matches[N], |
96 |
|
|
core::string_view ids[N], |
97 |
|
|
std::size_t n) |
98 |
|
|
{ |
99 |
|
|
for (std::size_t i = 0; i < n; ++i) |
100 |
|
|
{ |
101 |
|
|
matches_storage_[i] = matches[i]; |
102 |
|
|
ids_storage_[i] = ids[i]; |
103 |
|
|
} |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
virtual |
107 |
|
|
core::string_view* |
108 |
|
245 |
matches() override |
109 |
|
|
{ |
110 |
|
245 |
return matches_storage_; |
111 |
|
|
} |
112 |
|
|
|
113 |
|
|
virtual |
114 |
|
|
core::string_view* |
115 |
|
93 |
ids() override |
116 |
|
|
{ |
117 |
|
93 |
return ids_storage_; |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
public: |
121 |
|
93 |
matches_storage() = default; |
122 |
|
|
|
123 |
|
|
virtual |
124 |
|
|
core::string_view const* |
125 |
|
1016 |
matches() const override |
126 |
|
|
{ |
127 |
|
1016 |
return matches_storage_; |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
virtual |
131 |
|
|
core::string_view const* |
132 |
|
792 |
ids() const override |
133 |
|
|
{ |
134 |
|
792 |
return ids_storage_; |
135 |
|
|
} |
136 |
|
|
|
137 |
|
|
virtual |
138 |
|
|
std::size_t |
139 |
|
1758 |
size() const override |
140 |
|
|
{ |
141 |
|
1758 |
return size_; |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
virtual |
145 |
|
|
void |
146 |
|
93 |
resize(std::size_t n) override |
147 |
|
|
{ |
148 |
|
93 |
size_ = n; |
149 |
|
93 |
} |
150 |
|
|
}; |
151 |
|
|
|
152 |
|
|
/// Default type for storing route match results |
153 |
|
|
using matches = matches_storage<20>; |
154 |
|
|
|
155 |
|
|
} // urls |
156 |
|
|
} // boost |
157 |
|
|
|
158 |
|
|
#endif |
159 |
|
|
|
160 |
|
|
|