/** True if there are items of a certain kind. */
bool empty( const ResKind & kind_r ) const;
- template<class _Res>
+ template<class TRes>
bool empty() const
- { return empty( ResTraits<_Res>::kind ); }
+ { return empty( ResTraits<TRes>::kind ); }
/** Number of Items of a certain kind. */
size_type size( const ResKind & kind_r ) const;
- template<class _Res>
+ template<class TRes>
size_type size() const
- { return size( ResTraits<_Res>::kind ); }
+ { return size( ResTraits<TRes>::kind ); }
const_iterator byKindBegin( const ResKind & kind_r ) const;
- template<class _Res>
+ template<class TRes>
const_iterator byKindBegin() const
- { return byKindBegin( ResTraits<_Res>::kind ); }
+ { return byKindBegin( ResTraits<TRes>::kind ); }
const_iterator byKindEnd( const ResKind & kind_r ) const;
- template<class _Res>
+ template<class TRes>
const_iterator byKindEnd() const
- { return byKindEnd( ResTraits<_Res>::kind ); }
+ { return byKindEnd( ResTraits<TRes>::kind ); }
+
+
+ Iterable<const_iterator> byKind( const ResKind & kind_r ) const
+ { return makeIterable( byKindBegin( kind_r ), byKindEnd( kind_r ) ); }
+
+ template<class TRes>
+ Iterable<const_iterator> byKind() const
+ { return makeIterable( byKindBegin<TRes>(), byKindEnd<TRes>() ); }
+
//@}
public:
repository_iterator knownRepositoriesBegin() const;
repository_iterator knownRepositoriesEnd() const;
+
+ Iterable<repository_iterator> knownRepositories() const
+ { return makeIterable( knownRepositoriesBegin(), knownRepositoriesEnd() ); }
//@}
public:
!= make_end<ui::selfilter::ByHasInstalledObj>( kind_r ) );
}
- template<class _Res>
+ template<class TRes>
bool hasInstalledObj() const
- { return hasInstalledObj( ResTraits<_Res>::kind ); }
+ { return hasInstalledObj( ResTraits<TRes>::kind ); }
public:
/** \name Save and restore state per kind of resolvable.
- * Simple version, no savety net. So don't restore or diff,
+ * Simple version, no safety net. So don't restore or diff,
* if you didn't save before.
*
* Diff returns true, if current stat differs from the saved
* state.
- */
+ *
+ * Use \ref scopedSaveState for exception safe scoped save/restore
+ */
//@{
void saveState() const;
void saveState( const ResKind & kind_r ) const;
- template<class _Res>
+ template<class TRes>
void saveState() const
- { return saveState( ResTraits<_Res>::kind ); }
+ { return saveState( ResTraits<TRes>::kind ); }
void restoreState() const;
void restoreState( const ResKind & kind_r ) const;
- template<class _Res>
+ template<class TRes>
void restoreState() const
- { return restoreState( ResTraits<_Res>::kind ); }
+ { return restoreState( ResTraits<TRes>::kind ); }
bool diffState() const;
bool diffState( const ResKind & kind_r ) const;
- template<class _Res>
+ template<class TRes>
bool diffState() const
- { return diffState( ResTraits<_Res>::kind ); }
+ { return diffState( ResTraits<TRes>::kind ); }
+
+ /**
+ * \class ScopedSaveState
+ * \brief Exception safe scoped save/restore state.
+ * Call \ref acceptState to prevent the class from restoring
+ * the remembered state.
+ * \ingroup g_RAII
+ */
+ struct ScopedSaveState;
+
+ ScopedSaveState scopedSaveState() const;
+
+ ScopedSaveState scopedSaveState( const ResKind & kind_r ) const;
+
+ template<class TRes>
+ ScopedSaveState && scopedSaveState() const
+ { return scopedSaveState( ResTraits<TRes>::kind ); }
+
//@}
private:
- template<class _Filter>
- filter_iterator<_Filter,const_iterator>
- make_begin( _Filter filter_r, const ResKind & kind_r ) const
+ template<class TFilter>
+ filter_iterator<TFilter,const_iterator>
+ make_begin( TFilter filter_r, const ResKind & kind_r ) const
{
return make_filter_iterator( filter_r,
byKindBegin(kind_r),
byKindEnd(kind_r) );
}
- template<class _Filter>
- filter_iterator<_Filter,const_iterator>
+ template<class TFilter>
+ filter_iterator<TFilter,const_iterator>
make_begin( const ResKind & kind_r ) const
{
- return make_begin( _Filter(), kind_r );
+ return make_begin( TFilter(), kind_r );
}
- template<class _Filter>
- filter_iterator<_Filter,const_iterator>
- make_end( _Filter filter_r, const ResKind & kind_r ) const
+ template<class TFilter>
+ filter_iterator<TFilter,const_iterator>
+ make_end( TFilter filter_r, const ResKind & kind_r ) const
{
return make_filter_iterator( filter_r,
byKindEnd(kind_r),
byKindEnd(kind_r) );
}
- template<class _Filter>
- filter_iterator<_Filter,const_iterator>
+ template<class TFilter>
+ filter_iterator<TFilter,const_iterator>
make_end( const ResKind & kind_r ) const
{
- return make_end( _Filter(), kind_r );
+ return make_end( TFilter(), kind_r );
}
private:
/** \relates ResPoolProxy Verbose stream output */
std::ostream & dumpOn( std::ostream & str, const ResPoolProxy & obj );
+ ///////////////////////////////////////////////////////////////////
+
+ struct ResPoolProxy::ScopedSaveState
+ {
+ NON_COPYABLE_BUT_MOVE( ScopedSaveState );
+
+ ScopedSaveState( const ResPoolProxy & pool_r )
+ : _pimpl( new Impl( pool_r ) )
+ { _pimpl->saveState(); }
+
+ ScopedSaveState( const ResPoolProxy & pool_r, const ResKind & kind_r )
+ : _pimpl( new Impl( pool_r, kind_r ) )
+ { _pimpl->saveState(); }
+
+ ~ScopedSaveState()
+ { if ( _pimpl ) _pimpl->restoreState(); }
+
+ void acceptState()
+ { _pimpl.reset(); }
+
+ private:
+ struct Impl
+ {
+ Impl( const ResPoolProxy & pool_r )
+ : _pool( pool_r )
+ {}
+ Impl( const ResPoolProxy & pool_r, const ResKind & kind_r )
+ : _pool( pool_r ), _kind( new ResKind( kind_r ) )
+ {}
+ void saveState()
+ { if ( _kind ) _pool.saveState( *_kind ); else _pool.saveState(); }
+ void restoreState()
+ { if ( _kind ) _pool.restoreState( *_kind ); else _pool.restoreState(); }
+ ResPoolProxy _pool;
+ scoped_ptr<ResKind> _kind;
+
+ };
+ std::unique_ptr<Impl> _pimpl;
+ };
+
+ inline ResPoolProxy::ScopedSaveState ResPoolProxy::scopedSaveState() const
+ { return ScopedSaveState( *this ); }
+
+ inline ResPoolProxy::ScopedSaveState ResPoolProxy::scopedSaveState( const ResKind & kind_r ) const
+ { return ScopedSaveState( *this, kind_r ); }
+
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////