Update mysql module project files and use AMTL.

This commit is contained in:
Arkshine 2014-08-10 12:27:05 +02:00
parent 4f3d335ab4
commit 3ba84fb283
19 changed files with 70 additions and 6430 deletions

View File

@ -34,7 +34,7 @@ if AMXX.mysql_path:
'handles.cpp',
'module.cpp',
'threading.cpp',
'sdk/amxxmodule.cpp',
'../../public/sdk/amxxmodule.cpp',
'oldcompat_sql.cpp',
'thread/BaseWorker.cpp',
'thread/ThreadWorker.cpp',

View File

@ -8,6 +8,7 @@
HLSDK = ../../../hlsdk
MM_ROOT = ../../../metamod/metamod
MYSQL_DIR = ../../../mysql-5.0
PUBLIC_ROOT = ../../public
#####################################
### EDIT BELOW FOR OTHER PROJECTS ###
@ -15,7 +16,7 @@ MYSQL_DIR = ../../../mysql-5.0
PROJECT = mysql
OBJECTS = basic_sql.cpp handles.cpp module.cpp threading.cpp sdk/amxxmodule.cpp oldcompat_sql.cpp \
OBJECTS = basic_sql.cpp handles.cpp module.cpp threading.cpp amxxmodule.cpp oldcompat_sql.cpp \
thread/BaseWorker.cpp thread/ThreadWorker.cpp thread/PosixThreads.cpp \
mysql/MysqlQuery.cpp mysql/MysqlResultSet.cpp mysql/MysqlDatabase.cpp mysql/MysqlDriver.cpp
@ -32,8 +33,10 @@ CPP_OSX = clang
LINK = $(MYSQL_DIR)/lib/libmysqlclient_r.a -lz -lpthread -L$(MYSQL_DIR)/lib
INCLUDE = -I. -I$(HLSDK) -I$(HLSDK)/common -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared \
-I$(HLSDK)/public -I$(MM_ROOT) -I$(MYSQL_DIR)/include -Ithread -Imysql -Isdk
INCLUDE = -I. -I$(PUBLIC_ROOT) -I$(PUBLIC_ROOT)/sdk -I$(PUBLIC_ROOT)/amtl \
-I$(HLSDK) -I$(HLSDK)/public -I$(HLSDK)/common -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared -I$(HLSDK)/pm_shared\
-I$(MYSQL_DIR)/include -Ithread -Imysql \
-I$(MM_ROOT)
################################################
### DO NOT EDIT BELOW HERE FOR MOST PROJECTS ###
@ -111,7 +114,7 @@ all:
mkdir -p $(BIN_DIR)
mkdir -p $(BIN_DIR)/mysql
mkdir -p $(BIN_DIR)/thread
mkdir -p $(BIN_DIR)/sdk
ln -sf $(PUBLIC_ROOT)/sdk/amxxmodule.cpp
$(MAKE) -f $(MAKEFILE_NAME) $(PROJECT)
$(PROJECT): $(OBJ_BIN)
@ -126,6 +129,5 @@ clean:
rm -rf $(BIN_DIR)/*.o
rm -rf $(BIN_DIR)/mysql/*.o
rm -rf $(BIN_DIR)/thread/*.o
rm -rf $(BIN_DIR)/sdk/*.o
rm -f $(BIN_DIR)/$(BINARY)

View File

@ -12,12 +12,10 @@
//
#include <stdio.h>
#include "sh_list.h"
#include "mysql2_header.h"
#include "sqlheaders.h"
using namespace SourceMod;
using namespace SourceHook;
MysqlDriver g_Mysql;

View File

@ -12,8 +12,8 @@
//
#include <string.h>
#include "sh_stack.h"
#include "CVector.h"
#include <sh_stack.h>
#include <am-vector.h>
#include "mysql2_header.h"
struct QHandle
@ -24,7 +24,7 @@ struct QHandle
bool isfree;
};
CVector<QHandle *> g_Handles;
ke::Vector<QHandle *> g_Handles;
CStack<unsigned int> g_FreeHandles;
unsigned int MakeHandle(void *ptr, HandleType type, FREEHANDLE f)
@ -39,8 +39,8 @@ unsigned int MakeHandle(void *ptr, HandleType type, FREEHANDLE f)
h = g_Handles[num];
} else {
h = new QHandle;
g_Handles.push_back(h);
num = static_cast<unsigned int>(g_Handles.size()) - 1;
g_Handles.append(h);
num = static_cast<unsigned int>(g_Handles.length()) - 1;
}
h->_ptr = ptr;
@ -57,7 +57,7 @@ void *GetHandle(unsigned int num, HandleType type)
return NULL;
num--;
if (num >= g_Handles.size())
if (num >= g_Handles.length())
return NULL;
QHandle *h = g_Handles[num];
@ -75,7 +75,7 @@ bool FreeHandle(unsigned int num)
unsigned int _num = num;
num--;
if (num >= g_Handles.size())
if (num >= g_Handles.length())
return false;
QHandle *h = g_Handles[num];
@ -95,7 +95,7 @@ bool FreeHandle(unsigned int num)
void FreeAllHandles(HandleType type)
{
QHandle *q;
for (size_t i = 0; i < g_Handles.size(); i++)
for (size_t i = 0; i < g_Handles.length(); i++)
{
q = g_Handles[i];
if (q && !q->isfree && q->type == type)
@ -108,7 +108,7 @@ void FreeAllHandles(HandleType type)
void FreeHandleTable()
{
QHandle *q;
for (size_t i = 0; i < g_Handles.size(); i++)
for (size_t i = 0; i < g_Handles.length(); i++)
{
q = g_Handles[i];
if (q && !q->isfree)

View File

View File

@ -52,8 +52,8 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\;..\..\..\..\mysql-5.0\include;..\mysql;..\sdk;..\thread;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\public;$(MYSQL5)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;MYSQL2_EXPORTS;SM_DEFAULT_THREADER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\;..\..\..\public;..\..\..\public\sdk; ..\..\..\public\amtl;..\..\..\..\mysql-5.0\include;..\mysql;..\sdk;..\thread;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\public;$(MYSQL5)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;MYSQL2_EXPORTS;SM_DEFAULT_THREADER;HAVE_STDINT_H;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
@ -75,8 +75,8 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>..\;..\..\..\..\mysql-5.0\include;..\mysql;..\sdk;..\thread;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\public;$(MYSQL5)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;MYSQL2_EXPORTS;SM_DEFAULT_THREADER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\;..\..\..\public;..\..\..\public\sdk; ..\..\..\public\amtl;..\..\..\..\mysql-5.0\include;..\mysql;..\sdk;..\thread;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\public;$(MYSQL5)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;MYSQL2_EXPORTS;SM_DEFAULT_THREADER;HAVE_STDINT_H;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<PrecompiledHeader>
@ -108,7 +108,7 @@
<ClCompile Include="..\mysql\MysqlDriver.cpp" />
<ClCompile Include="..\mysql\MysqlQuery.cpp" />
<ClCompile Include="..\mysql\MysqlResultSet.cpp" />
<ClCompile Include="..\sdk\amxxmodule.cpp" />
<ClCompile Include="..\..\..\public\sdk\amxxmodule.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\mysql2_header.h" />
@ -126,11 +126,8 @@
<ClInclude Include="..\mysql\MysqlHeaders.h" />
<ClInclude Include="..\mysql\MysqlQuery.h" />
<ClInclude Include="..\mysql\MysqlResultSet.h" />
<ClInclude Include="..\sdk\moduleconfig.h" />
<ClInclude Include="..\sdk\CVector.h" />
<ClInclude Include="..\sdk\sh_list.h" />
<ClInclude Include="..\sdk\sh_stack.h" />
<ClInclude Include="..\sdk\amxxmodule.h" />
<ClInclude Include="..\moduleconfig.h" />
<ClInclude Include="..\..\..\public\sdk\amxxmodule.h" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\plugins\include\sqlx.inc" />

View File

@ -30,9 +30,6 @@
<Filter Include="Module SDK">
<UniqueIdentifier>{15c62ca4-f448-4a1e-8277-9bee3e572408}</UniqueIdentifier>
</Filter>
<Filter Include="Module SDK\AMXX STL">
<UniqueIdentifier>{915eac13-018c-4e63-b9b1-080e89173ce6}</UniqueIdentifier>
</Filter>
<Filter Include="Module SDK\SDK Base">
<UniqueIdentifier>{41c3be98-7cfc-4071-b7fd-be17c2ee7279}</UniqueIdentifier>
</Filter>
@ -77,7 +74,7 @@
<ClCompile Include="..\mysql\MysqlResultSet.cpp">
<Filter>Database\Source Files</Filter>
</ClCompile>
<ClCompile Include="..\sdk\amxxmodule.cpp">
<ClCompile Include="..\..\..\public\sdk\amxxmodule.cpp">
<Filter>Module SDK\SDK Base</Filter>
</ClCompile>
</ItemGroup>
@ -127,19 +124,10 @@
<ClInclude Include="..\mysql\MysqlResultSet.h">
<Filter>Database\Header Files</Filter>
</ClInclude>
<ClInclude Include="..\sdk\moduleconfig.h">
<ClInclude Include="..\moduleconfig.h">
<Filter>Module SDK</Filter>
</ClInclude>
<ClInclude Include="..\sdk\CVector.h">
<Filter>Module SDK\AMXX STL</Filter>
</ClInclude>
<ClInclude Include="..\sdk\sh_list.h">
<Filter>Module SDK\AMXX STL</Filter>
</ClInclude>
<ClInclude Include="..\sdk\sh_stack.h">
<Filter>Module SDK\AMXX STL</Filter>
</ClInclude>
<ClInclude Include="..\sdk\amxxmodule.h">
<ClInclude Include="..\..\..\public\sdk\amxxmodule.h">
<Filter>Module SDK\SDK Base</Filter>
</ClInclude>
</ItemGroup>

View File

@ -12,7 +12,6 @@
//
#include <stdio.h>
#include "sh_list.h"
#include "mysql2_header.h"
using namespace SourceMod;

View File

@ -1,480 +0,0 @@
// vim: set ts=4 sw=4 tw=99 noet:
//
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
// Copyright (C) The AMX Mod X Development Team.
//
// This software is licensed under the GNU General Public License, version 3 or higher.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// https://alliedmods.net/amxmodx-license
#ifndef __CVECTOR_H__
#define __CVECTOR_H__
#include <assert.h>
// Vector
template <class T> class CVector
{
bool Grow(size_t amount)
{
// automatic grow
size_t newSize = m_Size * 2;
if (newSize == 0)
{
newSize = 8;
}
while (m_CurrentUsedSize + amount > newSize)
{
newSize *= 2;
}
T *newData = new T[newSize];
if (!newData)
return false;
if (m_Data)
{
for (size_t i=0; i<m_CurrentUsedSize; i++)
newData[i] = m_Data[i];
delete [] m_Data;
}
m_Data = newData;
m_Size = newSize;
return true;
}
bool GrowIfNeeded(size_t amount)
{
if (m_CurrentUsedSize + amount >= m_Size)
{
return Grow(amount);
}
else
{
return true;
}
}
bool ChangeSize(size_t size)
{
// change size
if (size == m_Size)
return true;
if (!size)
{
if (m_Data)
{
delete [] m_Data;
m_Data = NULL;
m_Size = 0;
}
return true;
}
T *newData = new T[size];
if (!newData)
return false;
if (m_Data)
{
size_t end = (m_CurrentUsedSize < size) ? (m_CurrentUsedSize) : size;
for (size_t i=0; i<end; i++)
newData[i] = m_Data[i];
delete [] m_Data;
}
m_Data = newData;
m_Size = size;
if (m_CurrentUsedSize > m_Size)
m_CurrentUsedSize = m_Size;
return true;
}
void FreeMemIfPossible()
{
if (!m_Data)
return;
if (!m_CurrentUsedSize)
{
ChangeSize(0);
return;
}
size_t newSize = m_Size;
while (m_CurrentUsedSize <= newSize / 2)
newSize /= 2;
if (newSize != m_Size)
ChangeSize(newSize);
}
protected:
T *m_Data;
size_t m_Size;
size_t m_CurrentUsedSize;
public:
class iterator
{
protected:
T *m_Ptr;
public:
// constructors / destructors
iterator()
{
m_Ptr = NULL;
}
iterator(T * ptr)
{
m_Ptr = ptr;
}
// member functions
T * base()
{
return m_Ptr;
}
const T * base() const
{
return m_Ptr;
}
// operators
T & operator*()
{
return *m_Ptr;
}
T * operator->()
{
return m_Ptr;
}
iterator & operator++() // preincrement
{
++m_Ptr;
return (*this);
}
iterator operator++(int) // postincrement
{
iterator tmp = *this;
++m_Ptr;
return tmp;
}
iterator & operator--() // predecrement
{
--m_Ptr;
return (*this);
}
iterator operator--(int) // postdecrememnt
{
iterator tmp = *this;
--m_Ptr;
return tmp;
}
bool operator==(T * right) const
{
return (m_Ptr == right);
}
bool operator==(const iterator & right) const
{
return (m_Ptr == right.m_Ptr);
}
bool operator!=(T * right) const
{
return (m_Ptr != right);
}
bool operator!=(const iterator & right) const
{
return (m_Ptr != right.m_Ptr);
}
iterator & operator+=(size_t offset)
{
m_Ptr += offset;
return (*this);
}
iterator & operator-=(size_t offset)
{
m_Ptr -= offset;
return (*this);
}
iterator operator+(size_t offset) const
{
iterator tmp(*this);
tmp.m_Ptr += offset;
return tmp;
}
iterator operator-(size_t offset) const
{
iterator tmp(*this);
tmp.m_Ptr -= offset;
return tmp;
}
T & operator[](size_t offset)
{
return (*(*this + offset));
}
const T & operator[](size_t offset) const
{
return (*(*this + offset));
}
bool operator<(const iterator & right) const
{
return m_Ptr < right.m_Ptr;
}
bool operator>(const iterator & right) const
{
return m_Ptr > right.m_Ptr;
}
bool operator<=(const iterator & right) const
{
return m_Ptr <= right.m_Ptr;
}
bool operator>=(const iterator & right) const
{
return m_Ptr >= right.m_Ptr;
}
size_t operator-(const iterator & right) const
{
return m_Ptr - right.m_Ptr;
}
};
// constructors / destructors
CVector<T>()
{
m_Size = 0;
m_CurrentUsedSize = 0;
m_Data = NULL;
}
CVector<T>(const CVector<T> & other)
{
// copy data
m_Data = new T [other.m_CurrentUsedSize];
m_Size = other.m_CurrentUsedSize;
m_CurrentUsedSize = other.m_CurrentUsedSize;
for (size_t i=0; i<other.m_CurrentUsedSize; i++)
m_Data[i] = other.m_Data[i];
}
~CVector<T>()
{
clear();
}
// interface
size_t size() const
{
return m_CurrentUsedSize;
}
size_t capacity() const
{
return m_Size;
}
iterator begin() const
{
return iterator(m_Data);
}
iterator end() const
{
return iterator(m_Data + m_CurrentUsedSize);
}
iterator iterAt(size_t pos)
{
if (pos > m_CurrentUsedSize)
assert(0);
return iterator(m_Data + pos);
}
bool reserve(size_t newSize)
{
if (newSize > m_Size)
return ChangeSize(newSize);
return true;
}
bool push_back(const T & elem)
{
if (!GrowIfNeeded(1))
{
return false;
}
m_Data[m_CurrentUsedSize++] = elem;
return true;
}
void pop_back()
{
--m_CurrentUsedSize;
if (m_CurrentUsedSize < 0)
m_CurrentUsedSize = 0;
FreeMemIfPossible();
}
bool resize(size_t newSize)
{
if (!ChangeSize(newSize))
return false;
m_CurrentUsedSize = newSize;
return true;
}
bool empty() const
{
return (m_CurrentUsedSize == 0);
}
T & at(size_t pos)
{
if (pos > m_CurrentUsedSize)
{
assert(0);
}
return m_Data[pos];
}
const T & at(size_t pos) const
{
if (pos > m_CurrentUsedSize)
{
assert(0);
}
return m_Data[pos];
}
T & operator[](size_t pos)
{
return at(pos);
}
const T & operator[](size_t pos) const
{
return at(pos);
}
T & front()
{
if (m_CurrentUsedSize < 1)
{
assert(0);
}
return m_Data[0];
}
const T & front() const
{
if (m_CurrentUsedSize < 1)
{
assert(0);
}
return m_Data[0];
}
T & back()
{
if (m_CurrentUsedSize < 1)
{
assert(0);
}
return m_Data[m_CurrentUsedSize - 1];
}
const T & back() const
{
if (m_CurrentUsedSize < 1)
{
assert(0);
}
return m_Data[m_CurrentUsedSize - 1];
}
iterator insert(iterator where, const T & value)
{
// validate iter
if (where < m_Data || where > (m_Data + m_CurrentUsedSize))
return iterator(0);
size_t ofs = where - begin();
if (!GrowIfNeeded(1))
{
return false;
}
++m_CurrentUsedSize;
where = begin() + ofs;
// Move subsequent entries
for (T *ptr = m_Data + m_CurrentUsedSize - 2; ptr >= where.base(); --ptr)
*(ptr + 1) = *ptr;
*where.base() = value;
return where;
}
iterator erase(iterator where)
{
// validate iter
if (where < m_Data || where >= (m_Data + m_CurrentUsedSize))
return iterator(0);
size_t ofs = where - begin();
if (m_CurrentUsedSize > 1)
{
// move
T *theend = m_Data + m_CurrentUsedSize;
for (T *ptr = where.base() + 1; ptr < theend; ++ptr)
*(ptr - 1) = *ptr;
}
--m_CurrentUsedSize;
FreeMemIfPossible();
return begin() + ofs;
}
void clear()
{
m_Size = 0;
m_CurrentUsedSize = 0;
if (m_Data)
{
delete [] m_Data;
m_Data = NULL;
}
}
};
#endif // __CVECTOR_H__

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,219 +0,0 @@
/* ======== SourceMM ========
* Copyright (C) 2004-2005 Metamod:Source Development Team
* No warranties of any kind
*
* License: zlib/libpng
*
* Author(s): Pavol "PM OnoTo" Marko
* ============================
*/
#ifndef __SH_STACK_H__
#define __SH_STACK_H__
#define SH_STACK_DEFAULT_SIZE 4
//namespace SourceHook
//{/
// Vector
template <class T> class CStack
{
T *m_Elements;
size_t m_AllocatedSize;
size_t m_UsedSize;
public:
friend class iterator;
class iterator
{
CStack<T> *m_pParent;
size_t m_Index;
public:
iterator(CStack<T> *pParent, size_t id) : m_pParent(pParent), m_Index(id)
{
}
iterator(CStack<T> *pParent) : m_pParent(pParent), m_Index(0)
{
}
iterator() : m_pParent(NULL), m_Index(0)
{
}
T &operator *()
{
return m_pParent->m_Elements[m_Index];
}
const T &operator *() const
{
return m_pParent->m_Elements[m_Index];
}
T * operator->()
{
return m_pParent->m_Elements + m_Index;
}
const T * operator->() const
{
return m_pParent->m_Elements + m_Index;
}
iterator & operator++() // preincrement
{
++m_Index;
return (*this);
}
iterator operator++(int) // postincrement
{
iterator tmp = *this;
++m_Index;
return tmp;
}
iterator & operator--() // predecrement
{
--m_Index;
return (*this);
}
iterator operator--(int) // postdecrememnt
{
iterator tmp = *this;
--m_Index;
return tmp;
}
bool operator==(const iterator & right) const
{
return (m_pParent == right.m_pParent && m_Index == right.m_Index);
}
bool operator!=(const iterator & right) const
{
return !(*this == right);
}
};
CStack() : m_Elements(new T[SH_STACK_DEFAULT_SIZE]),
m_AllocatedSize(SH_STACK_DEFAULT_SIZE),
m_UsedSize(0)
{
}
CStack(size_t size) : m_Elements(new T[size]),
m_AllocatedSize(size),
m_UsedSize(0)
{
}
CStack(const CStack &other) : m_Elements(NULL),
m_AllocatedSize(0),
m_UsedSize(0)
{
reserve(other.m_AllocatedSize);
m_UsedSize = other.m_UsedSize;
for (size_t i = 0; i < m_UsedSize; ++i)
m_Elements[i] = other.m_Elements[i];
}
~CStack()
{
if (m_Elements)
delete [] m_Elements;
}
void operator=(const CStack &other)
{
if (m_AllocatedSize < other.m_AllocatedSize)
{
if (m_Elements)
delete [] m_Elements;
m_Elements = new T[other.m_AllocatedSize];
m_AllocatedSize = other.m_AllocatedSize;
}
m_UsedSize = other.m_UsedSize;
for (size_t i = 0; i < m_UsedSize; ++i)
m_Elements[i] = other.m_Elements[i];
}
bool push(const T &val)
{
if (m_UsedSize + 1 == m_AllocatedSize)
{
// zOHNOES! REALLOCATE!
m_AllocatedSize *= 2;
T *newElements = new T[m_AllocatedSize];
if (!newElements)
{
m_AllocatedSize /= 2;
return false;
}
if (m_Elements)
{
for (size_t i = 0; i < m_UsedSize; ++i)
newElements[i] = m_Elements[i];
delete [] m_Elements;
}
m_Elements = newElements;
}
m_Elements[m_UsedSize++] = val;
return true;
}
void pop()
{
--m_UsedSize;
}
T &front()
{
return m_Elements[m_UsedSize - 1];
}
const T &front() const
{
return m_Elements[m_UsedSize - 1];
}
iterator begin()
{
return iterator(this, 0);
}
iterator end()
{
return iterator(this, m_UsedSize);
}
size_t size()
{
return m_UsedSize;
}
size_t capacity()
{
return m_AllocatedSize;
}
bool empty()
{
return m_UsedSize == 0 ? true : false;
}
bool reserve(size_t size)
{
if (size > m_AllocatedSize)
{
T *newElements = new T[size];
if (!newElements)
return false;
if (m_Elements)
{
for (size_t i = 0; i < m_UsedSize; ++i)
newElements[i] = m_Elements[i];
delete [] m_Elements;
}
m_Elements = newElements;
m_AllocatedSize = size;
}
return true;
}
};
//}; //namespace SourceHook
#endif

View File

@ -8,6 +8,7 @@
// https://alliedmods.net/amxmodx-license
#include "BaseWorker.h"
#include <am-linkedlist.h>
BaseWorker::BaseWorker() :
m_perFrame(SM_DEFAULT_THREADS_PER_FRAME),
@ -20,7 +21,7 @@ BaseWorker::~BaseWorker()
if (m_state != Worker_Stopped || m_state != Worker_Invalid)
Stop(true);
if (m_ThreadQueue.size())
if (m_ThreadQueue.length())
Flush(true);
}
@ -83,10 +84,10 @@ unsigned int BaseWorker::Flush(bool flush_cancel)
SWThreadHandle *BaseWorker::PopThreadFromQueue()
{
if (!m_ThreadQueue.size())
if (!m_ThreadQueue.length())
return NULL;
SourceHook::List<SWThreadHandle *>::iterator begin;
ke::LinkedList<SWThreadHandle *>::iterator begin;
SWThreadHandle *swt;
begin = m_ThreadQueue.begin();
@ -98,7 +99,7 @@ SWThreadHandle *BaseWorker::PopThreadFromQueue()
void BaseWorker::AddThreadToQueue(SWThreadHandle *pHandle)
{
m_ThreadQueue.push_back(pHandle);
m_ThreadQueue.append(pHandle);
}
unsigned int BaseWorker::GetMaxThreadsPerFrame()

View File

@ -10,7 +10,7 @@
#ifndef _INCLUDE_SOURCEMOD_BASEWORKER_H
#define _INCLUDE_SOURCEMOD_BASEWORKER_H
#include "sh_list.h"
#include <am-linkedlist.h>
#include "ThreadSupport.h"
#define SM_DEFAULT_THREADS_PER_FRAME 1
@ -73,7 +73,7 @@ public: //BaseWorker
virtual void SetMaxThreadsPerFrame(unsigned int threads);
virtual unsigned int GetMaxThreadsPerFrame();
protected:
SourceHook::List<SWThreadHandle *> m_ThreadQueue;
ke::LinkedList<SWThreadHandle *> m_ThreadQueue;
unsigned int m_perFrame;
volatile WorkerState m_state;
};

View File

@ -43,7 +43,7 @@ ThreadWorker::~ThreadWorker()
if (m_state != Worker_Stopped || m_state != Worker_Invalid)
Stop(true);
if (m_ThreadQueue.size())
if (m_ThreadQueue.length())
Flush(true);
}
@ -69,7 +69,7 @@ void ThreadWorker::RunThread(IThreadHandle *pHandle)
if (this_state != Worker_Stopped)
{
m_QueueLock->Lock();
num = m_ThreadQueue.size();
num = m_ThreadQueue.length();
if (!num)
{
/**
@ -106,7 +106,7 @@ void ThreadWorker::RunThread(IThreadHandle *pHandle)
// run all of the remaining frames first.
if (!m_FlushType)
{
while (m_ThreadQueue.size())
while (m_ThreadQueue.length())
RunFrame();
}
break;

View File

@ -16,7 +16,6 @@
#include "threading.h"
using namespace SourceMod;
using namespace SourceHook;
MainThreader g_Threader;
ThreadWorker *g_pWorker = NULL;
@ -144,10 +143,10 @@ void MysqlThread::SetForward(int forward)
void MysqlThread::SetInfo(const char *host, const char *user, const char *pass, const char *db, int port, unsigned int max_timeout)
{
m_host.assign(host);
m_user.assign(user);
m_pass.assign(pass);
m_db.assign(db);
m_host = host;
m_user = user;
m_pass = pass;
m_db = db;
m_max_timeout = max_timeout;
m_port = port;
m_qrInfo.queue_time = gpGlobals->time;
@ -155,25 +154,25 @@ void MysqlThread::SetInfo(const char *host, const char *user, const char *pass,
void MysqlThread::SetCharacterSet(const char *charset)
{
m_charset.assign(charset);
m_charset = charset;
}
void MysqlThread::SetQuery(const char *query)
{
m_query.assign(query);
m_query = query;
}
void MysqlThread::RunThread(IThreadHandle *pHandle)
{
DatabaseInfo info;
info.database = m_db.c_str();
info.pass = m_pass.c_str();
info.user = m_user.c_str();
info.host = m_host.c_str();
info.database = m_db.chars();
info.pass = m_pass.chars();
info.user = m_user.chars();
info.host = m_host.chars();
info.port = m_port;
info.max_timeout = m_max_timeout;
info.charset = m_charset.c_str();
info.charset = m_charset.chars();
float save_time = m_qrInfo.queue_time;
@ -191,7 +190,7 @@ void MysqlThread::RunThread(IThreadHandle *pHandle)
else
{
m_qrInfo.connect_success = true;
pQuery = pDatabase->PrepareQuery(m_query.c_str());
pQuery = pDatabase->PrepareQuery(m_query.chars());
if (!pQuery->Execute2(&m_qrInfo.amxinfo.info, m_qrInfo.amxinfo.error, 254))
{
m_qrInfo.query_success = false;
@ -215,8 +214,8 @@ void MysqlThread::RunThread(IThreadHandle *pHandle)
}
m_qrInfo.amxinfo.pQuery = NULL;
m_qrInfo.amxinfo.opt_ptr = new char[m_query.size() + 1];
strcpy(m_qrInfo.amxinfo.opt_ptr, m_query.c_str());
m_qrInfo.amxinfo.opt_ptr = new char[m_query.length() + 1];
strcpy(m_qrInfo.amxinfo.opt_ptr, m_query.chars());
if (pDatabase)
{
@ -440,7 +439,7 @@ bool AtomicResult::FieldNameToNum(const char *name, unsigned int *columnId)
for (unsigned int i=0; i<m_FieldCount; i++)
{
assert(m_Table[i] != NULL);
if (strcmp(m_Table[i]->c_str(), name) == 0)
if (strcmp(m_Table[i]->chars(), name) == 0)
{
if (columnId)
{
@ -460,7 +459,7 @@ const char *AtomicResult::FieldNumToName(unsigned int num)
assert(m_Table[num] != NULL);
return m_Table[num]->c_str();
return m_Table[num]->chars();
}
double AtomicResult::GetDouble(unsigned int columnId)
@ -501,7 +500,7 @@ const char *AtomicResult::GetString(unsigned int columnId)
assert(m_Table[idx] != NULL);
return m_Table[idx]->c_str();
return m_Table[idx]->chars();
}
IResultRow *AtomicResult::GetRow()
@ -551,11 +550,11 @@ void AtomicResult::CopyFrom(IResultSet *rs)
size_t newTotal = (m_RowCount * m_FieldCount) + m_FieldCount;
if (newTotal > m_AllocSize)
{
SourceHook::String **table = new SourceHook::String *[newTotal];
memset(table, 0, newTotal * sizeof(SourceHook::String *));
ke::AString **table = new ke::AString *[newTotal];
memset(table, 0, newTotal * sizeof(ke::AString *));
if (m_Table)
{
memcpy(table, m_Table, m_AllocSize * sizeof(SourceHook::String *));
memcpy(table, m_Table, m_AllocSize * sizeof(ke::AString *));
delete [] m_Table;
}
m_Table = table;
@ -566,9 +565,9 @@ void AtomicResult::CopyFrom(IResultSet *rs)
{
if (m_Table[i])
{
m_Table[i]->assign(rs->FieldNumToName(i));
*m_Table[i] = rs->FieldNumToName(i);
} else {
m_Table[i] = new SourceHook::String(rs->FieldNumToName(i));
m_Table[i] = new ke::AString(rs->FieldNumToName(i));
}
}
@ -581,9 +580,9 @@ void AtomicResult::CopyFrom(IResultSet *rs)
{
if (m_Table[idx])
{
m_Table[idx]->assign(row->GetString(i));
*m_Table[idx] = row->GetString(i);
} else {
m_Table[idx] = new SourceHook::String(row->GetString(i));
m_Table[idx] = new ke::AString(row->GetString(i));
}
}
rs->NextRow();

View File

@ -16,9 +16,8 @@
#include "IThreader.h"
#include "ISQLDriver.h"
#include "sh_string.h"
#include "CVector.h"
#include "sh_stack.h"
#include <am-string.h>
#include <sh_stack.h>
struct QueuedResultInfo
{
@ -64,7 +63,7 @@ private:
unsigned int m_RowCount;
unsigned int m_FieldCount;
size_t m_AllocSize;
SourceHook::String **m_Table;
ke::AString **m_Table;
unsigned int m_CurRow;
bool m_IsFree;
};
@ -86,13 +85,13 @@ public:
void RunThread(IThreadHandle *pHandle);
void OnTerminate(IThreadHandle *pHandle, bool cancel);
private:
SourceHook::String m_query;
SourceHook::String m_host;
SourceHook::String m_user;
SourceHook::String m_pass;
SourceHook::String m_db;
ke::AString m_query;
ke::AString m_host;
ke::AString m_user;
ke::AString m_pass;
ke::AString m_db;
unsigned int m_max_timeout;
SourceHook::String m_charset;
ke::AString m_charset;
int m_port;
cell *m_data;
ucell m_datalen;

0
dlls/mysqlx/sdk/sh_string.h → public/sh_string.h Executable file → Normal file
View File