15 #include <vsg/core/ref_ptr.h>
22 template<
class T,
class R>
23 int compare_pointer(
const ref_ptr<T>& lhs,
const ref_ptr<R>& rhs)
25 if (lhs == rhs)
return 0;
26 return lhs ? (rhs ? lhs->compare(*rhs) : 1) : (rhs ? -1 : 0);
30 int compare_value(
const T& lhs,
const T& rhs)
32 return (lhs < rhs) ? -1 : ((rhs < lhs) ? 1 : 0);
36 int compare_values(
const T* lhs,
const T* rhs,
size_t size)
39 for (
size_t i = 0; i < size; ++i)
41 if ((result = compare_value(lhs[i], rhs[i])))
break;
47 int compare_memory(
const T& lhs,
const T& rhs)
49 return std::memcmp(&lhs, &rhs,
sizeof(T));
52 template<
typename S,
typename E>
53 int compare_region(
const S& start,
const E& end,
const S& rhs)
55 const char* lhs_ptr =
reinterpret_cast<const char*
>(&start);
56 const char* rhs_ptr =
reinterpret_cast<const char*
>(&rhs);
57 size_t size = size_t(
reinterpret_cast<const char*
>(&end) - lhs_ptr) +
sizeof(E);
60 return std::memcmp(lhs_ptr, rhs_ptr, size);
64 int compare_pointer_container(
const T& lhs,
const T& rhs)
66 if (lhs.size() < rhs.size())
return -1;
67 if (lhs.size() > rhs.size())
return 1;
68 if (lhs.empty())
return 0;
70 auto rhs_itr = rhs.begin();
71 for (
auto&
object : lhs)
73 int result = compare_pointer(
object, *rhs_itr++);
74 if (result != 0)
return result;
80 int compare_value_container(
const T& lhs,
const T& rhs)
82 if (lhs.size() < rhs.size())
return -1;
83 if (lhs.size() > rhs.size())
return 1;
84 if (lhs.empty())
return 0;
86 return compare_region(lhs.front(), lhs.back(), rhs.front());
90 int compare_container(
const T& lhs,
const T& rhs)
92 if (lhs.size() < rhs.size())
return -1;
93 if (lhs.size() > rhs.size())
return 1;
94 if (lhs.empty())
return 0;
96 auto rhs_itr = rhs.begin();
97 for (
auto&
object : lhs)
99 int result =
object.compare(*rhs_itr++);
100 if (result != 0)
return result;
109 bool operator()(
const P& lhs,
const P& rhs)
const
111 return lhs->compare(*rhs) < 0;
less functor for comparing ref_ptr<Object> typically used with std::set<> etc.
Definition: compare.h:107