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>
343 HasID(
const std::string&
id) : id_(id) {}
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)
355 : mine_(object), config_(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)
399 : mine_(object), config_(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_
HasID(const std::string &id)
Diff(const config_type &config=config_type())
void vector_diff_diff(const std::vector< object_type > &a, const std::vector< object_type > &b, std::vector< object_type > &a_b, std::vector< object_type > &b_a, const config_type &config)
bool operator()(const boost::shared_ptr< object_type > &yours)
Calculate diffs of objects in a ProteoWizard data model hierarchy.
Information about an ontology or CV source and a short 'lookup' tag to refer to.
BaseDiffConfig(double _precision=1e-6)
void vector_diff_deep(const std::vector< boost::shared_ptr< object_type > > &a, const std::vector< boost::shared_ptr< object_type > > &b, std::vector< boost::shared_ptr< object_type > > &a_b, std::vector< boost::shared_ptr< object_type > > &b_a, const config_type &config)
void diff(const string &filename1, const string &filename2)
Uncontrolled user parameters (essentially allowing free text). Before using these, one should verify whether there is an appropriate CV term available, and if so, use the CV term instead.
std::string diff_string(const diff_type &diff)
Same(const object_type &object, const config_type &config)
PWIZ_API_DECL void write(minimxml::XMLWriter &writer, const CV &cv)
The base class for elements that may contain cvParams, userParams, or paramGroup references.
Diff & operator()(const object_type &a, const object_type &b)
const config_type & config_
SameDeep(const object_type &object, const config_type &config)
floating_type maxdiff(const std::vector< floating_type > &a, const std::vector< floating_type > &b)
measure maximum relative difference between elements in the vectors
const config_type & config_
void diff_char(const char_type &a, const char_type &b, char_type &a_b, char_type &b_a)
bool operator()(const object_type &yours)
A collection of CVParam and UserParam elements that can be referenced from elsewhere in this mzML doc...
Diff(const object_type &a, const object_type &b, const config_type &config=config_type())
const object_type & mine_
bool operator()(const boost::shared_ptr< object_type > &objectPtr)
PWIZ_API_DECL void diff_ids(const std::string &a, const std::string &b, std::string &a_b, std::string &b_a, const BaseDiffConfig &config)
const object_type & mine_
void ptr_diff(const boost::shared_ptr< object_type > &a, const boost::shared_ptr< object_type > &b, boost::shared_ptr< object_type > &a_b, boost::shared_ptr< object_type > &b_a, const config_type &config)
void vector_diff(const std::vector< object_type > &a, const std::vector< object_type > &b, std::vector< object_type > &a_b, std::vector< object_type > &b_a)
void diff_floating(const floating_type &a, const floating_type &b, floating_type &a_b, floating_type &b_a, const BaseDiffConfig &config)
void diff_integral(const integral_type &a, const integral_type &b, integral_type &a_b, integral_type &b_a, const BaseDiffConfig &config)
represents a tag-value pair, where the tag comes from the controlled vocabulary
PWIZ_API_DECL void diff(const std::string &a, const std::string &b, std::string &a_b, std::string &b_a, const BaseDiffConfig &config)