Restructure repository to include all source folders
Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
92
Server/ToolProject/Arrangement2/MemUtils.h
Normal file
92
Server/ToolProject/Arrangement2/MemUtils.h
Normal file
@@ -0,0 +1,92 @@
|
||||
#ifndef _MEMUTILS_H_
|
||||
#define _MEMUTILS_H_
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
|
||||
#define SAFE_FREE(p) { if (p) { free(p); (p) = NULL; } }
|
||||
#define SAFE_DELETE(p) { if (p) { delete (p); (p) = NULL; } }
|
||||
#define SAFE_DELETE_ARRAY(p) { if (p) { delete[] (p); (p) = NULL; } }
|
||||
#define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p) = NULL; } }
|
||||
#define SAFE_CLOSESOCK(p) { if (INVALID_SOCKET != (p)) { closesocket(p); (p) = INVALID_SOCKET; } }
|
||||
#define SAFE_CLOSEHANDLE(p) { if (INVALID_HANDLE_VALUE != (p)) { CloseHandle(p); (p) = INVALID_HANDLE_VALUE; } }
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Լ<EFBFBD><D4BC>ڿ<EFBFBD>, <20>˰<EFBFBD><CBB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ֽ<EFBFBD><D6BD>ϴ<EFBFBD>.
|
||||
namespace MemUtils
|
||||
{
|
||||
// <20><>ü <20><><EFBFBD><EFBFBD>
|
||||
template<typename Object>
|
||||
struct fnCreate {
|
||||
Object* operator() () {
|
||||
return new Object;
|
||||
}
|
||||
};
|
||||
|
||||
// <20><>ü <20><><EFBFBD><EFBFBD>
|
||||
struct fnDelete {
|
||||
template<typename Object>
|
||||
void operator() (Object* pObject) {
|
||||
delete pObject;
|
||||
}
|
||||
};
|
||||
|
||||
// Map<61><70> Pair<69><72> <20>ִ<EFBFBD> <20><>ü <20><><EFBFBD><EFBFBD>
|
||||
struct fnDelete2nd {
|
||||
template<typename Pair>
|
||||
void operator() (Pair& pair) {
|
||||
delete pair.second;
|
||||
}
|
||||
};
|
||||
|
||||
// <20>迭 <20><><EFBFBD><EFBFBD>
|
||||
struct fnDeleteArray {
|
||||
template<typename Object>
|
||||
void operator() (Object* pObject) {
|
||||
delete [] pObject;
|
||||
}
|
||||
};
|
||||
|
||||
// Release <20><>.
|
||||
struct fnRelease {
|
||||
template<typename Object>
|
||||
void operator() (Object* pObject) {
|
||||
pObject->Release();
|
||||
}
|
||||
};
|
||||
|
||||
// Map<61><70> Pair<69><72> <20>ִ<EFBFBD> <20><>ü <20><><EFBFBD><EFBFBD>.
|
||||
struct fnRelease2nd {
|
||||
template<typename Pair>
|
||||
void operator() (Pair& pair) {
|
||||
pair.second->Release();
|
||||
}
|
||||
};
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> true<75≯<EFBFBD> <20><><EFBFBD>縦 <20>ϴ<EFBFBD> iterator.
|
||||
template<typename InputIterator, typename OutputIterator, typename Predicate>
|
||||
inline OutputIterator copy_if(InputIterator begin, InputIterator end, OutputIterator destBegin, Predicate Pred) {
|
||||
while(begin != end) {
|
||||
if(Pred(*begin)) *destBegin++ = *begin;
|
||||
++begin;
|
||||
}
|
||||
|
||||
return destBegin;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>̳ʸ<CCB3> <20><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD>̳<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ؼ<EFBFBD> delete<74><65> <20><><EFBFBD><EFBFBD>. DestructType <20><> fnDelete<74><65> fnRelease<73><65> <20>ϳ<EFBFBD>
|
||||
template<typename ContainerType, typename DesturctType, typename LockType>
|
||||
inline void ClearContainer(ContainerType& Container, DesturctType fnDestructor, LockType& Lock) {
|
||||
LockType::Syncronize sync(Lock);
|
||||
std::for_each(Container.begin(), Container.end(), fnDestructor);
|
||||
Container.clear();
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>̳ʸ<CCB3> <20><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD>̳<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ؼ<EFBFBD> delete<74><65> <20><><EFBFBD><EFBFBD>. DestructType <20><> fnDelete<74><65> fnRelease<73><65> <20>ϳ<EFBFBD>
|
||||
template<typename ContainerType, typename DestructType>
|
||||
inline void ClearContainer(ContainerType& Container, DestructType fnDestructor) {
|
||||
std::for_each(Container.begin(), Container.end(), fnDestructor);
|
||||
Container.clear();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user