Update engine module project files and use AMTL.
This commit is contained in:
		@@ -3,8 +3,12 @@ import os.path
 | 
			
		||||
 | 
			
		||||
binary = AMXX.MetaModule(builder, 'engine')
 | 
			
		||||
 | 
			
		||||
binary.compiler.defines += [
 | 
			
		||||
  'HAVE_STDINT_H',
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
binary.sources = [
 | 
			
		||||
  'sdk/amxxmodule.cpp',
 | 
			
		||||
  '../../public/sdk/amxxmodule.cpp',
 | 
			
		||||
  'amxxapi.cpp',
 | 
			
		||||
  'engine.cpp',
 | 
			
		||||
  'entity.cpp',
 | 
			
		||||
 
 | 
			
		||||
@@ -7,6 +7,7 @@
 | 
			
		||||
 | 
			
		||||
HLSDK = ../../../hlsdk
 | 
			
		||||
MM_ROOT = ../../../metamod/metamod
 | 
			
		||||
PUBLIC_ROOT = ../../public
 | 
			
		||||
 | 
			
		||||
#####################################
 | 
			
		||||
### EDIT BELOW FOR OTHER PROJECTS ###
 | 
			
		||||
@@ -14,7 +15,7 @@ MM_ROOT = ../../../metamod/metamod
 | 
			
		||||
 | 
			
		||||
PROJECT = engine
 | 
			
		||||
 | 
			
		||||
OBJECTS = sdk/amxxmodule.cpp amxxapi.cpp engine.cpp entity.cpp globals.cpp forwards.cpp
 | 
			
		||||
OBJECTS = amxxmodule.cpp amxxapi.cpp engine.cpp entity.cpp globals.cpp forwards.cpp
 | 
			
		||||
 | 
			
		||||
##############################################
 | 
			
		||||
### CONFIGURE ANY OTHER FLAGS/OPTIONS HERE ###
 | 
			
		||||
@@ -29,8 +30,9 @@ CPP_OSX = clang
 | 
			
		||||
 | 
			
		||||
LINK =
 | 
			
		||||
 | 
			
		||||
INCLUDE = -I. -I$(HLSDK) -I$(HLSDK)/common -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared \
 | 
			
		||||
	  -I$(HLSDK)/pm_shared -I$(HLSDK)/public -I$(MM_ROOT) -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$(MM_ROOT)
 | 
			
		||||
 | 
			
		||||
################################################
 | 
			
		||||
### DO NOT EDIT BELOW HERE FOR MOST PROJECTS ###
 | 
			
		||||
@@ -105,7 +107,7 @@ $(BIN_DIR)/%.o: %.cpp
 | 
			
		||||
 | 
			
		||||
all:
 | 
			
		||||
	mkdir -p $(BIN_DIR)
 | 
			
		||||
	mkdir -p $(BIN_DIR)/sdk
 | 
			
		||||
	ln -sf $(PUBLIC_ROOT)/sdk/amxxmodule.cpp
 | 
			
		||||
	$(MAKE) -f $(MAKEFILE_NAME) $(PROJECT)
 | 
			
		||||
 | 
			
		||||
$(PROJECT): $(OBJ_BIN)
 | 
			
		||||
@@ -118,6 +120,5 @@ default: all
 | 
			
		||||
 | 
			
		||||
clean:
 | 
			
		||||
	rm -rf $(BIN_DIR)/*.o
 | 
			
		||||
	rm -rf $(BIN_DIR)/sdk/*.o
 | 
			
		||||
	rm -f $(BIN_DIR)/$(BINARY)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -28,11 +28,11 @@ void ClearHooks()
 | 
			
		||||
{
 | 
			
		||||
	size_t i;
 | 
			
		||||
 | 
			
		||||
	for (i=0; i<Touches.size(); i++)
 | 
			
		||||
	for (i=0; i<Touches.length(); i++)
 | 
			
		||||
		delete Touches[i];
 | 
			
		||||
	for (i=0; i<Impulses.size(); i++)
 | 
			
		||||
	for (i=0; i<Impulses.length(); i++)
 | 
			
		||||
		delete Impulses[i];
 | 
			
		||||
	for (i=0; i<Thinks.size(); i++)
 | 
			
		||||
	for (i=0; i<Thinks.length(); i++)
 | 
			
		||||
		delete Thinks[i];
 | 
			
		||||
 | 
			
		||||
	Touches.clear();
 | 
			
		||||
 
 | 
			
		||||
@@ -43,11 +43,11 @@ static cell AMX_NATIVE_CALL register_think(AMX *amx, cell *params)
 | 
			
		||||
 | 
			
		||||
	EntClass *p = new EntClass;
 | 
			
		||||
	const char *clsname = MF_GetAmxString(amx, params[1], 0, &len);
 | 
			
		||||
	p->Class.assign(clsname);
 | 
			
		||||
	p->Class = clsname;
 | 
			
		||||
 | 
			
		||||
	p->Forward = MF_RegisterSPForwardByName(amx, MF_GetAmxString(amx, params[2], 0, &len), FP_CELL, FP_DONE);
 | 
			
		||||
 | 
			
		||||
	Thinks.push_back(p);
 | 
			
		||||
	Thinks.append(p);
 | 
			
		||||
 | 
			
		||||
	if (!g_pFunctionTable->pfnThink)
 | 
			
		||||
		g_pFunctionTable->pfnThink=Think;
 | 
			
		||||
@@ -64,7 +64,7 @@ static cell AMX_NATIVE_CALL register_impulse(AMX *amx, cell *params)
 | 
			
		||||
 | 
			
		||||
	p->Forward = MF_RegisterSPForwardByName(amx, MF_GetAmxString(amx, params[2], 0, &len), FP_CELL, FP_CELL, FP_DONE);
 | 
			
		||||
 | 
			
		||||
	Impulses.push_back(p);
 | 
			
		||||
	Impulses.append(p);
 | 
			
		||||
 | 
			
		||||
	if (!g_pFunctionTable->pfnCmdStart)
 | 
			
		||||
		g_pFunctionTable->pfnCmdStart=CmdStart;
 | 
			
		||||
@@ -82,19 +82,19 @@ static cell AMX_NATIVE_CALL register_touch(AMX *amx, cell *params)
 | 
			
		||||
	Touch *p = new Touch;
 | 
			
		||||
 | 
			
		||||
	if (!strlen(Toucher) || strcmp(Toucher, "*")==0) {
 | 
			
		||||
		p->Toucher.assign("");
 | 
			
		||||
		p->Toucher.setVoid();
 | 
			
		||||
	} else {
 | 
			
		||||
		p->Toucher.assign(Toucher);
 | 
			
		||||
		p->Toucher = Toucher;
 | 
			
		||||
	}
 | 
			
		||||
	if (!strlen(Touched) || strcmp(Touched, "*")==0) {
 | 
			
		||||
		p->Touched.assign("");
 | 
			
		||||
		p->Touched.setVoid();
 | 
			
		||||
	} else {
 | 
			
		||||
		p->Touched.assign(Touched);
 | 
			
		||||
		p->Touched = Touched;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	p->Forward = MF_RegisterSPForwardByName(amx, MF_GetAmxString(amx, params[3], 2, &len), FP_CELL, FP_CELL, FP_DONE);
 | 
			
		||||
 | 
			
		||||
	Touches.push_back(p);
 | 
			
		||||
	Touches.append(p);
 | 
			
		||||
 | 
			
		||||
	if (!g_pFunctionTable->pfnTouch)
 | 
			
		||||
		g_pFunctionTable->pfnTouch=pfnTouch;
 | 
			
		||||
 
 | 
			
		||||
@@ -19,12 +19,12 @@
 | 
			
		||||
#include <string.h> 
 | 
			
		||||
#include <meta_api.h>
 | 
			
		||||
#include <sdk_util.h>
 | 
			
		||||
#include "CVector.h"
 | 
			
		||||
#include "CString.h"
 | 
			
		||||
#include <usercmd.h>
 | 
			
		||||
#include "entity.h"
 | 
			
		||||
#include "gpglobals.h"
 | 
			
		||||
#include "entity_state.h"
 | 
			
		||||
#include <am-vector.h>
 | 
			
		||||
#include <am-string.h>
 | 
			
		||||
 | 
			
		||||
extern DLL_FUNCTIONS *g_pFunctionTable;
 | 
			
		||||
extern DLL_FUNCTIONS *g_pFunctionTable_Post;
 | 
			
		||||
@@ -140,8 +140,8 @@ class Touch
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
	int Forward;
 | 
			
		||||
	String Toucher;
 | 
			
		||||
	String Touched;
 | 
			
		||||
	ke::AString Toucher;
 | 
			
		||||
	ke::AString Touched;
 | 
			
		||||
	~Touch()
 | 
			
		||||
	{
 | 
			
		||||
		if (Forward != -1)
 | 
			
		||||
@@ -153,7 +153,7 @@ class EntClass
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
	int Forward;
 | 
			
		||||
	String Class;
 | 
			
		||||
	ke::AString Class;
 | 
			
		||||
	~EntClass()
 | 
			
		||||
	{
 | 
			
		||||
		if (Forward != -1)
 | 
			
		||||
@@ -226,9 +226,9 @@ extern struct PlayerInfo plinfo[33];
 | 
			
		||||
extern struct GlobalInfo glinfo;
 | 
			
		||||
extern AMX_NATIVE_INFO engine_Natives[];
 | 
			
		||||
extern AMX_NATIVE_INFO engine_NewNatives[];
 | 
			
		||||
extern CVector<Impulse *> Impulses;
 | 
			
		||||
extern CVector<EntClass *> Thinks;
 | 
			
		||||
extern CVector<Touch *> Touches;
 | 
			
		||||
extern ke::Vector<Impulse *> Impulses;
 | 
			
		||||
extern ke::Vector<EntClass *> Thinks;
 | 
			
		||||
extern ke::Vector<Touch *> Touches;
 | 
			
		||||
 | 
			
		||||
#endif //_ENGINE_INCLUDE_H
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -28,9 +28,9 @@ int CmdStartForward = 0;
 | 
			
		||||
int StartFrameForward = 0;
 | 
			
		||||
int VexdTouchForward = 0;
 | 
			
		||||
int VexdServerForward = 0;
 | 
			
		||||
CVector<Impulse *> Impulses;
 | 
			
		||||
CVector<EntClass *> Thinks;
 | 
			
		||||
CVector<Touch *> Touches;
 | 
			
		||||
ke::Vector<Impulse *> Impulses;
 | 
			
		||||
ke::Vector<EntClass *> Thinks;
 | 
			
		||||
ke::Vector<Touch *> Touches;
 | 
			
		||||
KeyValueData *g_pkvd;
 | 
			
		||||
bool g_inKeyValue=false;
 | 
			
		||||
bool g_precachedStuff = false;
 | 
			
		||||
@@ -139,7 +139,7 @@ void CmdStart(const edict_t *player, const struct usercmd_s *_cmd, unsigned int
 | 
			
		||||
	edict_t *pEntity = (edict_t *)player;
 | 
			
		||||
	g_cmd = (struct usercmd_s *)_cmd;
 | 
			
		||||
	int origImpulse = g_cmd->impulse; // incase a plugin alters it
 | 
			
		||||
	for (i=0; i<Impulses.size(); i++)
 | 
			
		||||
	for (i=0; i<Impulses.length(); i++)
 | 
			
		||||
	{
 | 
			
		||||
		if (Impulses[i]->Check == g_cmd->impulse)
 | 
			
		||||
		{
 | 
			
		||||
@@ -251,11 +251,11 @@ void pfnTouch(edict_t *pToucher, edict_t *pTouched)
 | 
			
		||||
	int ptrIndex = ENTINDEX(pToucher);
 | 
			
		||||
	int ptdIndex = ENTINDEX(pTouched);
 | 
			
		||||
	META_RES res=MRES_IGNORED;
 | 
			
		||||
	for (i=0; i<Touches.size(); i++)
 | 
			
		||||
	for (i=0; i<Touches.length(); i++)
 | 
			
		||||
	{
 | 
			
		||||
		if (Touches[i]->Toucher.size() == 0)
 | 
			
		||||
		if (Touches[i]->Toucher.length() == 0)
 | 
			
		||||
		{
 | 
			
		||||
			if (Touches[i]->Touched.size() == 0)
 | 
			
		||||
			if (Touches[i]->Touched.length() == 0)
 | 
			
		||||
			{
 | 
			
		||||
				retVal = MF_ExecuteForward(Touches[i]->Forward, (cell)ptrIndex, (cell)ptdIndex);
 | 
			
		||||
				if (retVal & 2/*PLUGIN_HANDLED_MAIN*/)
 | 
			
		||||
@@ -270,7 +270,7 @@ void pfnTouch(edict_t *pToucher, edict_t *pTouched)
 | 
			
		||||
					res=MRES_SUPERCEDE;
 | 
			
		||||
			}
 | 
			
		||||
		} else if (Touches[i]->Toucher.compare(ptrClass)==0) {
 | 
			
		||||
			if (Touches[i]->Touched.size() == 0)
 | 
			
		||||
			if (Touches[i]->Touched.length() == 0)
 | 
			
		||||
			{
 | 
			
		||||
				retVal = MF_ExecuteForward(Touches[i]->Forward, (cell)ptrIndex, (cell)ptdIndex);
 | 
			
		||||
				if (retVal & 2/*PLUGIN_HANDLED_MAIN*/)
 | 
			
		||||
@@ -307,7 +307,7 @@ void Think(edict_t *pent)
 | 
			
		||||
	const char *cls = STRING(pent->v.classname);
 | 
			
		||||
	META_RES res=MRES_IGNORED;
 | 
			
		||||
	int retVal=0;
 | 
			
		||||
	for (i=0; i<Thinks.size(); i++)
 | 
			
		||||
	for (i=0; i<Thinks.length(); i++)
 | 
			
		||||
	{
 | 
			
		||||
		if (Thinks[i]->Class.compare(cls)==0)
 | 
			
		||||
		{
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										0
									
								
								dlls/engine/sdk/moduleconfig.h → dlls/engine/moduleconfig.h
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										0
									
								
								dlls/engine/sdk/moduleconfig.h → dlls/engine/moduleconfig.h
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							@@ -52,8 +52,8 @@
 | 
			
		||||
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
 | 
			
		||||
    <ClCompile>
 | 
			
		||||
      <Optimization>Disabled</Optimization>
 | 
			
		||||
      <AdditionalIncludeDirectories>..\;..\sdk;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\pm_shared;$(HLSDK)\public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
 | 
			
		||||
      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;ENGINE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
			
		||||
      <AdditionalIncludeDirectories>..\;..\..\..\public;..\..\..\public\sdk; ..\..\..\public\amtl;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\pm_shared;$(HLSDK)\public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
 | 
			
		||||
      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;ENGINE_EXPORTS;HAVE_STDINT_H;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
			
		||||
      <MinimalRebuild>true</MinimalRebuild>
 | 
			
		||||
      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
 | 
			
		||||
      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
 | 
			
		||||
@@ -74,8 +74,8 @@
 | 
			
		||||
  </ItemDefinitionGroup>
 | 
			
		||||
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
 | 
			
		||||
    <ClCompile>
 | 
			
		||||
      <AdditionalIncludeDirectories>..\;..\sdk;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\pm_shared;$(HLSDK)\public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
 | 
			
		||||
      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;ENGINE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
			
		||||
      <AdditionalIncludeDirectories>..\;..\..\..\public;..\..\..\public\sdk; ..\..\..\public\amtl;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\pm_shared;$(HLSDK)\public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
 | 
			
		||||
      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;ENGINE_EXPORTS;HAVE_STDINT_H;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 | 
			
		||||
      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
 | 
			
		||||
      <StructMemberAlignment>4Bytes</StructMemberAlignment>
 | 
			
		||||
      <RuntimeTypeInfo>false</RuntimeTypeInfo>
 | 
			
		||||
@@ -99,17 +99,15 @@
 | 
			
		||||
    <ClCompile Include="..\entity.cpp" />
 | 
			
		||||
    <ClCompile Include="..\forwards.cpp" />
 | 
			
		||||
    <ClCompile Include="..\globals.cpp" />
 | 
			
		||||
    <ClCompile Include="..\sdk\amxxmodule.cpp" />
 | 
			
		||||
    <ClCompile Include="..\..\..\public\sdk\amxxmodule.cpp" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <ClInclude Include="..\engine.h" />
 | 
			
		||||
    <ClInclude Include="..\entity.h" />
 | 
			
		||||
    <ClInclude Include="..\gpglobals.h" />
 | 
			
		||||
    <ClInclude Include="..\svn_version.h" />
 | 
			
		||||
    <ClInclude Include="..\sdk\moduleconfig.h" />
 | 
			
		||||
    <ClInclude Include="..\sdk\CString.h" />
 | 
			
		||||
    <ClInclude Include="..\sdk\CVector.h" />
 | 
			
		||||
    <ClInclude Include="..\sdk\amxxmodule.h" />
 | 
			
		||||
    <ClInclude Include="..\moduleconfig.h" />
 | 
			
		||||
    <ClInclude Include="..\..\..\public\sdk\amxxmodule.h" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <None Include="..\..\..\plugins\include\engine.inc" />
 | 
			
		||||
 
 | 
			
		||||
@@ -12,9 +12,6 @@
 | 
			
		||||
    <Filter Include="Module SDK">
 | 
			
		||||
      <UniqueIdentifier>{fb945ae1-3977-41e3-a51b-04242aff8c78}</UniqueIdentifier>
 | 
			
		||||
    </Filter>
 | 
			
		||||
    <Filter Include="Module SDK\AMXX STL">
 | 
			
		||||
      <UniqueIdentifier>{a7c79424-2a0f-459d-a4f9-0ccbeb06dd3e}</UniqueIdentifier>
 | 
			
		||||
    </Filter>
 | 
			
		||||
    <Filter Include="Module SDK\SDK Base">
 | 
			
		||||
      <UniqueIdentifier>{aad49737-4d0e-4276-a471-dc77365bf9e0}</UniqueIdentifier>
 | 
			
		||||
    </Filter>
 | 
			
		||||
@@ -38,7 +35,7 @@
 | 
			
		||||
    <ClCompile Include="..\globals.cpp">
 | 
			
		||||
      <Filter>Source Files</Filter>
 | 
			
		||||
    </ClCompile>
 | 
			
		||||
    <ClCompile Include="..\sdk\amxxmodule.cpp">
 | 
			
		||||
    <ClCompile Include="..\..\..\public\sdk\amxxmodule.cpp">
 | 
			
		||||
      <Filter>Module SDK\SDK Base</Filter>
 | 
			
		||||
    </ClCompile>
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
@@ -55,16 +52,10 @@
 | 
			
		||||
    <ClInclude Include="..\svn_version.h">
 | 
			
		||||
      <Filter>Header Files</Filter>
 | 
			
		||||
    </ClInclude>
 | 
			
		||||
    <ClInclude Include="..\sdk\moduleconfig.h">
 | 
			
		||||
    <ClInclude Include="..\moduleconfig.h">
 | 
			
		||||
      <Filter>Module SDK</Filter>
 | 
			
		||||
    </ClInclude>
 | 
			
		||||
    <ClInclude Include="..\sdk\CString.h">
 | 
			
		||||
      <Filter>Module SDK\AMXX STL</Filter>
 | 
			
		||||
    </ClInclude>
 | 
			
		||||
    <ClInclude Include="..\sdk\CVector.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>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,367 +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 _INCLUDE_CSTRING_H
 | 
			
		||||
#define _INCLUDE_CSTRING_H
 | 
			
		||||
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
//by David "BAILOPAN" Anderson
 | 
			
		||||
class String
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
	String() 
 | 
			
		||||
	{
 | 
			
		||||
		v = NULL;
 | 
			
		||||
		a_size = 0;
 | 
			
		||||
		//assign("");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	~String()
 | 
			
		||||
	{ 
 | 
			
		||||
		if (v) 
 | 
			
		||||
			delete [] v; 
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	String(const char *src) 
 | 
			
		||||
	{
 | 
			
		||||
		v = NULL; 
 | 
			
		||||
		a_size = 0;
 | 
			
		||||
		assign(src); 
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	const char * _fread(FILE *fp) 	 
 | 
			
		||||
	{ 	 
 | 
			
		||||
		Grow(512, false); 	 
 | 
			
		||||
		char *ret = fgets(v, 511, fp); 	 
 | 
			
		||||
		return ret; 	 
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	String(const String &src) 
 | 
			
		||||
	{
 | 
			
		||||
		v = NULL;
 | 
			
		||||
		a_size = 0;
 | 
			
		||||
		assign(src.c_str()); 
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	const char *c_str() { return v?v:""; }
 | 
			
		||||
 | 
			
		||||
	const char *c_str() const { return v?v:""; }
 | 
			
		||||
 | 
			
		||||
	void append(const char *t)
 | 
			
		||||
	{
 | 
			
		||||
		Grow(size() + strlen(t) + 1);
 | 
			
		||||
		strcat(v, t);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void append(const char c)
 | 
			
		||||
	{
 | 
			
		||||
		size_t len = size();
 | 
			
		||||
		Grow(len + 2);
 | 
			
		||||
		v[len] = c;
 | 
			
		||||
		v[len + 1] = '\0';
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void append(String &d)
 | 
			
		||||
	{
 | 
			
		||||
		append(d.c_str());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void assign(const String &src)
 | 
			
		||||
	{
 | 
			
		||||
		assign(src.c_str());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void assign(const char *d)
 | 
			
		||||
	{
 | 
			
		||||
		if (!d)
 | 
			
		||||
		{
 | 
			
		||||
			clear();
 | 
			
		||||
		} else {
 | 
			
		||||
			size_t len = strlen(d);
 | 
			
		||||
			Grow(len + 1, false);
 | 
			
		||||
			memcpy(v, d, len);
 | 
			
		||||
			v[len] = '\0';
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void clear()
 | 
			
		||||
	{
 | 
			
		||||
		if (v)
 | 
			
		||||
			v[0] = '\0';
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	int compare (const char *d) const
 | 
			
		||||
	{
 | 
			
		||||
		if (!v)
 | 
			
		||||
			return strcmp("", d);
 | 
			
		||||
		else
 | 
			
		||||
			return strcmp(v, d);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	//Added this for amxx inclusion
 | 
			
		||||
	bool empty()
 | 
			
		||||
	{
 | 
			
		||||
		if (!v)
 | 
			
		||||
			return true;
 | 
			
		||||
 | 
			
		||||
		if (v[0] == '\0')
 | 
			
		||||
			return true;
 | 
			
		||||
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	size_t size()
 | 
			
		||||
	{
 | 
			
		||||
		if (v)
 | 
			
		||||
			return strlen(v);
 | 
			
		||||
		else
 | 
			
		||||
			return 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	int find(const char c, int index = 0)
 | 
			
		||||
	{
 | 
			
		||||
		int len = static_cast<int>(size());
 | 
			
		||||
		if (len < 1)
 | 
			
		||||
			return npos;
 | 
			
		||||
		if (index >= len || index < 0)
 | 
			
		||||
			return npos;
 | 
			
		||||
		int i = 0;
 | 
			
		||||
		for (i=index; i<len; i++)
 | 
			
		||||
		{
 | 
			
		||||
			if (v[i] == c)
 | 
			
		||||
			{
 | 
			
		||||
				return i;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return npos;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	bool is_space(int c)
 | 
			
		||||
	{
 | 
			
		||||
		if (c == '\f' || c == '\n' ||
 | 
			
		||||
			c == '\t' || c == '\r' ||
 | 
			
		||||
			c == '\v' || c == ' ')
 | 
			
		||||
		{
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	void trim()
 | 
			
		||||
	{
 | 
			
		||||
		if (!v)
 | 
			
		||||
			return;
 | 
			
		||||
 | 
			
		||||
		unsigned int i = 0;
 | 
			
		||||
		unsigned int j = 0;
 | 
			
		||||
		size_t len = strlen(v);
 | 
			
		||||
 | 
			
		||||
		if (len == 1)
 | 
			
		||||
		{
 | 
			
		||||
			if (is_space(v[i]))
 | 
			
		||||
			{
 | 
			
		||||
				clear();
 | 
			
		||||
				return;
 | 
			
		||||
			} 
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		unsigned char c0 = v[0];
 | 
			
		||||
 | 
			
		||||
		if (is_space(c0))
 | 
			
		||||
		{
 | 
			
		||||
			for (i=0; i<len; i++)
 | 
			
		||||
			{
 | 
			
		||||
				if (!is_space(v[i]) || (is_space(v[i]) && ((unsigned char)i==len-1)))
 | 
			
		||||
				{
 | 
			
		||||
					erase(0, i);
 | 
			
		||||
					break;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		len = strlen(v);
 | 
			
		||||
 | 
			
		||||
		if (len < 1)
 | 
			
		||||
		{
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (is_space(v[len-1]))
 | 
			
		||||
		{
 | 
			
		||||
			for (i=len-1; i<len; i--)
 | 
			
		||||
			{
 | 
			
		||||
				if (!is_space(v[i])
 | 
			
		||||
					|| (is_space(v[i]) && i==0))
 | 
			
		||||
				{
 | 
			
		||||
					erase(i+1, j);
 | 
			
		||||
					break;
 | 
			
		||||
				}
 | 
			
		||||
				j++;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (len == 1)
 | 
			
		||||
		{
 | 
			
		||||
			if (is_space(v[0]))
 | 
			
		||||
			{
 | 
			
		||||
				clear();
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void erase(unsigned int start, int num = npos)
 | 
			
		||||
	{
 | 
			
		||||
		if (!v)
 | 
			
		||||
			return;
 | 
			
		||||
		unsigned int i = 0;
 | 
			
		||||
		size_t len = size();
 | 
			
		||||
		//check for bounds
 | 
			
		||||
		if (num == npos || start+num > len-start)
 | 
			
		||||
			num = len - start;
 | 
			
		||||
		//do the erasing
 | 
			
		||||
		bool copyflag = false;
 | 
			
		||||
		for (i=0; i<len; i++)
 | 
			
		||||
		{
 | 
			
		||||
			if (i>=start && i<start+num)
 | 
			
		||||
			{
 | 
			
		||||
				if (i+num < len)
 | 
			
		||||
				{	
 | 
			
		||||
					v[i] = v[i+num];
 | 
			
		||||
				} else {
 | 
			
		||||
					v[i] = 0;
 | 
			
		||||
				}
 | 
			
		||||
				copyflag = true;
 | 
			
		||||
			} else if (copyflag) {
 | 
			
		||||
				if (i+num < len)
 | 
			
		||||
				{
 | 
			
		||||
					v[i] = v[i+num];
 | 
			
		||||
				} else {
 | 
			
		||||
					v[i] = 0;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		len -= num;
 | 
			
		||||
		v[len] = 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	String substr(unsigned int index, int num = npos)
 | 
			
		||||
	{
 | 
			
		||||
		if (!v)
 | 
			
		||||
		{
 | 
			
		||||
			String b("");
 | 
			
		||||
			return b;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		String ns;
 | 
			
		||||
 | 
			
		||||
		size_t len = size();
 | 
			
		||||
 | 
			
		||||
		if (index >= len || !v)
 | 
			
		||||
			return ns;
 | 
			
		||||
		
 | 
			
		||||
		if (num == npos)
 | 
			
		||||
		{
 | 
			
		||||
			num = len - index;
 | 
			
		||||
		} else if (index+num >= len) {
 | 
			
		||||
			num = len - index;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		unsigned int i = 0;
 | 
			
		||||
		unsigned int nslen = num + 2;
 | 
			
		||||
 | 
			
		||||
		ns.Grow(nslen);
 | 
			
		||||
 | 
			
		||||
		for (i=index; i<index+num; i++)
 | 
			
		||||
			ns.append(v[i]);
 | 
			
		||||
 | 
			
		||||
		return ns;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void toLower()
 | 
			
		||||
	{
 | 
			
		||||
		if (!v)
 | 
			
		||||
			return;
 | 
			
		||||
		unsigned int i = 0;
 | 
			
		||||
		size_t len = strlen(v);
 | 
			
		||||
		for (i=0; i<len; i++)
 | 
			
		||||
		{
 | 
			
		||||
			if (v[i] >= 65 && v[i] <= 90)
 | 
			
		||||
				v[i] &= ~(1<<5);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	String & operator = (const String &src)
 | 
			
		||||
	{
 | 
			
		||||
		assign(src);
 | 
			
		||||
		return *this;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	String & operator = (const char *src)
 | 
			
		||||
	{
 | 
			
		||||
		assign(src);
 | 
			
		||||
		return *this;
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	char operator [] (unsigned int index)
 | 
			
		||||
	{
 | 
			
		||||
		if (index > size() || !v)
 | 
			
		||||
		{
 | 
			
		||||
			return -1;
 | 
			
		||||
		} else {
 | 
			
		||||
			return v[index];
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	int at(int a)
 | 
			
		||||
	{
 | 
			
		||||
		if (a < 0 || a >= (int)size() || !v)
 | 
			
		||||
			return -1;
 | 
			
		||||
 | 
			
		||||
		return v[a];
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	bool at(int at, char c)
 | 
			
		||||
	{
 | 
			
		||||
		if (at < 0 || at >= (int)size() || !v)
 | 
			
		||||
			return false;
 | 
			
		||||
 | 
			
		||||
		v[at] = c;
 | 
			
		||||
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	void Grow(unsigned int d, bool copy=true)
 | 
			
		||||
	{
 | 
			
		||||
		if (d <= a_size)
 | 
			
		||||
			return;
 | 
			
		||||
		char *n = new char[d + 1];
 | 
			
		||||
		if (copy && v)
 | 
			
		||||
			strcpy(n, v);
 | 
			
		||||
		if (v)
 | 
			
		||||
			delete [] v;
 | 
			
		||||
		else
 | 
			
		||||
			strcpy(n, "");			
 | 
			
		||||
		v = n;
 | 
			
		||||
		a_size = d + 1;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	char *v;
 | 
			
		||||
	unsigned int a_size;
 | 
			
		||||
public:
 | 
			
		||||
	static const int npos = -1;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif //_INCLUDE_CSTRING_H
 | 
			
		||||
@@ -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
											
										
									
								
							
		Reference in New Issue
	
	Block a user