24 #ifndef _DIFF_STD_HPP_
25 #define _DIFF_STD_HPP_
34 #include <boost/logic/tribool.hpp>
54 void diff(
const std::string& a,
70 void diff(
const boost::logic::tribool& a,
71 const boost::logic::tribool& b,
72 boost::logic::tribool& a_b,
73 boost::logic::tribool& b_a,
141 template <
typename object_type,
typename config_type = BaseDiffConfig,
typename object_result_type =
object_type>
144 Diff(
const config_type& config = config_type())
149 const object_type& b,
150 const config_type& config = config_type())
162 operator bool() {
return !(
a_b.empty() &&
b_a.empty());}
165 const object_type& b)
176 template <
typename textwriter_type,
typename diff_type>
179 std::ostringstream os;
180 textwriter_type
write(os, 1);
182 if (!diff.a_b.empty())
188 if (!diff.b_a.empty())
199 template <
typename textwriter_type,
typename object_type,
typename config_type>
200 std::ostream& operator<<(std::ostream& os, const Diff<object_type, config_type>&
diff)
202 textwriter_type
write(os, 1);
204 if (!
diff.a_b.empty())
210 if (!
diff.b_a.empty())
220 namespace diff_impl {
223 template <
typename string_type>
225 const string_type& b,
240 template <
typename char_type>
257 template <
typename integral_type>
259 const integral_type& b,
264 a_b = integral_type();
265 b_a = integral_type();
269 a_b =
static_cast<integral_type
>(a);
270 b_a =
static_cast<integral_type
>(b);
275 template <
typename floating_type>
277 const floating_type& b,
294 template <
typename floating_type>
295 floating_type
maxdiff(
const std::vector<floating_type>& a,
const std::vector<floating_type>& b)
297 if (a.size() != b.size())
298 throw std::runtime_error(
"[Diff::maxdiff()] Sizes differ.");
300 typename std::vector<floating_type>::const_iterator i = a.begin();
301 typename std::vector<floating_type>::const_iterator j = b.begin();
303 floating_type
max = 0;
305 for (; i!=a.end(); ++i, ++j)
307 floating_type denominator =
std::min(*i, *j);
308 if (denominator == 0) denominator = 1;
309 floating_type current = fabs(*i - *j)/denominator;
310 if (max < current) max = current;
318 template <
typename object_type>
320 const std::vector<object_type>& b,
321 std::vector<object_type>& a_b,
322 std::vector<object_type>& b_a)
329 for (
typename std::vector<object_type>::const_iterator it=a.begin(); it!=a.end(); ++it)
330 if (std::find(b.begin(), b.end(), *it) == b.end())
333 for (
typename std::vector<object_type>::const_iterator it=b.begin(); it!=b.end(); ++it)
334 if (std::find(a.begin(), a.end(), *it) == a.end())
339 template <
typename object_type>
344 bool operator()(
const boost::shared_ptr<object_type>& objectPtr) {
return objectPtr->id ==
id_;}
348 template <
typename object_type,
typename config_type>
353 Same(
const object_type&
object,
354 const config_type& config)
370 template <
typename object_type,
typename config_type>
372 const std::vector<object_type>& b,
373 std::vector<object_type>& a_b,
374 std::vector<object_type>& b_a,
375 const config_type& config)
382 for (
typename std::vector<object_type>::const_iterator it=a.begin(); it!=a.end(); ++it)
386 for (
typename std::vector<object_type>::const_iterator it=b.begin(); it!=b.end(); ++it)
392 template <
typename object_type,
typename config_type>
398 const config_type& config)
414 template <
typename object_type,
typename config_type>
416 const std::vector< boost::shared_ptr<object_type> >& b,
417 std::vector< boost::shared_ptr<object_type> >& a_b,
418 std::vector< boost::shared_ptr<object_type> >& b_a,
419 const config_type& config)
426 config_type quick_config(config);
427 quick_config.partialDiffOK =
true;
429 for (
typename std::vector< boost::shared_ptr<object_type> >::const_iterator it=a.begin(); it!=a.end(); ++it)
433 for (
typename std::vector< boost::shared_ptr<object_type> >::const_iterator it=b.begin(); it!=b.end(); ++it)
439 template <
typename object_type,
typename config_type>
440 void ptr_diff(
const boost::shared_ptr<object_type>& a,
441 const boost::shared_ptr<object_type>& b,
442 boost::shared_ptr<object_type>& a_b,
443 boost::shared_ptr<object_type>& b_a,
444 const config_type& config)
446 if (!a.get() && !b.get())
return;
448 boost::shared_ptr<object_type> a_temp = a.get() ? a : boost::shared_ptr<object_type>(
new object_type);
449 boost::shared_ptr<object_type> b_temp = b.get() ? b : boost::shared_ptr<object_type>(
new object_type);
451 if (!a_b.get()) a_b = boost::shared_ptr<object_type>(
new object_type);
452 if (!b_a.get()) b_a = boost::shared_ptr<object_type>(
new object_type);
453 diff(*a_temp, *b_temp, *a_b, *b_a, config);
455 if (a_b->empty()) a_b = boost::shared_ptr<object_type>();
456 if (b_a->empty()) b_a = boost::shared_ptr<object_type>();
465 #endif // _DIFF_STD_HPP_