Make Buffer::operator== a free function

This commit is contained in:
Matias Fontanini
2016-11-06 13:50:50 -08:00
parent 33680839a2
commit aa7fa6ce0d
2 changed files with 21 additions and 21 deletions

View File

@@ -134,16 +134,6 @@ public:
return std::vector<T>(data_, data_ + size_);
}
/**
* Compares this Buffer for equality
*/
bool operator==(const Buffer& rhs) const;
/**
* Compares this Buffer for inequality
*/
bool operator!=(const Buffer& rhs) const;
/**
* Output operator
*/
@@ -153,6 +143,16 @@ private:
size_t size_;
};
/**
* Compares Buffer objects for equality
*/
bool operator==(const Buffer& lhs, const Buffer& rhs);
/**
* Compares Buffer objects for inequality
*/
bool operator!=(const Buffer& lhs, const Buffer& rhs);
} // cppkafka
#endif // CPPKAFKA_BUFFER_H

View File

@@ -74,17 +74,6 @@ Buffer::operator string() const {
return string(data_, data_ + size_);
}
bool Buffer::operator==(const Buffer& rhs) const {
if (get_size() != rhs.get_size()) {
return false;
}
return equal(get_data(), get_data() + get_size(), rhs.get_data());
}
bool Buffer::operator!=(const Buffer& rhs) const {
return !(*this == rhs);
}
ostream& operator<<(ostream& output, const Buffer& rhs) {
for (const uint8_t value : rhs) {
if (value >= 0x20 && value < 0x7f) {
@@ -101,4 +90,15 @@ ostream& operator<<(ostream& output, const Buffer& rhs) {
return output;
}
bool operator==(const Buffer& lhs, const Buffer& rhs) {
if (lhs.get_size() != rhs.get_size()) {
return false;
}
return equal(lhs.get_data(), lhs.get_data() + lhs.get_size(), rhs.get_data());
}
bool operator!=(const Buffer& lhs, const Buffer& rhs) {
return !(lhs == rhs);
}
} // cppkafka