Removed epicsList and associated test file - not used or maintained.

This commit is contained in:
Andrew Johnson
2005-10-28 19:36:09 +00:00
parent eea13fb653
commit 81c052a4e2
6 changed files with 0 additions and 952 deletions

View File

@@ -48,10 +48,7 @@ SRCS += cvtFast.c
SRC_DIRS += $(LIBCOM)/cppStd
INC += epicsAlgorithm.h
INC += epicsExcept.h
INC += epicsList.h
INC += epicsListBase.h
INC += epicsMemory.h
SRCS += epicsListBase.cpp
# From cxxTemplates
SRC_DIRS += $(LIBCOM)/cxxTemplates

View File

@@ -1,458 +0,0 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
// epicsList.h
// Author: Andrew Johnson
// Date: October 2000
#ifndef __EPICS_LIST_H__
#define __EPICS_LIST_H__
#include "epicsListBase.h"
#include <stdexcept>
// epicsList
// ===========
// This implementation omits allocators, and only supports lists of pointers to
// objects. Class templates are not provided, so functions overloaded on input
// iterators are not available, nor are reverse iterators. Some functionality
// makes no sense in this version, for example splice cannot be implemented
// quickly because list nodes must never be transferred to a different list.
// Reference numbers in comments are to sections in ISO/IEC 14882:1998(E)
template <class T> class epicsListIterator;
template <class T> class epicsListConstIterator;
template <class T>
class epicsList {
public:
// Types
typedef size_t size_type;
typedef epicsListIterator<T> iterator;
typedef epicsListConstIterator<T> const_iterator;
// Construct/copy/destroy (23.2.2.1)
epicsList();
~epicsList();
// Iterator support
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
// Capacity
bool empty() const;
size_type size() const;
// Element access
T front();
const T front() const;
T back();
const T back() const;
// Modifiers (23.2.2.3)
void push_front(const T x);
void pop_front();
void push_back(const T x);
void pop_back();
iterator insert(iterator position, const T x);
iterator erase(iterator position);
iterator erase(iterator position, iterator leave);
void swap(epicsList<T>& x);
void clear();
// List operations (23.2.2.4)
// void remove(const T value);
// void unique();
// void reverse();
private: // Prevent compiler-generated functions
epicsList(const epicsList<T>&);
epicsList<T>& operator=(const epicsList<T>&);
private: // Data
size_type _count;
epicsListNode _head;
epicsListNodePool _pool;
friend class epicsListIterator<T>;
friend class epicsListConstIterator<T>;
};
// Specialized algorithms:
template <class T>
inline void epicsListSwap(epicsList<T>& x, epicsList<T>& y) { x.swap(y); }
// Mutable iterator
// These used to be inner classes of epicsList<T>, but MSVC6
// didn't like that so they had to be typedefs...
template <class T>
class epicsListIterator {
public:
epicsListIterator();
// The following are created automatically by C++:
// epicsListIterator(const epicsListIterator& rhs);
// epicsListIterator& operator=(const epicsListIterator& rhs);
T operator*() const;
T operator->() const;
epicsListIterator& operator++();
const epicsListIterator operator++(int);
epicsListIterator& operator--();
const epicsListIterator operator--(int);
bool operator==(const epicsListIterator& rhs) const;
bool operator==(const epicsListConstIterator<T>& rhs) const;
bool operator!=(const epicsListIterator& rhs) const;
bool operator!=(const epicsListConstIterator<T>& rhs) const;
private: // Constructor for List use
epicsListIterator(epicsListNode* node);
private:
epicsListNode* _node;
friend class epicsList<T>;
friend class epicsListConstIterator<T>;
};
// Constant iterator
template <class T>
class epicsListConstIterator {
public:
epicsListConstIterator();
epicsListConstIterator(const epicsListIterator<T>& rhs);
epicsListConstIterator& operator=(const epicsListIterator<T>& rhs);
// The following are created automatically by C++:
// epicsListConstIterator(const epicsListConstIterator& rhs);
// epicsListConstIterator& operator=(const epicsListConstIterator& rhs);
const T operator*() const;
const T operator->() const;
epicsListConstIterator& operator++();
const epicsListConstIterator operator++(int);
epicsListConstIterator& operator--();
const epicsListConstIterator operator--(int);
bool operator==(const epicsListConstIterator& rhs) const;
bool operator==(const epicsListIterator<T>& rhs) const;
bool operator!=(const epicsListConstIterator& rhs) const;
bool operator!=(const epicsListIterator<T>& rhs) const;
private: // Constructor for List use
epicsListConstIterator(const epicsListNode* node);
private:
const epicsListNode* _node;
friend class epicsList<T>;
};
// END OF DECLARATIONS
// INLINE METHODS
// epicsList<T>
template <class T>
inline epicsList<T>::epicsList() :
_count(0), _head(0), _pool() {}
template <class T>
inline epicsList<T>::~epicsList() {}
template <class T>
inline typename epicsList<T>::iterator epicsList<T>::begin() {
return _head.next();
}
template <class T>
inline typename epicsList<T>::const_iterator epicsList<T>::begin() const {
return _head.next();
}
template <class T>
inline typename epicsList<T>::iterator epicsList<T>::end() {
return &_head;
}
template <class T>
inline typename epicsList<T>::const_iterator epicsList<T>::end() const {
return &_head;
}
template <class T>
inline bool epicsList<T>::empty() const {
return (_count == 0);
}
template <class T>
inline typename epicsList<T>::size_type epicsList<T>::size() const {
return _count;
}
template <class T>
inline T epicsList<T>::front() {
if (empty())
throw std::logic_error("epicsList::front: list empty");
return static_cast<T>(_head.next()->payload);
}
template <class T>
inline const T epicsList<T>::front() const {
if (empty())
throw std::logic_error("epicsList::front: list empty");
return static_cast<const T>(_head.next()->payload);
}
template <class T>
inline T epicsList<T>::back() {
if (empty())
throw std::logic_error("epicsList::back: list empty");
return static_cast<T>(_head.prev()->payload);
}
template <class T>
inline const T epicsList<T>::back() const {
if (empty())
throw std::logic_error("epicsList::back: list empty");
return static_cast<const T>(_head.prev()->payload);
}
template <class T>
inline void epicsList<T>::push_front(const T x) {
epicsListNode* node = _pool.allocate();
node->payload = x;
_head.append(*node);
_count++;
}
template <class T>
inline void epicsList<T>::pop_front() {
if (empty())
throw std::logic_error("epicsList::pop_front: list empty");
epicsListNode* node = _head.next();
node->unlink();
_count--;
_pool.free(node);
}
template <class T>
inline void epicsList<T>::push_back(const T x) {
epicsListNode* node = _pool.allocate();
node->payload = x;
_head.insert(*node);
_count++;
}
template <class T>
inline void epicsList<T>::pop_back() {
if (empty())
throw std::logic_error("epicsList::pop_back: list empty");
epicsListNode* node = _head.prev();
node->unlink();
_count--;
_pool.free(node);
}
template <class T>
inline typename epicsList<T>::iterator epicsList<T>::insert(iterator pos, const T x) {
epicsListNode* node = _pool.allocate();
node->payload = x;
pos._node->insert(*node);
_count++;
return node;
}
template <class T>
inline typename epicsList<T>::iterator epicsList<T>::erase(iterator pos) {
if ((pos._node == 0) || (pos._node == &_head))
return pos;
iterator next = pos._node->next();
pos._node->unlink();
_count--;
_pool.free(pos._node);
return next;
}
template <class T>
inline typename epicsList<T>::iterator epicsList<T>::erase(iterator pos, iterator leave) {
while (pos != leave) {
pos = erase(pos);
}
return pos;
}
template <class T>
inline void epicsList<T>::swap(epicsList<T>& x) {
_head.swap(x._head);
_pool.swap(x._pool);
epicsSwap(x._count, _count);
}
template <class T>
inline void epicsList<T>::clear() {
if (!empty())
erase(begin(), end());
}
// epicsListIterator<T>
template <class T>
inline epicsListIterator<T>::epicsListIterator() :
_node(0) {}
template <class T>
inline epicsListIterator<T>::epicsListIterator(epicsListNode* node) :
_node(node) {}
template <class T>
inline T epicsListIterator<T>::operator*() const {
return static_cast<T>(_node->payload);
}
template <class T>
inline T epicsListIterator<T>::operator->() const {
return static_cast<T>(_node->payload);
}
template <class T>
inline epicsListIterator<T>& epicsListIterator<T>::operator++() {
_node = _node->next();
return *this;
}
template <class T>
inline const epicsListIterator<T> epicsListIterator<T>::operator++(int) {
epicsListIterator<T> temp = *this;
++(*this);
return temp;
}
template <class T>
inline epicsListIterator<T>& epicsListIterator<T>::operator--() {
_node = _node->prev();
return *this;
}
template <class T>
inline const epicsListIterator<T> epicsListIterator<T>::operator--(int) {
epicsListIterator<T> temp = *this;
--(*this);
return temp;
}
template <class T>
inline bool epicsListIterator<T>::operator==(const epicsListIterator<T>& rhs) const {
return (_node == rhs._node);
}
template <class T>
inline bool epicsListIterator<T>::operator==(const epicsListConstIterator<T>& rhs) const {
return (rhs == *this);
}
template <class T>
inline bool epicsListIterator<T>::operator!=(const epicsListIterator<T>& rhs) const {
return !(_node == rhs._node);
}
template <class T>
inline bool epicsListIterator<T>::operator!=(const epicsListConstIterator<T>& rhs) const {
return !(rhs == *this);
}
// epicsListConstIterator<T>
template <class T>
inline epicsListConstIterator<T>::epicsListConstIterator() :
_node(0) {}
template <class T>
inline epicsListConstIterator<T>::epicsListConstIterator(const epicsListIterator<T>& rhs) :
_node(rhs._node) {}
template <class T>
inline epicsListConstIterator<T>::epicsListConstIterator(const epicsListNode* node) :
_node(node) {}
template <class T>
inline epicsListConstIterator<T>&
epicsListConstIterator<T>::operator=(const epicsListIterator<T>& rhs){
_node = rhs._node;
return *this;
}
template <class T>
inline const T epicsListConstIterator<T>::operator*() const {
return static_cast<T>(_node->payload);
}
template <class T>
inline const T epicsListConstIterator<T>::operator->() const {
return static_cast<T>(_node->payload);
}
template <class T>
inline epicsListConstIterator<T>& epicsListConstIterator<T>::operator++() {
_node = _node->next();
return *this;
}
template <class T>
inline const epicsListConstIterator<T> epicsListConstIterator<T>::operator++(int) {
epicsListConstIterator<T> temp = *this;
++(*this);
return temp;
}
template <class T>
inline epicsListConstIterator<T>& epicsListConstIterator<T>::operator--() {
_node = _node->prev();
return *this;
}
template <class T>
inline const epicsListConstIterator<T> epicsListConstIterator<T>::operator--(int) {
epicsListConstIterator<T> temp = *this;
--(*this);
return temp;
}
template <class T>
inline bool
epicsListConstIterator<T>::operator==(const epicsListConstIterator<T>& rhs) const {
return (_node == rhs._node);
}
template <class T>
inline bool epicsListConstIterator<T>::operator==(const epicsListIterator<T>& rhs) const {
return (_node == rhs._node);
}
template <class T>
inline bool
epicsListConstIterator<T>::operator!=(const epicsListConstIterator<T>& rhs) const {
return !(_node == rhs._node);
}
template <class T>
inline bool epicsListConstIterator<T>::operator!=(const epicsListIterator<T>& rhs) const {
return !(_node == rhs._node);
}
#endif

View File

@@ -1,53 +0,0 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
// epicsListBase.cpp
// Author: Andrew Johnson
// Date: October 2000
#ifdef __GNUG__
#pragma implementation
#endif
#define epicsExportSharedSymbols
#include "epicsListBase.h"
#include "cantProceed.h"
// epicsListNodePool
epicsMutex epicsListNodePool::_mutex;
epicsListLink epicsListNodePool::_store;
epicsShareFunc epicsShareAPI epicsListNodePool::~epicsListNodePool() {
while (_blocks.hasNext()) {
epicsListNodeBlock* block =
static_cast<epicsListNodeBlock*>(_blocks.extract());
block->reset();
_mutex.lock();
_store.append(block);
_mutex.unlock();
}
}
epicsShareFunc void epicsShareAPI epicsListNodePool::extend() {
assert(!_free.hasNext());
epicsListNodeBlock* block = 0;
if (_store.hasNext()) {
_mutex.lock();
if (_store.hasNext())
block = static_cast<epicsListNodeBlock*>(_store.extract());
_mutex.unlock();
}
if (block == 0)
block = new epicsListNodeBlock;
if (block == 0) // in case new didn't throw...
cantProceed("epicsList: out of memory");
_blocks.append(block);
_free.set(block->first());
}

View File

@@ -1,240 +0,0 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
// epicsListBase.h
// Author: Andrew Johnson
// Date: October 2000
#ifndef __EPICS_LIST_BASE_H__
#define __EPICS_LIST_BASE_H__
#ifdef __GNUG__
#pragma interface
#endif
#include "epicsMutex.h"
#include "epicsAlgorithm.h"
// epicsListNode
class epicsListNode {
public:
epicsListNode(int /*dummy*/); // constructor for epicsList<T>._head
// Status queries
bool hasNext() const;
epicsListNode* next() const;
epicsListNode* prev() const;
// Node operations
void insert(epicsListNode& node);
void append(epicsListNode& node);
void unlink();
void swap(epicsListNode& node);
private: // Constructor for epicsListNodeBlock._node[]
epicsListNode();
private: // Data - must start with the _next pointer
epicsListNode* _next;
epicsListNode* _prev;
public: // Data
void* payload;
friend class epicsListNodeBlock;
};
// epicsListLink
class epicsListLink {
public:
epicsListLink();
// Status queries
bool hasNext() const;
// list operations
void set(epicsListLink* node);
void append(epicsListLink* node);
epicsListLink* extract();
void swap(epicsListLink& node);
private:
epicsListLink* _next;
};
// epicsListNodeBlock
class epicsListNodeBlock : public epicsListLink {
public:
epicsListNodeBlock();
// operations
epicsListLink* first();
void reset();
private: // Data
enum {blocksize = 256}; // Poor man's const int, for MSVC++
epicsListNode _node[blocksize];
};
// epicsListNodePool
class epicsListNodePool {
public:
epicsListNodePool();
epicsShareFunc epicsShareAPI ~epicsListNodePool();
// allocate & free nodes
epicsListNode* allocate();
void free(epicsListNode* node);
void swap(epicsListNodePool& pool);
private: // Non-inline routines
epicsShareFunc void epicsShareAPI extend();
private: // Data
epicsListLink _free;
epicsListLink _blocks;
static epicsMutex _mutex;
static epicsListLink _store;
};
// END OF DECLARATIONS
// INLINE METHODS
// epicsListLink
inline epicsListLink::epicsListLink() :
_next(0) {}
inline bool epicsListLink::hasNext() const {
return (_next != 0);
}
inline void epicsListLink::set(epicsListLink* node) {
_next = node;
}
inline void epicsListLink::append(epicsListLink* node) {
node->_next = _next;
_next = node;
}
inline epicsListLink* epicsListLink::extract() {
epicsListLink* result = _next;
_next = result->_next;
result->_next = 0;
return result;
}
inline void epicsListLink::swap(epicsListLink& node) {
epicsSwap(node._next, _next);
}
// epicsListNode
// Disable spurious warnings from MSVC
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:4355)
#endif
inline epicsListNode::epicsListNode() :
_next(this + 1), _prev(0), payload(0) {}
inline epicsListNode::epicsListNode(int) :
_next(this), _prev(this), payload(0) {}
#ifdef _MSC_VER
#pragma warning(pop)
#endif
inline bool epicsListNode::hasNext() const {
return (_next != this);
}
inline epicsListNode* epicsListNode::next() const {
return _next;
}
inline epicsListNode* epicsListNode::prev() const {
return _prev;
}
inline void epicsListNode::insert(epicsListNode& node) {
node._next = this;
node._prev = _prev;
_prev->_next = &node;
_prev = &node;
}
inline void epicsListNode::append(epicsListNode& node) {
node._prev = this;
node._next = _next;
_next->_prev = &node;
_next = &node;
}
inline void epicsListNode::unlink() {
_prev->_next = _next;
_next->_prev = _prev;
_next = this;
_prev = this;
}
inline void epicsListNode::swap(epicsListNode& node) {
epicsSwap(node._next, _next);
_next->_prev = this;
node._next->_prev = &node;
epicsSwap(node._prev, _prev);
_prev->_next = this;
node._prev->_next = &node;
}
// epicsListNodeBlock
inline epicsListNodeBlock::epicsListNodeBlock() {
// The epicsListNode constructor links all the _next pointers in the block
_node[blocksize-1]._next = 0;
}
inline void epicsListNodeBlock::reset() {
for (int i=0; i<blocksize-1; i++)
_node[i]._next = &(_node[i+1]);
_node[blocksize-1]._next = 0;
}
inline epicsListLink* epicsListNodeBlock::first() {
return reinterpret_cast<epicsListLink*>(&(_node[0]));
}
// epicsListNodePool
inline epicsListNodePool::epicsListNodePool() :
_free(), _blocks() {}
inline epicsListNode* epicsListNodePool::allocate() {
if (!_free.hasNext())
extend(); // Complex non-inline code
return reinterpret_cast<epicsListNode*>(_free.extract());
}
inline void epicsListNodePool::free(epicsListNode* node) {
_free.append(reinterpret_cast<epicsListLink*>(node));
}
inline void epicsListNodePool::swap(epicsListNodePool& pool) {
_free.swap(pool._free);
_blocks.swap(pool._blocks);
}
#endif

View File

@@ -13,12 +13,6 @@ include $(TOP)/configure/CONFIG
PROD_LIBS += Com
#epicsListTest_SRCS += epicsListTest.cpp
PROD_HOST += epicsListTest
#epicsListTest build fails for vxWorks-ppc604 on win32-x86 host
#OBJS_IOC_vxWorks += epicsListTest
OBJS_IOC_RTEMS += epicsListTest
epicsAlgorithmTest_SRCS += epicsAlgorithmTest.cpp
PROD_HOST += epicsAlgorithmTest
OBJS_IOC_vxWorks += epicsAlgorithmTest

View File

@@ -1,192 +0,0 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
// $Id$
// Author: Andrew Johnson
// Date: December 2000
// Test code for the epics::List class
#include <iostream>
#include <stdio.h>
#include "epicsList.h"
using std::cout;
using std::endl;
#if defined(vxWorks) || defined(__rtems__)
#define MAIN epicsListTest
extern "C" int MAIN(int /*argc*/, char* /*argv[]*/);
#else
#define MAIN main
#endif
class fred {
public:
fred(const char* const _name) : name(_name) {}
void show () const {cout << name << ' ';}
private:
const char* const name;
};
static int tests = 0;
static int nak = 0;
static void check(bool res, const char* str, int line) {
tests++;
if (!res) {
printf("Test %d failed, line %d: %s\n", tests, line, str);
nak++;
}
}
#define test(expr) check(expr, #expr, __LINE__)
int MAIN(int /*argc*/, char* /*argv[]*/) {
fred* apf[10];
const char* const names[] = {
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"
};
int i;
for (i=0; i<10; i++)
apf[i] = new fred(names[i]);
epicsList<fred*> Fred;
test(Fred.empty());
test(Fred.size() == 0);
test(Fred.begin() == Fred.end());
Fred.push_back(apf[0]);
test(!Fred.empty());
test(Fred.size() == 1);
test(Fred.begin() != Fred.end());
test(Fred.front() == apf[0]);
test(Fred.back() == apf[0]);
epicsList<fred*>::iterator Fi = Fred.begin();
test(Fi != Fred.end());
test(*Fi == apf[0]);
epicsList<fred*>::const_iterator Fci = Fred.begin();
test(Fci != Fred.end());
test(Fci == Fi);
test(Fi == Fci);
test(*Fci == apf[0]);
++Fi;
test(Fi == Fred.end());
test(Fci != Fi);
test(Fi != Fci);
++Fci;
test(Fci == Fred.end());
Fci = --Fi;
test(Fi == Fred.begin());
test(Fci == Fred.begin());
Fred.push_front(apf[1]);
test(Fred.size() == 2);
test(Fred.front() == apf[1]);
test(Fred.back() == apf[0]);
test(*Fi == apf[0]);
Fi--;
test(*Fi == apf[1]);
Fci--;
test(*Fci == apf[1]);
Fi = Fred.insert(++Fi, apf[2]);
test(Fred.size() == 3);
test(Fred.front() == apf[1]);
test(Fred.back() == apf[0]);
test(Fi != Fci);
test(*Fi == apf[2]);
Fred.pop_back();
test(Fred.size() == 2);
Fred.push_front(apf[0]);
test(Fred.size() == 3);
Fi = Fred.begin();
Fred.erase(Fi);
test(Fred.size() == 2);
Fred.push_front(apf[0]);
test(Fred.size() == 3);
Fi = Fred.begin();
for (i=0; Fi != Fred.end(); i++, ++Fi)
test(*Fi == apf[i]);
Fci = Fred.begin();
for (i=0; Fci != Fred.end(); i++, ++Fci)
test(*Fci == apf[i]);
for (i=0; i<10; i++) {
test(Fred.size() == 3);
epicsList<fred*> Freda;
test(Freda.empty());
epicsListSwap(Fred, Freda);
test(Fred.empty());
test(Freda.size() == 3);
test(Freda.front() == apf[0]);
for (Fi = Freda.begin(); Fi != Freda.end(); Fi++)
Fred.push_back(*Fi);
test(Fred.size() == 3);
Fi = Freda.begin();
for (Fci = Fred.begin(); Fci != Fred.end(); ++Fci, ++Fi) {
test(Fi != Freda.end());
test(*Fci == *Fi);
}
// Freda's destructor returns her nodes to global store,
// from where they are allocated again during the next loop.
}
Fred.erase(Fred.begin(), --Fred.end());
test(Fred.size() == 1);
Fred.clear();
test(Fred.empty());
// Some more complicated stuff, just for the fun of it.
// Try doing this in tsDLList!
epicsList<epicsList<fred*>*> llf;
for (i=0; i<10; i++) {
llf.push_front(new epicsList<fred*>);
llf.front()->push_front(apf[i]);
}
test(llf.size() == 10);
epicsList<epicsList<fred*>*>::iterator llfi;
for (llfi = llf.begin(); llfi != llf.end(); ++llfi)
test(llfi->size() == 1);
for (llfi = llf.begin(); llfi != llf.end(); ++llfi) {
llfi->clear();
delete *llfi;
}
llf.clear();
for (i=0; i<10; i++)
delete apf[i];
cout << tests << " tests completed, " << nak << " failed." << endl;
return 0;
}