| 269 | } |
| 270 | |
| 271 | bool mitk::DataStorageCompare::IsDataEqual(const mitk::BaseData *reference, const mitk::BaseData *test, bool verbose) |
| 272 | { |
| 273 | // early-out for nullptrs |
| 274 | if (reference == nullptr && test == nullptr) |
| 275 | return true; |
| 276 | |
| 277 | if (reference == nullptr && test != nullptr) |
| 278 | { |
| 279 | if (verbose) |
| 280 | MITK_WARN << " Reference data is nullptr, test data is not (type " << test->GetNameOfClass() << ")"; |
| 281 | return false; |
| 282 | } |
| 283 | |
| 284 | if (reference != nullptr && test == nullptr) |
| 285 | { |
| 286 | if (verbose) |
| 287 | MITK_WARN << " Test data is nullptr, reference data is not (type " << reference->GetNameOfClass() << ")"; |
| 288 | return false; |
| 289 | } |
| 290 | |
| 291 | // two real BaseData objects, need to really compare |
| 292 | if (reference->GetNameOfClass() != test->GetNameOfClass()) |
| 293 | { |
| 294 | if (verbose) |
| 295 | MITK_WARN << " Mismatch: Reference data is '" << reference->GetNameOfClass() << "', " |
| 296 | << "test data is '" << test->GetNameOfClass() << "'"; |
| 297 | return false; |
| 298 | } |
| 299 | try |
| 300 | { |
| 301 | std::string ldapFilter = std::string("(basedata=") + reference->GetNameOfClass() + "*)"; |
| 302 | std::vector<us::ServiceReference<BaseDataCompare>> comparators = |
| 303 | us::GetModuleContext()->GetServiceReferences<BaseDataCompare>(ldapFilter); |
| 304 | if (comparators.empty()) |
| 305 | { |
| 306 | // bad, no comparator found, cannot compare |
| 307 | MITK_ERROR << "Comparison error: no comparator for objects of type '" << reference->GetNameOfClass() << "'"; |
| 308 | return false; |
| 309 | } |
| 310 | else if (comparators.size() > 1) |
| 311 | { |
| 312 | MITK_WARN << "Comparison warning: multiple comparisons possible for objects of type '" |
| 313 | << reference->GetNameOfClass() << "'. Using just one."; |
| 314 | // bad, multiple comparators, need to add ranking or something |
| 315 | } |
| 316 | |
| 317 | auto *comparator = us::GetModuleContext()->GetService<BaseDataCompare>(comparators.front()); |
| 318 | if (!comparator) |
| 319 | { |
| 320 | MITK_ERROR << "Service lookup error, cannot get comparator for class " << reference->GetNameOfClass(); |
| 321 | } |
| 322 | |
| 323 | return comparator->AreEqual(reference, test, m_Eps, verbose); |
| 324 | } |
| 325 | catch (std::exception &e) |
| 326 | { |
| 327 | MITK_ERROR << "Exception during comparison: " << e.what(); |
| 328 | return false; |
nothing calls this directly
no test coverage detected