TagLib API Documentation
Public Member Functions | Protected Member Functions | List of all members
TagLib::List< T > Class Template Reference

A generic, implicitly shared list. More...

#include <tlist.h>

Inheritance diagram for TagLib::List< T >:
[legend]

Public Member Functions

 List ()
 
 List (const List< T > &l)
 
 List (std::initializer_list< T > init)
 
 ~List ()
 
Iterator begin ()
 
ConstIterator begin () const
 
ConstIterator cbegin () const
 
Iterator end ()
 
ConstIterator end () const
 
ConstIterator cend () const
 
Iterator insert (Iterator it, const T &item)
 
List< T > & sortedInsert (const T &value, bool unique=false)
 
List< T > & append (const T &item)
 
List< T > & append (const List< T > &l)
 
List< T > & prepend (const T &item)
 
List< T > & prepend (const List< T > &l)
 
List< T > & clear ()
 
unsigned int size () const
 
bool isEmpty () const
 
Iterator find (const T &value)
 
ConstIterator find (const T &value) const
 
ConstIterator cfind (const T &value) const
 
bool contains (const T &value) const
 
Iterator erase (Iterator it)
 
const T & front () const
 
T & front ()
 
const T & back () const
 
T & back ()
 
void setAutoDelete (bool autoDelete)
 
bool autoDelete () const
 
T & operator[] (unsigned int i)
 
const T & operator[] (unsigned int i) const
 
List< T > & operator= (const List< T > &l)
 
List< T > & operator= (std::initializer_list< T > init)
 
void swap (List< T > &l) noexcept
 
bool operator== (const List< T > &l) const
 
bool operator!= (const List< T > &l) const
 
void sort ()
 
template<class Compare >
void sort (Compare &&comp)
 

Protected Member Functions

void detach ()
 

Detailed Description

template<class T>
class TagLib::List< T >

A generic, implicitly shared list.

This is a basic generic list that's somewhere between a std::list and a QList. This class is implicitly shared. For example:

TagLib::List<int> l = someOtherIntList;
A generic, implicitly shared list.
Definition: tlist.h:54

The above example is very cheap. This also makes lists suitable as return types of functions. The above example will just copy a pointer rather than copying the data in the list. When your shared list's data changes, only then will the data be copied.

Constructor & Destructor Documentation

◆ List() [1/3]

template<class T >
TagLib::List< T >::List ( )

Constructs an empty list.

◆ List() [2/3]

template<class T >
TagLib::List< T >::List ( const List< T > &  l)

Make a shallow, implicitly shared, copy of l. Because this is implicitly shared, this method is lightweight and suitable for pass-by-value usage.

◆ List() [3/3]

template<class T >
TagLib::List< T >::List ( std::initializer_list< T >  init)

Construct a List with the contents of the braced initializer list.

◆ ~List()

template<class T >
TagLib::List< T >::~List ( )

Destroys this List instance. If auto deletion is enabled and this list contains a pointer type, all of the members are also deleted.

Member Function Documentation

◆ append() [1/2]

template<class T >
List< T > & TagLib::List< T >::append ( const List< T > &  l)

Appends all of the values in l to the end of the list and returns a reference to the list.

◆ append() [2/2]

template<class T >
List< T > & TagLib::List< T >::append ( const T &  item)

Appends item to the end of the list and returns a reference to the list.

◆ autoDelete()

template<class T >
bool TagLib::List< T >::autoDelete ( ) const

Returns true if auto-deletion is enabled.

◆ back() [1/2]

template<class T >
T & TagLib::List< T >::back ( )

Returns a reference to the last item in the list.

◆ back() [2/2]

template<class T >
const T & TagLib::List< T >::back ( ) const

Returns a reference to the last item in the list.

◆ begin() [1/2]

template<class T >
Iterator TagLib::List< T >::begin ( )

Returns an STL style iterator to the beginning of the list. See std::list::const_iterator for the semantics.

◆ begin() [2/2]

template<class T >
ConstIterator TagLib::List< T >::begin ( ) const

Returns an STL style constant iterator to the beginning of the list. See std::list::iterator for the semantics.

◆ cbegin()

template<class T >
ConstIterator TagLib::List< T >::cbegin ( ) const

Returns an STL style constant iterator to the beginning of the list. See std::list::iterator for the semantics.

◆ cend()

template<class T >
ConstIterator TagLib::List< T >::cend ( ) const

Returns an STL style constant iterator to the end of the list. See std::list::const_iterator for the semantics.

◆ cfind()

template<class T >
ConstIterator TagLib::List< T >::cfind ( const T &  value) const

Find the first occurrence of value.

◆ clear()

template<class T >
List< T > & TagLib::List< T >::clear ( )

Clears the list. If auto deletion is enabled and this list contains a pointer type the members are also deleted.

See also
setAutoDelete()

◆ contains()

template<class T >
bool TagLib::List< T >::contains ( const T &  value) const

Returns true if the list contains value.

◆ detach()

template<class T >
void TagLib::List< T >::detach ( )
protected

If this List is being shared via implicit sharing, do a deep copy of the data and separate from the shared members. This should be called by all non-const subclass members without Iterator parameters.

◆ end() [1/2]

template<class T >
Iterator TagLib::List< T >::end ( )

Returns an STL style iterator to the end of the list. See std::list::iterator for the semantics.

◆ end() [2/2]

template<class T >
ConstIterator TagLib::List< T >::end ( ) const

Returns an STL style constant iterator to the end of the list. See std::list::const_iterator for the semantics.

◆ erase()

template<class T >
Iterator TagLib::List< T >::erase ( Iterator  it)

Erase the item at it from the list.

Note
This method cannot detach because it is tied to the internal list. Do not make an implicitly shared copy of this list between getting the iterator and calling this method!

◆ find() [1/2]

template<class T >
Iterator TagLib::List< T >::find ( const T &  value)

Find the first occurrence of value.

◆ find() [2/2]

template<class T >
ConstIterator TagLib::List< T >::find ( const T &  value) const

Find the first occurrence of value.

◆ front() [1/2]

template<class T >
T & TagLib::List< T >::front ( )

Returns a reference to the first item in the list.

◆ front() [2/2]

template<class T >
const T & TagLib::List< T >::front ( ) const

Returns a reference to the first item in the list.

◆ insert()

template<class T >
Iterator TagLib::List< T >::insert ( Iterator  it,
const T &  item 
)

Inserts a copy of item before it.

Note
This method cannot detach because it is tied to the internal list. Do not make an implicitly shared copy of this list between getting the iterator and calling this method!

◆ isEmpty()

template<class T >
bool TagLib::List< T >::isEmpty ( ) const

Returns whether or not the list is empty.

See also
size()

◆ operator!=()

template<class T >
bool TagLib::List< T >::operator!= ( const List< T > &  l) const

Compares this list with l and returns true if the lists differ.

◆ operator=() [1/2]

template<class T >
List< T > & TagLib::List< T >::operator= ( const List< T > &  l)

Make a shallow, implicitly shared, copy of l. Because this is implicitly shared, this method is lightweight and suitable for pass-by-value usage.

◆ operator=() [2/2]

template<class T >
List< T > & TagLib::List< T >::operator= ( std::initializer_list< T >  init)

Replace the contents of the list with those of the braced initializer list.

If auto deletion is enabled and the list contains a pointer type, the members are also deleted

◆ operator==()

template<class T >
bool TagLib::List< T >::operator== ( const List< T > &  l) const

Compares this list with l and returns true if all of the elements are the same.

◆ operator[]() [1/2]

template<class T >
T & TagLib::List< T >::operator[] ( unsigned int  i)

Returns a reference to item i in the list.

Warning
This method is slow. Use iterators to loop through the list.

◆ operator[]() [2/2]

template<class T >
const T & TagLib::List< T >::operator[] ( unsigned int  i) const

Returns a const reference to item i in the list.

Warning
This method is slow. Use iterators to loop through the list.

◆ prepend() [1/2]

template<class T >
List< T > & TagLib::List< T >::prepend ( const List< T > &  l)

Prepends all of the items in l to the beginning list and returns a reference to the list.

◆ prepend() [2/2]

template<class T >
List< T > & TagLib::List< T >::prepend ( const T &  item)

Prepends item to the beginning list and returns a reference to the list.

◆ setAutoDelete()

template<class T >
void TagLib::List< T >::setAutoDelete ( bool  autoDelete)

Auto delete the members of the list when the last reference to the list passes out of scope. This will have no effect on lists which do not contain a pointer type.

Note
This relies on partial template instantiation – most modern C++ compilers should now support this.

◆ size()

template<class T >
unsigned int TagLib::List< T >::size ( ) const

Returns the number of elements in the list.

See also
isEmpty()

◆ sort() [1/2]

template<class T >
void TagLib::List< T >::sort ( )

Sorts this list in ascending order using operator< of T.

◆ sort() [2/2]

template<class T >
template<class Compare >
void TagLib::List< T >::sort ( Compare &&  comp)

Sorts this list in ascending order using the comparison function object comp which returns true if the first argument is less than the second.

◆ sortedInsert()

template<class T >
List< T > & TagLib::List< T >::sortedInsert ( const T &  value,
bool  unique = false 
)

Inserts the value into the list. This assumes that the list is currently sorted. If unique is true then the value will not be inserted if it is already in the list.

◆ swap()

template<class T >
void TagLib::List< T >::swap ( List< T > &  l)
noexcept

Exchanges the content of this list with the content of l.


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