CSortedList.h
//-----------------------------------------------------------------------------
// $Header: CSortedList.h,v 1.3 97/04/25 21:32:14 messer Exp $
//
// COOL Program Library
// Copyright (C) CERES collaboration, 1996
//
// Declaration of template class CSortedList.
// This class behaves as a RWTPtrSortedVector<T>. The internal
// implementation however may change for persistency.
// Note that in order to implement the function getIndexOfBestMatch we
// must require the definition of the - operator for the items of type T
// consistently with the < operator.
//-----------------------------------------------------------------------------
#ifndef CSORTEDLIST_H
#define CSORTEDLIST_H
#include <rw/tpordvec.h>
#include <rw/tpsrtvec.h>
#include "cool.h"
template<class T> class CSortedList {
public:
CSortedList();
CSortedList(const CSortedList<T>&);
CSortedList<T>& operator= (const CSortedList<T>&);
virtual ~CSortedList();
T*& operator()(size_t i);
T*const& operator()(size_t i) const;
T*& operator[](size_t i);
T*const& operator[](size_t i) const;
void append(T*);
void insert(T*);
void clear();
void clearAndDestroy();
size_t entries() const;
size_t length() const;
T*& first();
T*const& first() const;
T*& last();
T*const& last() const;
T* removeAt(size_t);
CBoolean isEmpty() const;
size_t getIndexOfBestMatch(const T*) const;
size_t getIndexOfBestMatch(const T&) const;
const RWTPtrSortedVector<T>* getInternalVector() const { return &items; }
private:
size_t _getIndexOfBestMatch(const T*) const;
private:
RWTPtrSortedVector<T> items;
};
template<class T> inline CSortedList<T>::CSortedList() { /* nop */ }
template<class T> inline CSortedList<T>::CSortedList(const CSortedList<T>& lis)
{
items = lis.items;
}
template<class T> inline CSortedList<T>& CSortedList<T>::operator= (const CSortedList<T>& lis)
{
if (&lis != this) items = lis.items;
return *this;
}
template<class T> inline CSortedList<T>::~CSortedList()
{
items.clearAndDestroy();
}
template<class T> inline T*& CSortedList<T>::operator()(size_t i)
{
return items(i);
}
template<class T> inline T*const& CSortedList<T>::operator()(size_t i) const
{
return items(i);
}
template<class T> inline T*& CSortedList<T>::operator[](size_t i)
{
return items[i];
}
template<class T> inline T*const& CSortedList<T>::operator[](size_t i) const
{
return items[i];
}
template<class T> inline void CSortedList<T>::append(T* item)
{
items.append(item);
}
template<class T> inline void CSortedList<T>::insert(T* item)
{
items.insert(item);
}
template<class T> inline void CSortedList<T>::clear()
{
items.clear();
}
template<class T> inline void CSortedList<T>::clearAndDestroy()
{
items.clearAndDestroy();
}
template<class T> inline size_t CSortedList<T>::entries() const
{
return items.entries();
}
template<class T> inline size_t CSortedList<T>::length() const
{
return items.length();
}
template<class T> inline T*& CSortedList<T>::first()
{
return items.first();
}
template<class T> inline T*const& CSortedList<T>::first() const
{
return items.first();
}
template<class T> inline T*& CSortedList<T>::last()
{
return items.last();
}
template<class T> inline T*const& CSortedList<T>::last() const
{
return items.last();
}
template<class T> inline T* CSortedList<T>::removeAt(size_t i)
{
return items.removeAt(i);
}
template<class T> inline CBoolean CSortedList<T>::isEmpty() const
{
return items.isEmpty();
}
template<class T> inline size_t CSortedList<T>::getIndexOfBestMatch(const T* item) const
{
return _getIndexOfBestMatch(item);
}
template<class T> inline size_t CSortedList<T>::getIndexOfBestMatch(const T& item) const
{
return _getIndexOfBestMatch(&item);
}
#ifdef RW_COMPILE_INSTANTIATE
#include "CSortedList.C"
#endif
#endif /* CSORTEDLIST_H */