From: Patrick Donnelly Date: Tue, 18 Dec 2018 21:07:20 +0000 (-0800) Subject: include: add small_vector encode/decode/<< X-Git-Tag: v14.1.0~550^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3105f4e034748d1fd2f7fd9e67e00327def38dd0;p=ceph.git include: add small_vector encode/decode/<< Signed-off-by: Patrick Donnelly --- diff --git a/src/include/encoding.h b/src/include/encoding.h index fcef7672f5fa..13375c2da7db 100644 --- a/src/include/encoding.h +++ b/src/include/encoding.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -425,6 +426,23 @@ inline void encode(const std::vector,Alloc>& v, template inline void decode(std::vector,Alloc>& v, bufferlist::const_iterator& p); +// small_vector +template> +inline std::enable_if_t +encode(const boost::container::small_vector& v, bufferlist& bl, uint64_t features); +template> +inline std::enable_if_t +encode(const boost::container::small_vector& v, bufferlist& bl); +template> +inline std::enable_if_t +decode(boost::container::small_vector& v, bufferlist::const_iterator& p); +template> +inline std::enable_if_t +encode_nohead(const boost::container::small_vector& v, bufferlist& bl); +template> +inline std::enable_if_t +decode_nohead(int len, boost::container::small_vector& v, bufferlist::const_iterator& p); +// std::map template, typename u_traits=denc_traits> inline std::enable_if_t decode(v[i], p); } +// small vector +template +inline std::enable_if_t + encode(const boost::container::small_vector& v, bufferlist& bl, uint64_t features) +{ + __u32 n = (__u32)(v.size()); + encode(n, bl); + for (const auto& i : v) + encode(i, bl, features); +} +template +inline std::enable_if_t + encode(const boost::container::small_vector& v, bufferlist& bl) +{ + __u32 n = (__u32)(v.size()); + encode(n, bl); + for (const auto& i : v) + encode(i, bl); +} +template +inline std::enable_if_t + decode(boost::container::small_vector& v, bufferlist::const_iterator& p) +{ + __u32 n; + decode(n, p); + v.resize(n); + for (auto& i : v) + decode(i, p); +} + +template +inline std::enable_if_t + encode_nohead(const boost::container::small_vector& v, bufferlist& bl) +{ + for (const auto& i : v) + encode(i, bl); +} +template +inline std::enable_if_t + decode_nohead(int len, boost::container::small_vector& v, bufferlist::const_iterator& p) +{ + v.resize(len); + for (auto& i : v) + decode(i, p); +} + + // vector (shared_ptr) template inline void encode(const std::vector,Alloc>& v, diff --git a/src/include/types.h b/src/include/types.h index 8103cabbb365..76447caa0b28 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -100,6 +100,8 @@ template inline std::ostream& operator<<(std::ostream&out, const std::pair& v); template inline std::ostream& operator<<(std::ostream& out, const std::vector& v); +template +inline std::ostream& operator<<(std::ostream& out, const boost::container::small_vector& v); template inline std::ostream& operator<<(std::ostream& out, const std::deque& v); template @@ -136,10 +138,25 @@ inline std::ostream& operator<<(std::ostream& out, const std::pair& v) { template inline std::ostream& operator<<(std::ostream& out, const std::vector& v) { + bool first = true; out << "["; - for (auto p = v.begin(); p != v.end(); ++p) { - if (p != v.begin()) out << ","; - out << *p; + for (const auto& p : v) { + if (!first) out << ","; + out << p; + first = false; + } + out << "]"; + return out; +} + +template +inline std::ostream& operator<<(std::ostream& out, const boost::container::small_vector& v) { + bool first = true; + out << "["; + for (const auto& p : v) { + if (!first) out << ","; + out << p; + first = false; } out << "]"; return out;