Mantid
Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Mantid::Kernel::MRUList< T > Class Template Reference

An MRU (most recently used) list keeps record of the last n inserted items, listing first the newer ones. More...

#include <MRUList.h>

Public Member Functions

void clear ()
 Delete all the T's pointed to by the list, and empty the list itself. More...
 
void deleteIndex (const uintptr_t index)
 Delete the T at the given index. More...
 
T * find (const uintptr_t index) const
 Find an element of the list from the key of the index. More...
 
std::shared_ptr< T > insert (std::shared_ptr< T > item)
 Insert an item into the list. More...
 
 MRUList ()
 Constructor. More...
 
 MRUList (const std::size_t &max_num_items_)
 Constructor. More...
 
size_t size () const
 Size of the list. More...
 
 ~MRUList ()
 Destructor. More...
 

Private Types

using item_list = typename boost::multi_index::multi_index_container< std::shared_ptr< T >, boost::multi_index::indexed_by< boost::multi_index::sequenced<>, boost::multi_index::hashed_unique<::boost::multi_index::const_mem_fun< T, std::uintptr_t, &T::hashIndexFunction > > > >
 hideous typedef for the container holding the list More...
 
using ordered_item_list = typename boost::multi_index::nth_index< item_list, 1 >::type
 This typedef makes an ordered item list (you access it by the 1st index) More...
 

Private Member Functions

 MRUList (MRUList &)
 Private, unimplemented copy constructor. More...
 
MRUListoperator= (MRUList &)
 Private, unimplemented copy assignment operator. More...
 

Private Attributes

item_list il
 The most recently used list. More...
 
std::mutex m_mutex
 Mutex for modifying the MRU list. More...
 
const std::size_t max_num_items
 The length of the list. More...
 

Detailed Description

template<class T>
class Mantid::Kernel::MRUList< T >

An MRU (most recently used) list keeps record of the last n inserted items, listing first the newer ones.

Care has to be taken when a duplicate item is inserted: instead of letting it appear twice, the MRU list relocates it to the first position. This class has been largely taken from one of the examples given in the Boost.MultiIndex documentation (http://www.boost.org/libs/multi_index/doc/reference/index.html)

Definition at line 32 of file MRUList.h.

Member Typedef Documentation

◆ item_list

template<class T >
using Mantid::Kernel::MRUList< T >::item_list = typename boost::multi_index::multi_index_container< std::shared_ptr<T>, boost::multi_index::indexed_by<boost::multi_index::sequenced<>, boost::multi_index::hashed_unique<::boost::multi_index::const_mem_fun< T, std::uintptr_t, &T::hashIndexFunction> >> >
private

hideous typedef for the container holding the list

Definition at line 35 of file MRUList.h.

◆ ordered_item_list

template<class T >
using Mantid::Kernel::MRUList< T >::ordered_item_list = typename boost::multi_index::nth_index<item_list, 1>::type
private

This typedef makes an ordered item list (you access it by the 1st index)

Definition at line 42 of file MRUList.h.

Constructor & Destructor Documentation

◆ MRUList() [1/3]

template<class T >
Mantid::Kernel::MRUList< T >::MRUList ( const std::size_t &  max_num_items_)
inline

Constructor.

Parameters
max_num_items_:: The length of the list

Definition at line 54 of file MRUList.h.

◆ MRUList() [2/3]

template<class T >
Mantid::Kernel::MRUList< T >::MRUList ( )
inline

Constructor.

Default to 100 items.

Definition at line 59 of file MRUList.h.

◆ ~MRUList()

template<class T >
Mantid::Kernel::MRUList< T >::~MRUList ( )
inline

Destructor.

Definition at line 64 of file MRUList.h.

◆ MRUList() [3/3]

template<class T >
Mantid::Kernel::MRUList< T >::MRUList ( MRUList< T > &  )
private

Private, unimplemented copy constructor.

Member Function Documentation

◆ clear()

template<class T >
void Mantid::Kernel::MRUList< T >::clear ( )
inline

Delete all the T's pointed to by the list, and empty the list itself.

Definition at line 107 of file MRUList.h.

◆ deleteIndex()

template<class T >
void Mantid::Kernel::MRUList< T >::deleteIndex ( const uintptr_t  index)
inline

Delete the T at the given index.

Will also delete the object itself.

Parameters
index:: the key (index) for this T that you want to remove from the MRU.

Definition at line 117 of file MRUList.h.

References index.

◆ find()

template<class T >
T * Mantid::Kernel::MRUList< T >::find ( const uintptr_t  index) const
inline

Find an element of the list from the key of the index.

Parameters
index:: The index value to search the list for
Returns
The object found, or NULL if not found.

Definition at line 135 of file MRUList.h.

References index.

◆ insert()

template<class T >
std::shared_ptr< T > Mantid::Kernel::MRUList< T >::insert ( std::shared_ptr< T >  item)
inline

Insert an item into the list.

If it's already in the list, it's moved to the top. If it's a new item, it's put at the top and the last item in the list is written to file and dropped.

Parameters
item:: The item, of type T, to put in the list
Returns
pointer to an item that is being dropped from the MRU. The calling code can do stuff to it (save it) and needs to delete it. NULL if nothing needs to be dropped.

Definition at line 78 of file MRUList.h.

◆ operator=()

template<class T >
MRUList & Mantid::Kernel::MRUList< T >::operator= ( MRUList< T > &  )
private

Private, unimplemented copy assignment operator.

◆ size()

template<class T >
size_t Mantid::Kernel::MRUList< T >::size ( ) const
inline

Size of the list.

Definition at line 128 of file MRUList.h.

Member Data Documentation

◆ il

template<class T >
item_list Mantid::Kernel::MRUList< T >::il
mutableprivate

The most recently used list.

Definition at line 45 of file MRUList.h.

◆ m_mutex

template<class T >
std::mutex Mantid::Kernel::MRUList< T >::m_mutex
mutableprivate

Mutex for modifying the MRU list.

Definition at line 153 of file MRUList.h.

◆ max_num_items

template<class T >
const std::size_t Mantid::Kernel::MRUList< T >::max_num_items
private

The length of the list.

Definition at line 47 of file MRUList.h.


The documentation for this class was generated from the following file: