Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
List.cpp
Package: LegendOfMir2_Server020418.zip [view]
Upload User: szopptop
Upload Date: 2013-04-23
Package Size: 1047k
Code Size: 4k
Category:
Game Server Simulator
Development Platform:
Visual C++
- // **************************************************************************************
- //
- // Euyheon's Linked List Class
- //
- // All written by Euy-heon, Jeong.
- // Copyright(C) 1999-2001 Euy-heon, Jeong. All rights reserved.
- //
- // Win32 Version : Compiled by Microsoft Visual C++ 6.0
- //
- // Problems & History
- // ------------------
- //
- // **************************************************************************************
- #include "stdafx.h"
- template<class T> CWHList<T>::CWHList()
- {
- m_lpHead = NULL;
- m_lpTail = NULL;
- m_nCount = 0;
- InitializeCriticalSection(&m_cs);
- }
- template<class T> CWHList<T>::~CWHList()
- {
- Clear();
- DeleteCriticalSection(&m_cs);
- }
- template<class T> BOOL CWHList<T>::AddNewNode(T lpData)
- {
- BOOL fRet = FALSE;
- EnterCriticalSection(&m_cs);
- __try
- {
- LPLINKEDLIST lpCD = (LPLINKEDLIST)GlobalAlloc(GPTR, sizeof(LINKEDLIST));
- lpCD->lpData = lpData;
- if (!m_lpHead)
- {
- m_lpHead = lpCD;
- lpCD->prev = (LPLINKEDLIST)NULL;
- }
- else
- {
- m_lpTail->next = lpCD;
- lpCD->prev = m_lpTail;
- }
- lpCD->next = (LPLINKEDLIST)NULL;
- m_lpTail = lpCD;
- m_nCount++;
- fRet = TRUE;
- }
- __finally
- {
- LeaveCriticalSection(&m_cs);
- }
- return fRet;
- }
- template<class T> void CWHList<T>::Clear()
- {
- EnterCriticalSection(&m_cs);
- LPLINKEDLIST lpNode = m_lpHead;
- __try
- {
- while (lpNode)
- lpNode = RemoveNode(lpNode);
- }
- __finally
- {
- LeaveCriticalSection(&m_cs);
- }
- }
- /*template<class T> LPLINKEDLIST CWHList<T>::RemoveNode(LPLINKEDLIST lpList)
- {
- LPLINKEDLIST prev = NULL, next;
- EnterCriticalSection(&m_cs);
- __try
- {
- next = lpList->next;
- prev = lpList->prev;
- if (prev) prev->next = next;
- else m_lpHead = next;
- if (next) next->prev = prev;
- else m_lpTail = prev;
- GlobalFree(lpList);
- m_nCount--;
- }
- __finally
- {
- LeaveCriticalSection(&m_cs);
- }
- return prev;
- }
- */
- template <class T>BOOL CWHList<T>::RemoveNodeByKey(SOCKET s)
- {
- EnterCriticalSection(&m_cs);
- LPLINKEDLIST prev = NULL, next;
- LPLINKEDLIST lpNode = m_lpHead;
- BOOL fFlag = FALSE;
- __try
- {
- while (lpNode)
- {
- if (((CSessionInfo*)lpNode->lpData)->sock == s)
- {
- next = lpNode->next;
- prev = lpNode->prev;
- if (prev) prev->next = next;
- else m_lpHead = next;
- if (next) next->prev = prev;
- else m_lpTail = prev;
- GlobalFree(lpNode);
- m_nCount--;
- fFlag = TRUE;
- break;
- }
- lpNode = lpNode->next;
- }
- }
- __finally
- {
- LeaveCriticalSection(&m_cs);
- }
- return fFlag;
- }
- template <class T>BOOL CWHList<T>::RemoveNodeByData(T lpData)
- {
- // EnterCriticalSection(&m_cs);
- LPLINKEDLIST prev = NULL, next;
- LPLINKEDLIST lpNode = m_lpHead;
- BOOL fFlag = FALSE;
- __try
- {
- while (lpNode)
- {
- if ((CSessionInfo*)lpNode->lpData == lpData)
- {
- next = lpNode->next;
- prev = lpNode->prev;
- if (prev) prev->next = next;
- else m_lpHead = next;
- if (next) next->prev = prev;
- else m_lpTail = prev;
- GlobalFree(lpNode);
- m_nCount--;
- fFlag = TRUE;
- break;
- }
- lpNode = lpNode->next;
- }
- }
- __finally
- {
- // LeaveCriticalSection(&m_cs);
- }
- return fFlag;
- }
- /*
- LPLINKEDLIST CWHList::FindNode(LPLINKEDLIST lpList)
- {
- EnterCriticalSection(&m_cs);
- LPLINKEDLIST lpNode = m_lpHead;
- while (lpNode)
- {
- if (lpNode == lpList)
- return lpNode;
- lpNode = lpNode->next;
- }
- LeaveCriticalSection(&m_cs);
- return NULL;
- }
- */
- template <class T>T CWHList<T>::FindDataByKey(SOCKET s)
- {
- LPLINKEDLIST lpNode = m_lpHead;
- // EnterCriticalSection(&m_cs);
- while (lpNode)
- {
- if (((CSessionInfo*)lpNode->lpData)->sock == s)
- return (CSessionInfo*)lpNode->lpData;
- lpNode = lpNode->next;
- }
- // LeaveCriticalSection(&m_cs);
- return NULL;
- }