fw4spl
compare.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "fwTest/helper/compare.hpp"
8 
9 #include <fwData/Object.hpp>
10 #include <fwDataCamp/visitor/CompareObjects.hpp>
11 
12 #include <boost/algorithm/string.hpp>
13 
14 
15 namespace fwTest
16 {
17 namespace helper
18 {
19 
20 bool compare(
21  ::fwData::Object::sptr objRef,
22  ::fwData::Object::sptr objComp,
23  ExcludeSetType excludeCompare,
24  ExcludeSetType excludeByPrefix)
25 {
27  visitor.compare(objRef, objComp);
28  SPTR(::fwDataCamp::visitor::CompareObjects::PropsMapType) props = visitor.getDifferences();
29 
30  for(const ExcludeSetType::value_type& key: excludeCompare)
31  {
32  props->erase(key);
33  }
34 
35  std::set< ::fwDataCamp::visitor::CompareObjects::PropsMapType::key_type > propsKey;
36  for(const ::fwDataCamp::visitor::CompareObjects::PropsMapType::value_type &prop: *props)
37  {
38  bool erased = false;
39  for(const ExcludeSetType::value_type& key: excludeByPrefix)
40  {
41  if(::boost::starts_with(prop.first, key))
42  {
43  propsKey.insert(prop.first);
44  erased = true;
45  }
46  }
47 
48  OSLM_ERROR_IF("new object difference found : " << prop.first << " '" << prop.second << "'", !erased);
49  }
50 
51  for(const ::fwDataCamp::visitor::CompareObjects::PropsMapType::key_type &key: propsKey)
52  {
53  props->erase(key);
54  }
55 
56  return props->empty();
57 }
58 
59 } // namespace helper
60 } // namespace fwTest
61 
62 
#define SPTR(_cls_)
Visitor used to compare two objects.
Definition: Data.hpp:15
FWDATACAMP_API void compare(std::shared_ptr< ::fwData::Object > objRef, std::shared_ptr< ::fwData::Object > objComp)
Process to the comparison between reference object and compared object. When the process completes...
std::map< std::string, std::string > PropsMapType
Associates property path (within its parent object) to its value.
#define OSLM_ERROR_IF(message, cond)
Definition: spyLog.hpp:278