Switched from <Strategy> to <Value, Strategy = Auto> template paramter format.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4603 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder 2003-09-09 06:25:31 +00:00
parent a64f0e9fc2
commit c72c47f361

View File

@ -7,8 +7,68 @@
namespace Strategy {
namespace SinglyLinkedList {
//! Automatic node strategy (works like STL containers do)
namespace Private {
template <class Value>
class ListNode
{
public:
typedef Value ValueType;
ListNode(const ValueType &data)
: data(data)
, next(NULL)
{
}
ValueType data;
ListNode<Value> *next;
};
} // namespace Private
template <typename Value, template <class> class Allocator = MallocFreeAllocator>
class Auto;
class Auto
{
public:
typedef Private::ListNode<Value> NodeType;
typedef Value ValueType;
inline NodeType *Allocate(const ValueType &data)
{
NodeType* result = fAllocator.Allocate();
fAllocator.Construct(result, data);
return result;
}
inline void Free(NodeType *node)
{
fAllocator.Destruct(node);
fAllocator.Deallocate(node);
}
inline ValueType& GetValue(NodeType *node) const {
return node->data;
}
inline NodeType* GetNext(NodeType *node) const {
return node->next;
}
inline NodeType* SetNext(NodeType *node, NodeType* next) const {
return node->next = next;
}
inline NodeType* GetPrevious(NodeType *node) const {
return node->previous;
}
inline NodeType* SetPrevious(NodeType *node, NodeType* previous) const {
return node->previous = previous;
}
protected:
Allocator<NodeType> fAllocator;
};
//! User managed node strategy (user is responsible for node allocation/deallocation)
template <class Node, Node* Node::* NextMember = &Node::next>
@ -19,11 +79,11 @@ namespace Strategy {
template <class Value, class Reference, class Pointer, class Parent>
class SinglyLinkedListIterator;
template <class NodeStrategy>
template <class Value, class NodeStrategy = Strategy::SinglyLinkedList::Auto<Value> >
class SinglyLinkedList
{
public:
typedef SinglyLinkedList<NodeStrategy> Type;
typedef SinglyLinkedList<Value, NodeStrategy> Type;
typedef typename NodeStrategy::NodeType NodeType;
typedef typename NodeStrategy::ValueType ValueType;
@ -88,10 +148,13 @@ public:
typedef SinglyLinkedListIterator<Value, Reference, Pointer, Parent> IteratorType;
typedef typename Parent::NodeType NodeType;
SinglyLinkedListIterator();
SinglyLinkedListIterator(Parent *parent, NodeType *node, NodeType *previous);
SinglyLinkedListIterator(const IteratorType &ref);
bool operator==(const IteratorType &ref) const;
bool operator!=(const IteratorType &ref) const;
IteratorType &operator=(const IteratorType &ref);
inline Reference operator*() const;
inline Pointer operator->() const;
IteratorType &operator++();
@ -106,6 +169,14 @@ private:
#define _ITERATOR_TEMPLATE_LIST template <class Value, class Reference, class Pointer, class Parent>
#define _ITERATOR SinglyLinkedListIterator<Value, Reference, Pointer, Parent>
_ITERATOR_TEMPLATE_LIST
_ITERATOR::SinglyLinkedListIterator()
: fParent(NULL)
, fNode(NULL)
, fPrevious(NULL)
{
}
_ITERATOR_TEMPLATE_LIST
_ITERATOR::SinglyLinkedListIterator(Parent *parent, NodeType *node, NodeType *previous)
: fParent(parent)
@ -114,6 +185,14 @@ _ITERATOR::SinglyLinkedListIterator(Parent *parent, NodeType *node, NodeType *pr
{
}
_ITERATOR_TEMPLATE_LIST
_ITERATOR::SinglyLinkedListIterator(const IteratorType &ref)
: fParent(ref.fParent)
, fNode(ref.fNode)
, fPrevious(ref.fPrevious)
{
}
_ITERATOR_TEMPLATE_LIST
bool
_ITERATOR::operator==(const _ITERATOR &ref) const
@ -128,6 +207,16 @@ _ITERATOR::operator!=(const _ITERATOR &ref) const
return !operator==(ref);
}
_ITERATOR_TEMPLATE_LIST
_ITERATOR&
_ITERATOR::operator=(const _ITERATOR &ref)
{
fParent = ref.fParent;
fNode = ref.fNode;
fPrevious = ref.fPrevious;
return *this;
}
_ITERATOR_TEMPLATE_LIST
inline
Reference
@ -165,8 +254,8 @@ _ITERATOR::operator++(int) {
// SinglyLinkedList implementation
//--------------------------------------------------------------------------
#define _SINGLY_LINKED_LIST_TEMPLATE_LIST template <class NodeStrategy>
#define _SINGLY_LINKED_LIST SinglyLinkedList<NodeStrategy>
#define _SINGLY_LINKED_LIST_TEMPLATE_LIST template <class Value, class NodeStrategy>
#define _SINGLY_LINKED_LIST SinglyLinkedList<Value, NodeStrategy>
_SINGLY_LINKED_LIST_TEMPLATE_LIST
_SINGLY_LINKED_LIST::~SinglyLinkedList()
@ -389,68 +478,6 @@ _SINGLY_LINKED_LIST::Erase(Iterator &pos)
namespace Strategy {
namespace SinglyLinkedList {
namespace Private {
template <class Value>
class ListNode
{
public:
typedef Value ValueType;
ListNode(const ValueType &data)
: data(data)
, next(NULL)
{
}
ValueType data;
ListNode<Value> *next;
};
} // namespace Private
template <typename Value, template <class> class Allocator>
class Auto
{
public:
typedef Private::ListNode<Value> NodeType;
typedef Value ValueType;
inline NodeType *Allocate(const ValueType &data)
{
NodeType* result = fAllocator.Allocate();
fAllocator.Construct(result, data);
return result;
}
inline void Free(NodeType *node)
{
fAllocator.Destruct(node);
fAllocator.Deallocate(node);
}
inline ValueType& GetValue(NodeType *node) const {
return node->data;
}
inline NodeType* GetNext(NodeType *node) const {
return node->next;
}
inline NodeType* SetNext(NodeType *node, NodeType* next) const {
return node->next = next;
}
inline NodeType* GetPrevious(NodeType *node) const {
return node->previous;
}
inline NodeType* SetPrevious(NodeType *node, NodeType* previous) const {
return node->previous = previous;
}
protected:
Allocator<NodeType> fAllocator;
};
template <class Node, Node* Node::* NextMember>
class User
{