More idiomatic way of checking if a shared_ptr has an associated managed object

This commit is contained in:
Lars Gullik Bjønnes 2012-10-21 21:04:05 +02:00
parent 1b65a03c13
commit dd2189656b
5 changed files with 23 additions and 24 deletions

View File

@ -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);

View File

@ -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;

View File

@ -235,7 +235,7 @@ void CacheItem::Impl::reset()
file_to_load_.erase();
to_.erase();
if (image_.get())
if (image_)
image_.reset();
status_ = WaitingToLoad;

View File

@ -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;
}

View File

@ -113,7 +113,7 @@ bool ForkedProcess::IAmAChild = false;
void ForkedProcess::emitSignal()
{
if (signal_.get()) {
if (signal_) {
signal_->operator()(pid_, retval_);
}
}