Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
elm::imm::list< T > Class Template Reference

#include <elm/imm/list.h>

+ Inheritance diagram for elm::imm::list< T >:

Classes

class  Collector
 

Public Member Functions

 list (void)
 
 list (const list< T > &l)
 
list< T > & operator= (list< T > l)
 
const T & hd (void) const
 
list< T > tl (void) const
 
const T & operator* (void) const
 
bool isEmpty (void) const
 
 operator bool (void) const
 
int length (void) const
 
bool contains (const T &v)
 
bool equals (list< T > l) const
 
bool operator== (list< T > l) const
 
bool operator!= (list< T > l) const
 
list< T > concat (list< T > l)
 
list< T > remove (const T &h)
 

Static Public Member Functions

static void add (Collector &coll)
 
static void remove (Collector &coll)
 
static list< T > cons (const T &h, list< T > t)
 

Static Public Attributes

static list< T > null
 

Detailed Description

template<class T>
class elm::imm::list< T >

Implementation of immutable and garbage collected list.

As C++ does not allow to implement easily and efficiently a garbage collector, the user of this class is responsible to provided its own collector using the function list<T>::add(object) with object inheriting from list<T>::Collector and implementing the member function list<T>::Collector::collect(). This function must call mark() for each list in use as in the example below:

list<int> first_list;
genstruct::Vector<list<int> > lists;
class MyCollector: public list<int>::Collector {
protected:
virtual void collect(void) {
mark(first_list);
for(int i = 0; i < lists.count(); i++)
mark(lists[i]);
}
};
int main(void) {
MyCollector coll;
// work with lists now
}
Parameters
TType of items in the list.

Constructor & Destructor Documentation

template<class T>
elm::imm::list< T >::list ( void  )

Build an empty list.

template<class T>
elm::imm::list< T >::list ( const list< T > &  l)

Clone a list.

Member Function Documentation

template<class T>
static void elm::imm::list< T >::add ( Collector coll)
static
template<class T>
list< T > elm::imm::list< T >::cons ( const T &  h,
list< T >  t 
)
static

Build a new list by prepending h to t.

Parameters
hItem to prepend.
tList to use as tail.
Returns
Built list.

Referenced by elm::imm::list< T >::concat(), elm::imm::cons(), and elm::imm::list< T >::remove().

template<class T>
bool elm::imm::list< T >::contains ( const T &  v)

Test if v is in the list. The Equiv<T> is used to perform the test of equality. Therefore, a user can provide its own implementation of Equiv<T> to change the usual behavior of the equality tests.

Parameters
vItem to test.
Returns
True if v is in the list, false else.
template<class T>
bool elm::imm::list< T >::equals ( list< T >  l) const

Test if the current list and l are equals.

Parameters
lList to compare.
Returns
True if both lists are equal, false else.

References elm::imm::list< T >::hd(), and elm::imm::list< T >::tl().

Referenced by elm::imm::list< T >::operator!=(), and elm::imm::list< T >::operator==().

template<class T>
const T & elm::imm::list< T >::hd ( void  ) const
template<class T>
bool elm::imm::list< T >::isEmpty ( void  ) const

Test if the list is empty.

Returns
True if the list is empty, false else.

Referenced by elm::imm::list< T >::concat(), and elm::imm::list< T >::operator bool().

template<class T>
int elm::imm::list< T >::length ( void  ) const

Compute the length of the list.

Returns
List length.
template<class T>
elm::imm::list< T >::operator bool ( void  ) const
template<class T>
bool elm::imm::list< T >::operator!= ( list< T >  l) const
template<class T>
const T& elm::imm::list< T >::operator* ( void  ) const
template<class T>
list<T>& elm::imm::list< T >::operator= ( list< T >  l)
template<class T>
bool elm::imm::list< T >::operator== ( list< T >  l) const
template<class T>
static void elm::imm::list< T >::remove ( Collector coll)
static
template<class T>
list< T > elm::imm::list< T >::remove ( const T &  h)

Build a new list without the first instance of h.

Parameters
hItem to remove.
Returns
List without first instance of h.

References elm::imm::list< T >::cons(), elm::imm::list< T >::hd(), and elm::imm::list< T >::tl().

template<class T>
list< T > elm::imm::list< T >::tl ( void  ) const

Get the sub-list after the first item in the list.

Returns
Tail of the list.

Referenced by elm::imm::list< T >::concat(), elm::imm::sorted_list< T, K, C >::contains(), elm::imm::list< T >::equals(), and elm::imm::list< T >::remove().

Member Data Documentation

template<class T>
list< T > elm::imm::list< T >::null
static

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