Mercurial > hg > orthanc
comparison Core/RestApi/RestApiPath.cpp @ 966:886652370ff2
accelerating REST API matching
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 27 Jun 2014 15:33:22 +0200 |
parents | a811bdf8b8eb |
children | c550e99c452b |
comparison
equal
deleted
inserted
replaced
965:d724ac031080 | 966:886652370ff2 |
---|---|
30 **/ | 30 **/ |
31 | 31 |
32 | 32 |
33 #include "../PrecompiledHeaders.h" | 33 #include "../PrecompiledHeaders.h" |
34 #include "RestApiPath.h" | 34 #include "RestApiPath.h" |
35 | |
36 #include "../OrthancException.h" | |
35 | 37 |
36 #include <cassert> | 38 #include <cassert> |
37 | 39 |
38 namespace Orthanc | 40 namespace Orthanc |
39 { | 41 { |
87 | 89 |
88 bool RestApiPath::Match(Components& components, | 90 bool RestApiPath::Match(Components& components, |
89 UriComponents& trailing, | 91 UriComponents& trailing, |
90 const UriComponents& uri) const | 92 const UriComponents& uri) const |
91 { | 93 { |
94 assert(uri_.size() == components_.size()); | |
95 | |
92 if (uri.size() < uri_.size()) | 96 if (uri.size() < uri_.size()) |
93 { | 97 { |
94 return false; | 98 return false; |
95 } | 99 } |
96 | 100 |
133 { | 137 { |
134 Components components; | 138 Components components; |
135 UriComponents trailing; | 139 UriComponents trailing; |
136 return Match(components, trailing, uri); | 140 return Match(components, trailing, uri); |
137 } | 141 } |
142 | |
143 | |
144 bool RestApiPath::IsWildcardLevel(size_t level) const | |
145 { | |
146 assert(uri_.size() == components_.size()); | |
147 | |
148 if (level >= uri_.size()) | |
149 { | |
150 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
151 } | |
152 | |
153 return uri_[level].length() == 0; | |
154 } | |
155 | |
156 const std::string& RestApiPath::GetWildcardName(size_t level) const | |
157 { | |
158 assert(uri_.size() == components_.size()); | |
159 | |
160 if (!IsWildcardLevel(level)) | |
161 { | |
162 throw OrthancException(ErrorCode_BadParameterType); | |
163 } | |
164 | |
165 return components_[level]; | |
166 } | |
167 | |
168 const std::string& RestApiPath::GetLevelName(size_t level) const | |
169 { | |
170 assert(uri_.size() == components_.size()); | |
171 | |
172 if (IsWildcardLevel(level)) | |
173 { | |
174 throw OrthancException(ErrorCode_BadParameterType); | |
175 } | |
176 | |
177 return uri_[level]; | |
178 } | |
138 } | 179 } |
180 |