Loading...
Searching...
No Matches
list.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#ifndef BALL_DATATYPE_LIST_H
#define BALL_DATATYPE_LIST_H
#ifndef BALL_COMMON_H
# include <BALL/common.h>
#endif
#ifndef BALL_CONCEPT_VISITOR_H
# include <BALL/CONCEPT/visitor.h>
#endif
#ifndef BALL_CONCEPT_PROCESSOR_H
# include <BALL/CONCEPT/processor.h>
#endif
#include <list>
#ifdef BALL_COMPILER_GXX || BALL_COMPILER_LLVM
#warning "This header file is deprecated and should not be used in new code! As a replacement for BALL::List the use of std::list is strongly suggested."
#endif
namespace BALL
{
template <typename Value>
class List
: public std::list<Value>
{
public:
typedef typename std::list<Value>::iterator Iterator;
// for STL compatibility
typedef typename std::list<Value>::iterator iterator;
typedef typename std::list<Value>::const_iterator ConstIterator;
// for STL compatibility
typedef typename std::list<Value>::const_iterator const_iterator;
BALL_CREATE_DEEP(List)
List()
: std::list<Value>()
{
}
List(const List& new_list, bool /* deep = true */)
: std::list<Value>(new_list)
{
}
void destroy()
{
std::list<Value>::clear();
}
virtual ~List()
{
std::list<Value>::clear();
}
void set(const List& list, bool /* deep */ = true)
{
std::list<Value>::clear();
ConstIterator it = list.begin();
for ( ; it != list.end(); ++it)
{
std::list<Value>::push_back(const_cast<Value&>(*it));
}
}
const List& operator = (const List& list)
{
set(list);
return *this;
}
void get(List& list, bool deep = true) const
{
list.set(*this, deep);
}
void swap(List& list)
{
List<Value> temp;
temp.set(*this);
(*this).set(list);
list.set(temp);
}
Size getSize() const
{
return (Size)std::list<Value>::size();
}
bool remove(const Value& item)
{
Iterator it = std::list<Value>::begin();
for (; it != std::list<Value>::end(); ++it)
{
if (*it == item)
{
std::list<Value>::erase(it);
return true;
}
}
return false;
}
bool isEmpty() const
{
return (std::list<Value>::size() == 0);
}
virtual void host(Visitor<List<Value> >& visitor);
bool apply(UnaryProcessor<Value>& processor)
{
if (!processor.start()) return false;
for (Iterator it = std::list<Value>::begin(); it != std::list<Value>::end(); ++it)
{
Processor::Result result = processor(*it);
if (result <= Processor::BREAK)
{
return (result == Processor::BREAK);
}
}
return processor.finish();
}
bool operator == (const List<Value>& list) const
{
if (std::list<Value>::size() != list.size())
{
return false;
}
typename List<Value>::ConstIterator this_it = std::list<Value>::begin();
typename List<Value>::ConstIterator list_it = list.begin();
for (; this_it != std::list<Value>::end(); ++this_it)
{
if (!(*this_it == *list_it))
{
return false;
}
++list_it;
}
return true;
}
bool operator != (const List<Value>& list) const
{
return !(*this == list);
}
};
template <typename Value>
void List<Value>::host(Visitor<List<Value> >& visitor)
{
visitor.visit(*this);
}
} // namespace BALL
#endif // BALL_DATATYPE_LIST_H
BALL::List
Definition list.h:36
BALL::List::operator=
const List & operator=(const List &list)
Definition list.h:114
BALL::List::List
List()
Definition list.h:64
BALL::List::operator!=
bool operator!=(const List< Value > &list) const
Definition list.h:239
BALL::List::apply
bool apply(UnaryProcessor< Value > &processor)
Definition list.h:194
BALL::List::destroy
void destroy()
Definition list.h:81
BALL::List::operator==
bool operator==(const List< Value > &list) const
Definition list.h:215
BALL::List::Iterator
std::list< Value >::iterator Iterator
Definition list.h:45
BALL::List::swap
void swap(List &list)
Swaps the contents of two lists.
Definition list.h:127
BALL::List::set
void set(const List &list, bool=true)
Definition list.h:101
BALL::List::ConstIterator
std::list< Value >::const_iterator ConstIterator
Definition list.h:51
BALL::List::const_iterator
std::list< Value >::const_iterator const_iterator
Definition list.h:53
BALL::List::get
void get(List &list, bool deep=true) const
Assign the content of a list to another.
Definition list.h:121
BALL::List::host
virtual void host(Visitor< List< Value > > &visitor)
Definition list.h:247
BALL::List::remove
bool remove(const Value &item)
Definition list.h:150
BALL::List::getSize
Size getSize() const
Definition list.h:141
BALL::List::isEmpty
bool isEmpty() const
Definition list.h:171
BALL::List::~List
virtual ~List()
Definition list.h:88
BALL::List::List
List(const List &new_list, bool)
Definition list.h:74
BALL::List::iterator
std::list< Value >::iterator iterator
Definition list.h:47
BALL::Processor::BREAK
@ BREAK
Definition processor.h:47
BALL::Processor::Result
int Result
Definition processor.h:36
BALL::UnaryProcessor
Definition processor.h:60
BALL::UnaryProcessor::start
virtual bool start()
Definition processor.h:92
BALL::UnaryProcessor::finish
virtual bool finish()
Definition processor.h:99
BALL::Visitor
Definition visitor.h:23
common.h
BALL_CREATE_DEEP
#define BALL_CREATE_DEEP(name)
Definition create.h:26
BALL
Definition constants.h:13
BALL::Size
BALL_SIZE_TYPE Size
Definition COMMON/global.h:114
std
STL namespace.
processor.h
visitor.h