touched up code a little bit

This commit is contained in:
hyung-hwan 2015-01-19 03:52:06 +00:00
parent dc118785c7
commit fc9ad20e7a
2 changed files with 25 additions and 24 deletions

View File

@ -24,8 +24,8 @@
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _QSE_CMN_HASHLIST_CLASS_ #ifndef _QSE_CMN_HASHLIST_HPP_
#define _QSE_CMN_HASHLIST_CLASS_ #define _QSE_CMN_HASHLIST_HPP_
#include <qse/Hashable.hpp> #include <qse/Hashable.hpp>
#include <qse/cmn/LinkedList.hpp> #include <qse/cmn/LinkedList.hpp>
@ -152,7 +152,7 @@ public:
do do
{ {
copy_datum (np, this->node_capacity, this->nodes, this->datum_list); this->copy_datum (np, this->node_capacity, this->nodes, this->datum_list);
if (np == list.nodes[tail]) break; if (np == list.nodes[tail]) break;
np = np->getNextNode (); np = np->getNextNode ();
} }
@ -364,12 +364,12 @@ public:
Node* getHeadNode () const Node* getHeadNode () const
{ {
return datum_list->getHeadNode(); return this->datum_list->getHeadNode();
} }
Node* getTaileNode () const Node* getTaileNode () const
{ {
return datum_list->getTailNode(); return this->datum_list->getTailNode();
} }
typedef int (SelfType::*TraverseCallback) (Node* start, Node* cur); typedef int (SelfType::*TraverseCallback) (Node* start, Node* cur);

View File

@ -43,50 +43,51 @@ class LinkedListNode: protected Mpoolable
{ {
public: public:
friend class LinkedList<T,MPOOL>; friend class LinkedList<T,MPOOL>;
typedef LinkedListNode<T,MPOOL> Node; typedef LinkedListNode<T,MPOOL> SelfType;
T value; // you can use this variable or accessor functions below T value; // you can use this variable or accessor functions below
protected: protected:
Node* next; SelfType* next;
Node* prev; SelfType* prev;
public: public:
T& getValue () { return this->value; } T& getValue () { return this->value; }
const T& getValue () const { return this->value; } const T& getValue () const { return this->value; }
void setValue (const T& v) { this->value = v; } void setValue (const T& v) { this->value = v; }
Node* getNext () { return this->next; } SelfType* getNext () { return this->next; }
const Node* getNext () const { return this->next; } const SelfType* getNext () const { return this->next; }
Node* getNextNode () { return this->next; } SelfType* getNextNode () { return this->next; }
const Node* getNextNode () const { return this->next; } const SelfType* getNextNode () const { return this->next; }
Node* getPrev () { return this->prev; } SelfType* getPrev () { return this->prev; }
const Node* getPrev () const { return this->prev; } const SelfType* getPrev () const { return this->prev; }
Node* getPrevNode () { return this->prev; } SelfType* getPrevNode () { return this->prev; }
const Node* getPrevNode () const { return this->prev; } const SelfType* getPrevNode () const { return this->prev; }
protected: protected:
LinkedListNode (): prev(QSE_NULL), next(QSE_NULL) {} LinkedListNode (): prev(QSE_NULL), next(QSE_NULL) {}
LinkedListNode (const T& v): value(v), prev(QSE_NULL), next(QSE_NULL) {} LinkedListNode (const T& v): value(v), prev(QSE_NULL), next(QSE_NULL) {}
void setNext (const Node* node) void setNext (const SelfType* node)
{ {
this->next = node; this->next = node;
} }
void setPrev (const Node* node) void setPrev (const SelfType* node)
{ {
this->prev = node; this->prev = node;
} }
}; };
/// ///
/// The LinkedList<T> class provides a template for a doubly-linked list. /// The LinkedList<T,MPOOL> class provides a template for a doubly-linked list.
/// ///
template <typename T, typename MPOOL = Mpool> class LinkedList template <typename T, typename MPOOL = Mpool> class LinkedList
{ {
public: public:
typedef LinkedList<T,MPOOL> SelfType;
typedef LinkedListNode<T,MPOOL> Node; typedef LinkedListNode<T,MPOOL> Node;
enum enum
@ -106,7 +107,7 @@ public:
this->tail_node = QSE_NULL; this->tail_node = QSE_NULL;
} }
LinkedList (const LinkedList<T>& ll): mp (ll.mp.getDatumSize(), ll.mp.getBlockSize()) LinkedList (const SelfType& ll): mp (ll.mp.getDatumSize(), ll.mp.getBlockSize())
{ {
this->node_count = 0; this->node_count = 0;
this->head_node = QSE_NULL; this->head_node = QSE_NULL;
@ -115,7 +116,7 @@ public:
this->append (p->value); this->append (p->value);
} }
LinkedList<T>& operator= (const LinkedList<T>& ll) SelfType& operator= (const SelfType& ll)
{ {
this->clear (); this->clear ();
for (Node* p = ll.head_node; p != QSE_NULL; p = p->next) for (Node* p = ll.head_node; p != QSE_NULL; p = p->next)
@ -222,7 +223,7 @@ public:
return this->insertValue ((Node*)QSE_NULL, value); return this->insertValue ((Node*)QSE_NULL, value);
} }
void prependAll (const LinkedList<T>& list) void prependAll (const SelfType& list)
{ {
Node* n = list.tail_node; Node* n = list.tail_node;
@ -246,7 +247,7 @@ public:
} }
} }
void appendAll (const LinkedList<T>& list) void appendAll (const SelfType& list)
{ {
Node* n = list.head_node; Node* n = list.head_node;
@ -523,7 +524,7 @@ public:
this->mp.dispose (); this->mp.dispose ();
} }
typedef int (LinkedList<T>::*TraverseCallback) (Node* start, Node* cur); typedef int (SelfType::*TraverseCallback) (Node* start, Node* cur);
void traverse (TraverseCallback callback, Node* start) void traverse (TraverseCallback callback, Node* start)
{ {