common: expose internal StackStringStream via deref

This makes it much easier to use and works similar to a smart ptr.

Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
This commit is contained in:
Patrick Donnelly 2018-12-23 10:17:22 -08:00
parent 38044113a1
commit e4bd6c114d
No known key found for this signature in database
GPG Key ID: 3A2A7E25BEA8AADB
3 changed files with 18 additions and 16 deletions

View File

@ -128,14 +128,17 @@ public:
}
}
sss& get_stream() {
sss& operator*() {
return *osp;
}
const sss& get_stream() const {
sss const& operator*() const {
return *osp;
}
std::string_view strv() const {
return osp->strv();
sss* operator->() {
return osp.get();
}
sss const* operator->() const {
return osp.get();
}
private:

View File

@ -62,14 +62,14 @@ public:
~MutableEntry() override = default;
std::ostream& get_ostream() {
return cos.get_stream();
return *cos;
}
std::string_view strv() const override {
return cos.get_stream().strv();
return cos->strv();
}
std::size_t size() const override {
return cos.get_stream().strv().size();
return cos->strv().size();
}
private:

View File

@ -2948,9 +2948,9 @@ bool MDSRank::command_dirfrag_ls(
f->open_object_section("frag");
f->dump_int("value", leaf.value());
f->dump_int("bits", leaf.bits());
CachedStackStringStream ss;
ss.get_stream() << std::hex << leaf.value() << "/" << std::dec << leaf.bits();
f->dump_string("str", ss.strv());
CachedStackStringStream css;
*css << std::hex << leaf.value() << "/" << std::dec << leaf.bits();
f->dump_string("str", css->strv());
f->close_section();
}
f->close_section();
@ -3199,12 +3199,11 @@ bool MDSRank::evict_client(int64_t session_id,
auto& addr = session->info.inst.addr;
{
CachedStackStringStream _ss;
auto& ss = _ss.get_stream();
ss << "Evicting " << (blacklist ? "(and blacklisting) " : "")
<< "client session " << session_id << " (" << addr << ")";
dout(1) << ss.strv() << dendl;
clog->info() << ss.strv();
CachedStackStringStream css;
*css << "Evicting " << (blacklist ? "(and blacklisting) " : "")
<< "client session " << session_id << " (" << addr << ")";
dout(1) << css->strv() << dendl;
clog->info() << css->strv();
}
dout(4) << "Preparing blacklist command... (wait=" << wait << ")" << dendl;