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:
@@ -7,8 +7,68 @@
|
|||||||
namespace Strategy {
|
namespace Strategy {
|
||||||
namespace SinglyLinkedList {
|
namespace SinglyLinkedList {
|
||||||
//! Automatic node strategy (works like STL containers do)
|
//! 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>
|
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)
|
//! User managed node strategy (user is responsible for node allocation/deallocation)
|
||||||
template <class Node, Node* Node::* NextMember = &Node::next>
|
template <class Node, Node* Node::* NextMember = &Node::next>
|
||||||
@@ -19,11 +79,11 @@ namespace Strategy {
|
|||||||
template <class Value, class Reference, class Pointer, class Parent>
|
template <class Value, class Reference, class Pointer, class Parent>
|
||||||
class SinglyLinkedListIterator;
|
class SinglyLinkedListIterator;
|
||||||
|
|
||||||
template <class NodeStrategy>
|
template <class Value, class NodeStrategy = Strategy::SinglyLinkedList::Auto<Value> >
|
||||||
class SinglyLinkedList
|
class SinglyLinkedList
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef SinglyLinkedList<NodeStrategy> Type;
|
typedef SinglyLinkedList<Value, NodeStrategy> Type;
|
||||||
|
|
||||||
typedef typename NodeStrategy::NodeType NodeType;
|
typedef typename NodeStrategy::NodeType NodeType;
|
||||||
typedef typename NodeStrategy::ValueType ValueType;
|
typedef typename NodeStrategy::ValueType ValueType;
|
||||||
@@ -88,10 +148,13 @@ public:
|
|||||||
typedef SinglyLinkedListIterator<Value, Reference, Pointer, Parent> IteratorType;
|
typedef SinglyLinkedListIterator<Value, Reference, Pointer, Parent> IteratorType;
|
||||||
typedef typename Parent::NodeType NodeType;
|
typedef typename Parent::NodeType NodeType;
|
||||||
|
|
||||||
|
SinglyLinkedListIterator();
|
||||||
SinglyLinkedListIterator(Parent *parent, NodeType *node, NodeType *previous);
|
SinglyLinkedListIterator(Parent *parent, NodeType *node, NodeType *previous);
|
||||||
|
SinglyLinkedListIterator(const IteratorType &ref);
|
||||||
|
|
||||||
bool operator==(const IteratorType &ref) const;
|
bool operator==(const IteratorType &ref) const;
|
||||||
bool operator!=(const IteratorType &ref) const;
|
bool operator!=(const IteratorType &ref) const;
|
||||||
|
IteratorType &operator=(const IteratorType &ref);
|
||||||
inline Reference operator*() const;
|
inline Reference operator*() const;
|
||||||
inline Pointer operator->() const;
|
inline Pointer operator->() const;
|
||||||
IteratorType &operator++();
|
IteratorType &operator++();
|
||||||
@@ -106,6 +169,14 @@ private:
|
|||||||
#define _ITERATOR_TEMPLATE_LIST template <class Value, class Reference, class Pointer, class Parent>
|
#define _ITERATOR_TEMPLATE_LIST template <class Value, class Reference, class Pointer, class Parent>
|
||||||
#define _ITERATOR SinglyLinkedListIterator<Value, Reference, Pointer, Parent>
|
#define _ITERATOR SinglyLinkedListIterator<Value, Reference, Pointer, Parent>
|
||||||
|
|
||||||
|
_ITERATOR_TEMPLATE_LIST
|
||||||
|
_ITERATOR::SinglyLinkedListIterator()
|
||||||
|
: fParent(NULL)
|
||||||
|
, fNode(NULL)
|
||||||
|
, fPrevious(NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
_ITERATOR_TEMPLATE_LIST
|
_ITERATOR_TEMPLATE_LIST
|
||||||
_ITERATOR::SinglyLinkedListIterator(Parent *parent, NodeType *node, NodeType *previous)
|
_ITERATOR::SinglyLinkedListIterator(Parent *parent, NodeType *node, NodeType *previous)
|
||||||
: fParent(parent)
|
: 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
|
_ITERATOR_TEMPLATE_LIST
|
||||||
bool
|
bool
|
||||||
_ITERATOR::operator==(const _ITERATOR &ref) const
|
_ITERATOR::operator==(const _ITERATOR &ref) const
|
||||||
@@ -128,6 +207,16 @@ _ITERATOR::operator!=(const _ITERATOR &ref) const
|
|||||||
return !operator==(ref);
|
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
|
_ITERATOR_TEMPLATE_LIST
|
||||||
inline
|
inline
|
||||||
Reference
|
Reference
|
||||||
@@ -165,8 +254,8 @@ _ITERATOR::operator++(int) {
|
|||||||
// SinglyLinkedList implementation
|
// SinglyLinkedList implementation
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
#define _SINGLY_LINKED_LIST_TEMPLATE_LIST template <class NodeStrategy>
|
#define _SINGLY_LINKED_LIST_TEMPLATE_LIST template <class Value, class NodeStrategy>
|
||||||
#define _SINGLY_LINKED_LIST SinglyLinkedList<NodeStrategy>
|
#define _SINGLY_LINKED_LIST SinglyLinkedList<Value, NodeStrategy>
|
||||||
|
|
||||||
_SINGLY_LINKED_LIST_TEMPLATE_LIST
|
_SINGLY_LINKED_LIST_TEMPLATE_LIST
|
||||||
_SINGLY_LINKED_LIST::~SinglyLinkedList()
|
_SINGLY_LINKED_LIST::~SinglyLinkedList()
|
||||||
@@ -389,68 +478,6 @@ _SINGLY_LINKED_LIST::Erase(Iterator &pos)
|
|||||||
namespace Strategy {
|
namespace Strategy {
|
||||||
namespace SinglyLinkedList {
|
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>
|
template <class Node, Node* Node::* NextMember>
|
||||||
class User
|
class User
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user