From dd2189656b2659a490c5336bb17525b6b5f83f0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Sun, 21 Oct 2012 21:04:05 +0200 Subject: [PATCH] More idiomatic way of checking if a shared_ptr has an associated managed object --- src/KeyMap.cpp | 17 ++++++++--------- src/frontends/qt4/LayoutBox.cpp | 4 ++-- src/graphics/GraphicsCacheItem.cpp | 2 +- src/graphics/GraphicsLoader.cpp | 22 +++++++++++----------- src/support/ForkedCalls.cpp | 2 +- 5 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/KeyMap.cpp b/src/KeyMap.cpp index ffd55c4970..50833c923a 100644 --- a/src/KeyMap.cpp +++ b/src/KeyMap.cpp @@ -115,13 +115,12 @@ void KeyMap::bind(KeySequence * seq, FuncRequest const & func, unsigned int r) LYXERR(Debug::KBMAP, "Warning: New binding for '" << to_utf8(seq->print(KeySequence::Portable)) << "' is overriding old binding..."); - if (it->prefixes.get()) { + if (it->prefixes) it->prefixes.reset(); - } it->func = func; it->func.setOrigin(FuncRequest::KEYBOARD); return; - } else if (!it->prefixes.get()) { + } else if (!it->prefixes) { lyxerr << "Error: New binding for '" << to_utf8(seq->print(KeySequence::Portable)) << "' is overriding old binding..." @@ -168,10 +167,10 @@ void KeyMap::unbind(KeySequence * seq, FuncRequest const & func, unsigned int r) if (r + 1 == seq->length()) { if (it->func == func) { remove = it; - if (it->prefixes.get()) + if (it->prefixes) it->prefixes.reset(); } - } else if (it->prefixes.get()) { + } else if (it->prefixes) { it->prefixes->unbind(seq, func, r + 1); if (it->prefixes->empty()) remove = it; @@ -201,7 +200,7 @@ FuncRequest KeyMap::getBinding(KeySequence const & seq, unsigned int r) && mod2 == it->mod.second) { if (r + 1 == seq.length()) return it->func; - else if (it->prefixes.get()) + else if (it->prefixes) return it->prefixes->getBinding(seq, r + 1); } } @@ -441,7 +440,7 @@ FuncRequest const & KeyMap::lookup(KeySymbol const &key, if (cit->code == key && cit->mod.first == check) { // match found - if (cit->prefixes.get()) { + if (cit->prefixes) { // this is a prefix key - set new map seq->curmap = cit->prefixes.get(); static FuncRequest prefix(LFUN_COMMAND_PREFIX); @@ -507,7 +506,7 @@ KeyMap::Bindings KeyMap::findBindings(FuncRequest const & func, Table::const_iterator end = table.end(); for (Table::const_iterator cit = table.begin(); cit != end; ++cit) { - if (cit->prefixes.get()) { + if (cit->prefixes) { KeySequence seq = prefix; seq.addkey(cit->code, cit->mod.first); Bindings res2 = cit->prefixes->findBindings(func, seq); @@ -555,7 +554,7 @@ void KeyMap::listBindings(BindingList & list, Table::const_iterator it_end = table.end(); for (; it != it_end; ++it) { // a LFUN_COMMAND_PREFIX - if (it->prefixes.get()) { + if (it->prefixes) { KeySequence seq = prefix; seq.addkey(it->code, it->mod.first); it->prefixes->listBindings(list, seq, tag); diff --git a/src/frontends/qt4/LayoutBox.cpp b/src/frontends/qt4/LayoutBox.cpp index aa22e60eac..e11a63dde7 100644 --- a/src/frontends/qt4/LayoutBox.cpp +++ b/src/frontends/qt4/LayoutBox.cpp @@ -536,7 +536,7 @@ void LayoutBox::set(docstring const & layout) { d->resetFilter(); - if (!d->text_class_.get()) + if (!d->text_class_) return; if (!d->text_class_->hasLayout(layout)) @@ -691,7 +691,7 @@ void LayoutBox::selected(int index) d->model_->itemFromIndex(mindex)->text()); d->owner_.setFocus(); - if (!d->text_class_.get()) { + if (!d->text_class_) { updateContents(false); d->resetFilter(); return; diff --git a/src/graphics/GraphicsCacheItem.cpp b/src/graphics/GraphicsCacheItem.cpp index fafa78bdcb..8183fea61e 100644 --- a/src/graphics/GraphicsCacheItem.cpp +++ b/src/graphics/GraphicsCacheItem.cpp @@ -235,7 +235,7 @@ void CacheItem::Impl::reset() file_to_load_.erase(); to_.erase(); - if (image_.get()) + if (image_) image_.reset(); status_ = WaitingToLoad; diff --git a/src/graphics/GraphicsLoader.cpp b/src/graphics/GraphicsLoader.cpp index 36f2839446..f635e0b321 100644 --- a/src/graphics/GraphicsLoader.cpp +++ b/src/graphics/GraphicsLoader.cpp @@ -273,7 +273,7 @@ void Loader::reset(Params const & params) const void Loader::startLoading() const { - if (pimpl_->status_ != WaitingToLoad || !pimpl_->cached_item_.get()) + if (pimpl_->status_ != WaitingToLoad || !pimpl_->cached_item_) return; pimpl_->startLoading(); } @@ -287,7 +287,7 @@ void Loader::reload() const void Loader::startMonitoring() const { - if (!pimpl_->cached_item_.get()) + if (!pimpl_->cached_item_) return; pimpl_->cached_item_->startMonitoring(); @@ -296,7 +296,7 @@ void Loader::startMonitoring() const bool Loader::monitoring() const { - if (!pimpl_->cached_item_.get()) + if (!pimpl_->cached_item_) return false; return pimpl_->cached_item_->monitoring(); @@ -305,7 +305,7 @@ bool Loader::monitoring() const unsigned long Loader::checksum() const { - if (!pimpl_->cached_item_.get()) + if (!pimpl_->cached_item_) return 0; return pimpl_->cached_item_->checksum(); @@ -315,7 +315,7 @@ unsigned long Loader::checksum() const FileName const & Loader::filename() const { static FileName const empty; - return pimpl_->cached_item_.get() ? + return pimpl_->cached_item_ ? pimpl_->cached_item_->filename() : empty; } @@ -352,7 +352,7 @@ Loader::Impl::~Impl() void Loader::Impl::resetFile(FileName const & file) { - FileName const old_file = cached_item_.get() ? + FileName const old_file = cached_item_ ? cached_item_->filename() : FileName(); if (file == old_file) @@ -375,10 +375,10 @@ void Loader::Impl::resetFile(FileName const & file) } } - status_ = cached_item_.get() ? cached_item_->status() : WaitingToLoad; + status_ = cached_item_ ? cached_item_->status() : WaitingToLoad; image_.reset(); - if (cached_item_.get() || file.empty()) + if (cached_item_ || file.empty()) return; Cache & gc = Cache::get(); @@ -402,14 +402,14 @@ void Loader::Impl::resetParams(Params const & params) return; params_ = params; - status_ = cached_item_.get() ? cached_item_->status() : WaitingToLoad; + status_ = cached_item_ ? cached_item_->status() : WaitingToLoad; image_.reset(); } void Loader::Impl::statusChanged() { - status_ = cached_item_.get() ? cached_item_->status() : WaitingToLoad; + status_ = cached_item_ ? cached_item_->status() : WaitingToLoad; createPixmap(); signal_(); } @@ -420,7 +420,7 @@ void Loader::Impl::createPixmap() if (!params_.display || status_ != Loaded) return; - if (!cached_item_.get()) { + if (!cached_item_) { LYXERR(Debug::GRAPHICS, "pixmap not cached yet"); return; } diff --git a/src/support/ForkedCalls.cpp b/src/support/ForkedCalls.cpp index 1c5e663723..0378b05bf1 100644 --- a/src/support/ForkedCalls.cpp +++ b/src/support/ForkedCalls.cpp @@ -113,7 +113,7 @@ bool ForkedProcess::IAmAChild = false; void ForkedProcess::emitSignal() { - if (signal_.get()) { + if (signal_) { signal_->operator()(pid_, retval_); } }