From: Yehuda Sadeh Date: Wed, 8 Feb 2017 23:36:43 +0000 (-0800) Subject: librados: ObjectCursor adjustments and additions X-Git-Tag: v12.0.1~154^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=38f0870f7c18b5e47c5eeab1e9a1b46a85ffcbaf;p=ceph.git librados: ObjectCursor adjustments and additions add missing constructor, operators, and to/from str functionality Signed-off-by: Yehuda Sadeh --- diff --git a/src/include/rados/librados.hpp b/src/include/rados/librados.hpp index 6c9817e4aaa9..ab6b7612787c 100644 --- a/src/include/rados/librados.hpp +++ b/src/include/rados/librados.hpp @@ -72,6 +72,32 @@ namespace librados }; CEPH_RADOS_API std::ostream& operator<<(std::ostream& out, const librados::ListObject& lop); + class CEPH_RADOS_API NObjectIterator; + + class CEPH_RADOS_API ObjectCursor + { + public: + ObjectCursor(); + ObjectCursor(const ObjectCursor &rhs); + explicit ObjectCursor(rados_object_list_cursor c); + ~ObjectCursor(); + ObjectCursor& operator=(const ObjectCursor& rhs); + bool operator<(const ObjectCursor &rhs) const; + bool operator==(const ObjectCursor &rhs) const; + void set(rados_object_list_cursor c); + + friend class IoCtx; + friend class NObjectIteratorImpl; + friend std::ostream& operator<<(std::ostream& os, const librados::ObjectCursor& oc); + + std::string to_str() const; + bool from_str(const std::string& s); + + protected: + rados_object_list_cursor c_cursor; + }; + CEPH_RADOS_API std::ostream& operator<<(std::ostream& os, const librados::ObjectCursor& oc); + class CEPH_RADOS_API NObjectIterator : public std::iterator { public: static const NObjectIterator __EndObjectIterator; @@ -107,21 +133,6 @@ namespace librados NObjectIteratorImpl *impl; }; - class CEPH_RADOS_API ObjectCursor - { - public: - ObjectCursor(); - ObjectCursor(const ObjectCursor &rhs); - ~ObjectCursor(); - bool operator<(const ObjectCursor &rhs); - void set(rados_object_list_cursor c); - - friend class IoCtx; - - protected: - rados_object_list_cursor c_cursor; - }; - class CEPH_RADOS_API ObjectItem { public: diff --git a/src/librados/librados.cc b/src/librados/librados.cc index a448d5346bed..72cdfc5c1730 100644 --- a/src/librados/librados.cc +++ b/src/librados/librados.cc @@ -5829,7 +5829,7 @@ CEPH_RADOS_API void rados_object_list_slice( librados::ObjectCursor::ObjectCursor() { - c_cursor = new hobject_t(); + c_cursor = (rados_object_list_cursor)new hobject_t(); } librados::ObjectCursor::~ObjectCursor() @@ -5838,14 +5838,16 @@ librados::ObjectCursor::~ObjectCursor() delete h; } -bool librados::ObjectCursor::operator<(const librados::ObjectCursor &rhs) +librados::ObjectCursor::ObjectCursor(rados_object_list_cursor c) { - const hobject_t lhs_hobj = (c_cursor == nullptr) ? hobject_t() : *((hobject_t*)c_cursor); - const hobject_t rhs_hobj = (rhs.c_cursor == nullptr) ? hobject_t() : *((hobject_t*)(rhs.c_cursor)); - return lhs_hobj < rhs_hobj; + if (!c) { + c_cursor = nullptr; + } else { + c_cursor = (rados_object_list_cursor)new hobject_t(*(hobject_t *)c); + } } -librados::ObjectCursor::ObjectCursor(const librados::ObjectCursor &rhs) +librados::ObjectCursor& librados::ObjectCursor::operator=(const librados::ObjectCursor& rhs) { if (rhs.c_cursor != nullptr) { hobject_t *h = (hobject_t*)rhs.c_cursor; @@ -5853,6 +5855,25 @@ librados::ObjectCursor::ObjectCursor(const librados::ObjectCursor &rhs) } else { c_cursor = nullptr; } + return *this; +} + +bool librados::ObjectCursor::operator<(const librados::ObjectCursor &rhs) const +{ + const hobject_t lhs_hobj = (c_cursor == nullptr) ? hobject_t() : *((hobject_t*)c_cursor); + const hobject_t rhs_hobj = (rhs.c_cursor == nullptr) ? hobject_t() : *((hobject_t*)(rhs.c_cursor)); + return lhs_hobj < rhs_hobj; +} + +bool librados::ObjectCursor::operator==(const librados::ObjectCursor &rhs) const +{ + const hobject_t lhs_hobj = (c_cursor == nullptr) ? hobject_t() : *((hobject_t*)c_cursor); + const hobject_t rhs_hobj = (rhs.c_cursor == nullptr) ? hobject_t() : *((hobject_t*)(rhs.c_cursor)); + return cmp(lhs_hobj, rhs_hobj) == 0; +} +librados::ObjectCursor::ObjectCursor(const librados::ObjectCursor &rhs) +{ + *this = rhs; } librados::ObjectCursor librados::IoCtx::object_list_begin() @@ -5879,6 +5900,32 @@ void librados::ObjectCursor::set(rados_object_list_cursor c) c_cursor = c; } +string librados::ObjectCursor::to_str() const +{ + stringstream ss; + ss << *(hobject_t *)c_cursor; + return ss.str(); +} + +bool librados::ObjectCursor::from_str(const string& s) +{ + if (s.empty()) { + *(hobject_t *)c_cursor = hobject_t(); + return true; + } + return ((hobject_t *)c_cursor)->parse(s); +} + +CEPH_RADOS_API std::ostream& librados::operator<<(std::ostream& os, const librados::ObjectCursor& oc) +{ + if (oc.c_cursor) { + os << *(hobject_t *)oc.c_cursor; + } else { + os << hobject_t(); + } + return os; +} + bool librados::IoCtx::object_list_is_end(const ObjectCursor &oc) { hobject_t *h = (hobject_t *)oc.c_cursor;