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 #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 /// The QSE_CPP_ENABLE_CPP11_MOVE macro enables C++11 move semantics
/// in various classes. /// in various classes.
#define QSE_CPP_ENABLE_CPP11_MOVE 1 #define QSE_CPP_ENABLE_CPP11_MOVE 1
@ -49,13 +52,18 @@
#define QSE_CPP_TEMPLATE_QUALIFIER template #define QSE_CPP_TEMPLATE_QUALIFIER template
#elif (__cplusplus >= 199711L) // C++98 #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_DESTRUCTOR(ptr, class_name) ((ptr)->~class_name())
#define QSE_CPP_CALL_PLACEMENT_DELETE1(ptr, arg1) (::operator delete((ptr), (arg1))) #define QSE_CPP_CALL_PLACEMENT_DELETE1(ptr, arg1) (::operator delete((ptr), (arg1)))
#define QSE_CPP_TEMPLATE_QUALIFIER template #define QSE_CPP_TEMPLATE_QUALIFIER template
#else #else
#define QSE_CPP_NOEXCEPT
#define QSE_CPP_EXPLICIT
#if defined(__BORLANDC__) #if defined(__BORLANDC__)

View File

@ -300,26 +300,15 @@ public:
return this->datum_list->isEmpty (); return this->datum_list->isEmpty ();
} }
Node* getHeadNode () Node* getHeadNode () { return this->datum_list->getHeadNode (); }
{ const Node* getHeadNode () const { return this->datum_list->getHeadNode (); }
return this->datum_list->getHeadNode (); Node* getFirstNode () { return this->datum_list->getHeadNode (); }
} const Node* getFirstNode () const { 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* 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: protected:
Node* find_node (const T& datum) const Node* find_node (const T& datum) const
{ {

View File

@ -174,25 +174,15 @@ public:
return this->pair_list.isEmpty (); return this->pair_list.isEmpty ();
} }
PairNode* getHeadNode () PairNode* getHeadNode () { return this->pair_list.getHeadNode (); }
{ const PairNode* getHeadNode () const { return this->pair_list.getHeadNode (); }
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 PairNode* getTailNode () { return this->pair_list.getTailNode (); }
{ const PairNode* getTailNode () const { return this->pair_list.getTailNode (); }
return this->pair_list.getHeadNode (); PairNode* getLastNode () { return this->pair_list.getTailNode (); }
} const PairNode* getLastNode () const { return this->pair_list.getTailNode (); }
PairNode* getTailNode ()
{
return this->pair_list.getTailNode ();
}
const PairNode* getTailNode () const
{
return this->pair_list.getTailNode ();
}
Pair* inject (const K& key, const V& value, int mode, bool* injected = QSE_NULL) 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 /// The prependNode() function adds an externally created \a node
/// to the front of the list. /// to the front of the list.
Node* prependNode (Node* node) Node* prependNode (Node* node) { return this->insertNode (this->head_node, node); }
{ Node* insertFirstNode (Node* node) { return this->insertNode (this->head_node, node); }
return this->insertNode (this->head_node, node);
}
/// The appendNode() function adds an externally created \a node /// The appendNode() function adds an externally created \a node
/// to the back of the list. /// to the back of the list.
Node* appendNode (Node* node) Node* appendNode (Node* node) { return this->insertNode (QSE_NULL, node); }
{ Node* insertLastNode (Node* node) { return this->insertNode (QSE_NULL, node); }
return this->insertNode (QSE_NULL, node);
}
// create a new node to hold the value and insert it. // create a new node to hold the value and insert it.
Node* insert (Node* pos, const T& value) Node* insert (Node* pos, const T& value)
@ -344,15 +340,11 @@ public:
return this->insertNode (pos, node); return this->insertNode (pos, node);
} }
Node* prepend (const T& 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); }
return this->insert (this->head_node, value);
}
Node* append (const T& 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); }
return this->insert ((Node*)QSE_NULL, value);
}
void prependAll (const SelfType& list) void prependAll (const SelfType& list)
{ {
@ -475,15 +467,11 @@ public:
return cnt; return cnt;
} }
void removeHead () void removeHead () { this->remove (this->head_node); }
{ void removeFirst () { this->remove (this->head_node); }
this->remove (this->head_node);
}
void removeTail () void removeTail () { this->remove (this->tail_node); }
{ void removeLast () { this->remove (this->tail_node); }
this->remove (this->tail_node);
}
/// The getHeadNode() function returns the first node. /// The getHeadNode() function returns the first node.
/// \code /// \code
@ -494,15 +482,11 @@ public:
/// printf ("%d\n", np->value); /// printf ("%d\n", np->value);
/// } /// }
/// \endcode /// \endcode
Node* getHeadNode () Node* getHeadNode () { return this->head_node; }
{ const Node* getHeadNode () const { return this->head_node; }
return this->head_node;
}
const Node* getHeadNode () const Node* getFirstNode () { return this->head_node; }
{ const Node* getFirstNode () const { return this->head_node; }
return this->head_node;
}
/// The getTailNode() function returns the last node. /// The getTailNode() function returns the last node.
/// \code /// \code
@ -513,15 +497,11 @@ public:
/// printf ("%d\n", np->value); /// printf ("%d\n", np->value);
/// } /// }
/// \endcode /// \endcode
Node* getTailNode () Node* getTailNode () { return this->tail_node; }
{ const Node* getTailNode () const { return this->tail_node; }
return this->tail_node;
}
const Node* getTailNode () const Node* getLastNode () { return this->tail_node; }
{ const Node* getLastNode () const { return this->tail_node; }
return this->tail_node;
}
protected: protected:
Node* get_node_at (qse_size_t index) const Node* get_node_at (qse_size_t index) const

View File

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

View File

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

View File

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

View File

@ -25,22 +25,43 @@
*/ */
#include <qse/si/Socket.hpp> #include <qse/si/Socket.hpp>
#include <sys/socket.h>
///////////////////////////////// /////////////////////////////////
QSE_BEGIN_NAMESPACE(QSE) 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 (); 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) 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) QSE_CPP_NOEXCEPT
{
//if (this->handle == QSE_INVALID_SCKHND)
//{ //{
//
//} //}
return -1;
int Socket::connect (const SocketAddress& target)
{
if (this->handle == QSE_INVALID_SCKHND)
{
//::socket (target.getFamily(), this->type, 0);
}
} }
int Socket::beginConnect (const SocketAddress &target) int Socket::beginConnect (const SocketAddress &target) QSE_CPP_NOEXCEPT
{ {
} }