MCPcopy Create free account
hub / github.com/comaps/comaps / ParseSelector

Function ParseSelector

libs/indexer/drules_selector.cpp:180–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

178} // namespace
179
180unique_ptr<ISelector> ParseSelector(string const & str)
181{
182 SelectorExpression e;
183 if (!ParseSelector(str, e))
184 {
185 // bad string format
186 LOG(LDEBUG, ("Invalid selector format:", str));
187 return {};
188 }
189
190 if (e.m_tag == "population")
191 {
192 uint64_t value = 0;
193 if (!e.m_value.empty() && !strings::to_uint64(e.m_value, value))
194 {
195 // bad string format
196 LOG(LDEBUG, ("Invalid selector:", str));
197 return {};
198 }
199 return make_unique<Selector<uint64_t>>(&GetPopulation, e.m_operator, value);
200 }
201 else if (e.m_tag == "name")
202 {
203 return make_unique<HasSelector>(&HasName, e.m_operator);
204 }
205 else if (e.m_tag == "bbox_area")
206 {
207 double value = 0;
208 if (!e.m_value.empty() && (!strings::to_double(e.m_value, value) || value < 0))
209 {
210 // bad string format
211 LOG(LDEBUG, ("Invalid selector:", str));
212 return {};
213 }
214 return make_unique<Selector<double>>(&GetBoundingBoxArea, e.m_operator, value);
215 }
216 // else if (e.m_tag == "extra_tag")
217 // {
218 // ASSERT(false, ());
219 // uint32_t const type = TagSelectorToType(e.m_value);
220 // if (type == Classificator::INVALID_TYPE)
221 // {
222 // // Type was not found.
223 // LOG(LDEBUG, ("Invalid selector:", str));
224 // return unique_ptr<ISelector>();
225 // }
226 // return make_unique<TypeSelector>(type, e.m_operator);
227 // }
228
229 LOG(LERROR, ("Unrecognized selector:", str));
230 return {};
231}
232
233unique_ptr<ISelector> ParseSelector(vector<string> const & strs)
234{

Callers 2

AddRuleMethod · 0.70
UNIT_TESTFunction · 0.50

Calls 6

to_uint64Function · 0.85
to_doubleFunction · 0.50
emptyMethod · 0.45
sizeMethod · 0.45
AddMethod · 0.45
releaseMethod · 0.45

Tested by 1

UNIT_TESTFunction · 0.40