added some convenience functions to QSE::LinkedList, QSE::HashTable, and QSE::HashList

This commit is contained in:
hyung-hwan 2017-09-04 12:32:48 +00:00
parent 3cd745c181
commit 8b40ed630c
8 changed files with 85 additions and 98 deletions

View File

@ -36,6 +36,9 @@
#if (__cplusplus >= 201103L) // C++11
#define QSE_CPP_NOEXCEPT noexcept(true)
#define QSE_CPP_EXPLICIT explicit
/// The QSE_CPP_ENABLE_CPP11_MOVE macro enables C++11 move semantics
/// in various classes.
#define QSE_CPP_ENABLE_CPP11_MOVE 1
@ -49,13 +52,18 @@
#define QSE_CPP_TEMPLATE_QUALIFIER template
#elif (__cplusplus >= 199711L) // C++98
#define QSE_CPP_NOEXCEPT throw()
#define QSE_CPP_EXPLICIT
#define QSE_CPP_CALL_DESTRUCTOR(ptr, class_name) ((ptr)->~class_name())
#define QSE_CPP_CALL_PLACEMENT_DELETE1(ptr, arg1) (::operator delete((ptr), (arg1)))
#define QSE_CPP_TEMPLATE_QUALIFIER template
#else
#define QSE_CPP_NOEXCEPT
#define QSE_CPP_EXPLICIT
#if defined(__BORLANDC__)

View File

@ -300,26 +300,15 @@ public:
return this->datum_list->isEmpty ();
}
Node* getHeadNode ()
{
return this->datum_list->getHeadNode ();
}
const Node* getHeadNode () const
{
return this->datum_list->getHeadNode ();
}
Node* getTailNode ()
{
return this->datum_list->getTailNode ();
}
const Node* getTailNode () const
{
return this->datum_list->getTailNode ();
}
Node* getHeadNode () { return this->datum_list->getHeadNode (); }
const Node* getHeadNode () const { return this->datum_list->getHeadNode (); }
Node* getFirstNode () { return this->datum_list->getHeadNode (); }
const Node* getFirstNode () const { return this->datum_list->getHeadNode (); }
Node* getTailNode () { return this->datum_list->getTailNode (); }
const Node* getTailNode () const { return this->datum_list->getTailNode (); }
Node* getLastNode () { return this->datum_list->getTailNode (); }
const Node* getLastNode () const { return this->datum_list->getTailNode (); }
protected:
Node* find_node (const T& datum) const
{

View File

@ -174,25 +174,15 @@ public:
return this->pair_list.isEmpty ();
}
PairNode* getHeadNode ()
{
return this->pair_list.getHeadNode ();
}
PairNode* getHeadNode () { return this->pair_list.getHeadNode (); }
const PairNode* getHeadNode () const { return this->pair_list.getHeadNode (); }
PairNode* getFirstNode () { return this->pair_list.getHeadNode (); }
const PairNode* getFirstNode () const { return this->pair_list.getHeadNode (); }
const PairNode* getHeadNode () const
{
return this->pair_list.getHeadNode ();
}
PairNode* getTailNode ()
{
return this->pair_list.getTailNode ();
}
const PairNode* getTailNode () const
{
return this->pair_list.getTailNode ();
}
PairNode* getTailNode () { return this->pair_list.getTailNode (); }
const PairNode* getTailNode () const { return this->pair_list.getTailNode (); }
PairNode* getLastNode () { return this->pair_list.getTailNode (); }
const PairNode* getLastNode () const { return this->pair_list.getTailNode (); }
Pair* inject (const K& key, const V& value, int mode, bool* injected = QSE_NULL)
{

View File

@ -325,17 +325,13 @@ public:
/// The prependNode() function adds an externally created \a node
/// to the front of the list.
Node* prependNode (Node* node)
{
return this->insertNode (this->head_node, node);
}
Node* prependNode (Node* node) { return this->insertNode (this->head_node, node); }
Node* insertFirstNode (Node* node) { return this->insertNode (this->head_node, node); }
/// The appendNode() function adds an externally created \a node
/// to the back of the list.
Node* appendNode (Node* node)
{
return this->insertNode (QSE_NULL, node);
}
Node* appendNode (Node* node) { return this->insertNode (QSE_NULL, node); }
Node* insertLastNode (Node* node) { return this->insertNode (QSE_NULL, node); }
// create a new node to hold the value and insert it.
Node* insert (Node* pos, const T& value)
@ -344,15 +340,11 @@ public:
return this->insertNode (pos, node);
}
Node* prepend (const T& value)
{
return this->insert (this->head_node, value);
}
Node* prepend (const T& value) { return this->insert (this->head_node, value); }
Node* insertFirst (const T& value) { return this->insert (this->head_node, value); }
Node* append (const T& value)
{
return this->insert ((Node*)QSE_NULL, value);
}
Node* append (const T& value) { return this->insert ((Node*)QSE_NULL, value); }
Node* insertLast (const T& value) { return this->insert ((Node*)QSE_NULL, value); }
void prependAll (const SelfType& list)
{
@ -475,15 +467,11 @@ public:
return cnt;
}
void removeHead ()
{
this->remove (this->head_node);
}
void removeHead () { this->remove (this->head_node); }
void removeFirst () { this->remove (this->head_node); }
void removeTail ()
{
this->remove (this->tail_node);
}
void removeTail () { this->remove (this->tail_node); }
void removeLast () { this->remove (this->tail_node); }
/// The getHeadNode() function returns the first node.
/// \code
@ -494,15 +482,11 @@ public:
/// printf ("%d\n", np->value);
/// }
/// \endcode
Node* getHeadNode ()
{
return this->head_node;
}
Node* getHeadNode () { return this->head_node; }
const Node* getHeadNode () const { return this->head_node; }
const Node* getHeadNode () const
{
return this->head_node;
}
Node* getFirstNode () { return this->head_node; }
const Node* getFirstNode () const { return this->head_node; }
/// The getTailNode() function returns the last node.
/// \code
@ -513,15 +497,11 @@ public:
/// printf ("%d\n", np->value);
/// }
/// \endcode
Node* getTailNode ()
{
return this->tail_node;
}
Node* getTailNode () { return this->tail_node; }
const Node* getTailNode () const { return this->tail_node; }
const Node* getTailNode () const
{
return this->tail_node;
}
Node* getLastNode () { return this->tail_node; }
const Node* getLastNode () const { return this->tail_node; }
protected:
Node* get_node_at (qse_size_t index) const

View File

@ -37,14 +37,14 @@ QSE_BEGIN_NAMESPACE(QSE)
class Socket
{
public:
Socket ();
~Socket ();
Socket () QSE_CPP_NOEXCEPT;
~Socket () QSE_CPP_NOEXCEPT;
int open (int domain, int type, int protocol);
void close ();
int open (int domain, int type, int protocol) QSE_CPP_NOEXCEPT;
void close () QSE_CPP_NOEXCEPT;
int connect (const SocketAddress& target);
int beginConnect (const SocketAddress& target);
int connect (const SocketAddress& target) QSE_CPP_NOEXCEPT;
int beginConnect (const SocketAddress& target) QSE_CPP_NOEXCEPT;
protected:
qse_sck_hnd_t handle;

View File

@ -27,6 +27,7 @@
#ifndef _QSE_SI_SOCKETADDRESS_HPP_
#define _QSE_SI_SOCKETADDRESS_HPP_
#include <qse/Types.hpp>
#include <qse/si/nwad.h>
/////////////////////////////////

View File

@ -27,6 +27,7 @@
#include <qse/cmn/hwad.h>
#include <qse/cmn/chr.h>
#include <qse/cmn/fmt.h>
#include <qse/cmn/str.h>
int qse_mbstoethwad (const qse_mchar_t* mbs, qse_ethwad_t* hwaddr)
{

View File

@ -25,22 +25,43 @@
*/
#include <qse/si/Socket.hpp>
#include <sys/socket.h>
/////////////////////////////////
QSE_BEGIN_NAMESPACE(QSE)
/////////////////////////////////
Socket::Socket (): handle(QSE_INVALID_SCKHND)
Socket::Socket () QSE_CPP_NOEXCEPT: handle(QSE_INVALID_SCKHND)
{
}
Socket::~Socket ()
Socket::~Socket () QSE_CPP_NOEXCEPT
{
this->close ();
}
#if 0
int Socket::fdopen (int handle) QSE_CPP_NOEXCEPT
{
this->handle = handle;
}
#endif
void Socket::close ()
int Socket::open (int domain, int type, int protocol) QSE_CPP_NOEXCEPT
{
int x;
x = ::socket (domain, type, protocol);
if (x != -1)
{
this->close ();
this->handle = x;
}
return x;
}
void Socket::close () QSE_CPP_NOEXCEPT
{
if (this->handle != QSE_INVALID_SCKHND)
{
@ -49,20 +70,17 @@ void Socket::close ()
}
}
//int Socket::open (int domain, int type, int protocol)
//{
//}
int Socket::connect (const SocketAddress& target)
int Socket::connect (const SocketAddress& target) QSE_CPP_NOEXCEPT
{
if (this->handle == QSE_INVALID_SCKHND)
{
//::socket (target.getFamily(), this->type, 0);
}
//if (this->handle == QSE_INVALID_SCKHND)
//{
//
//}
return -1;
}
int Socket::beginConnect (const SocketAddress &target)
int Socket::beginConnect (const SocketAddress &target) QSE_CPP_NOEXCEPT
{
}