From 2e247acdadaa6eb8d5a9f5a5e90399c648a9f1f7 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 22 Aug 2004 17:57:23 +0000 Subject: [PATCH] Updates --- dlls/pgsql/CString.h | 339 ++--------------------------------------- dlls/pgsql/CVector.h | 14 +- dlls/pgsql/pgsql_amx.h | 2 +- 3 files changed, 21 insertions(+), 334 deletions(-) diff --git a/dlls/pgsql/CString.h b/dlls/pgsql/CString.h index 9b14deef..c5e315bc 100755 --- a/dlls/pgsql/CString.h +++ b/dlls/pgsql/CString.h @@ -1,99 +1,26 @@ -/* AMX Mod X -* -* by the AMX Mod X Development Team -* originally developed by OLO -* -* -* This program is free software; you can redistribute it and/or modify it -* under the terms of the GNU General Public License as published by the -* Free Software Foundation; either version 2 of the License, or (at -* your option) any later version. -* -* This program is distributed in the hope that it will be useful, but -* WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software Foundation, -* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* In addition, as a special exception, the author gives permission to -* link the code of this program with the Half-Life Game Engine ("HL -* Engine") and Modified Game Libraries ("MODs") developed by Valve, -* L.L.C ("Valve"). You must obey the GNU General Public License in all -* respects for all of the code used other than the HL Engine and MODs -* from Valve. If you modify this file, you may extend this exception -* to your version of the file, but you are not obligated to do so. If -* you do not wish to do so, delete this exception statement from your -* version. -*/ - #ifndef _INCLUDE_CSTRING_H #define _INCLUDE_CSTRING_H //by David "BAILOPAN" Anderson -class String +class CString { public: - String() - { - v = NULL; - mSize = 0; - cSize = 0; - Grow(2); - assign(""); - } - - ~String() - { - if (v) - delete [] v; - } - - String(const char *src) - { - v = NULL; - mSize = 0; - cSize = 0; assign(src); - } - - String(String &src) - { - v = NULL; - mSize = 0; - cSize = 0; - assign(src.c_str()); - } + CString() { v = NULL; mSize = 0; } + ~CString() { if (v) delete [] v; } const char *c_str() { return v?v:""; } - const char *c_str() const { return v?v:""; } void append(const char *t) { - Grow(cSize + strlen(t)); + Grow(strlen(v) + strlen(t)); strcat(v, t); - cSize = strlen(v); } - void append(const char c) - { - Grow(cSize + 2); - v[cSize] = c; - v[++cSize] = 0; - } - - void append(String &d) + void append(CString &d) { const char *t = d.c_str(); - Grow(cSize + strlen(t)); + Grow(strlen(v) + strlen(t)); strcat(v, t); - cSize = strlen(v); - } - - void assign(const String &src) - { - assign(src.c_str()); } void assign(const char *d) @@ -101,27 +28,20 @@ public: if (!d) { Grow(1); - cSize = 0; strcpy(v, ""); return; } Grow(strlen(d)); if (v) - { strcpy(v, d); - cSize = strlen(v); - } else { - cSize = 0; - } } void clear() { if (v) - { - v[0] = 0; - cSize = 0; - } + delete [] v; + v = NULL; + mSize = 0; } int compare (const char *d) @@ -141,252 +61,24 @@ public: } } - //Added this for amxx inclusion - bool empty() - { - if (!v || !cSize) - return true; - - return false; - } - int size() { if (!v) return 0; - return cSize; - } - - const char * _fread(FILE *fp) - { - Grow(512); - char * ret = fgets(v, 511, fp); - cSize = strlen(v); - return ret; - } - - int find(const char c, int index = 0) - { - if (!v) - return npos; - if (index >= (int)cSize || index < 0) - return npos; - unsigned int i = 0; - for (i=index; i=0; i--) - { - if (!is_space(v[i]) - || (is_space(v[i]) && i==0)) - { - erase(i+1, j); - break; - } - j++; - } - } - - if (cSize == 1) - { - if (is_space(v[0])) - { - clear(); - return; - } - } - } - - String & erase(unsigned int start, int num = npos) - { - if (!v) - return (*this); - unsigned int i = 0; - //check for bounds - if (num == npos || start+num > cSize-num+1) - num = cSize - start; - //do the erasing - bool copyflag = false; - for (i=0; i=start && i= cSize || !v) - return ns; - - if (num == npos) - { - num = cSize - index; - } else if (index+num >= cSize) { - num = cSize - index; - } - - unsigned int i = 0, j=0; - char *s = new char[cSize+1]; - - for (i=index; i= 65 && v[i] <= 90) - v[i] |= 32; - } - } - - 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 > cSize) - { - return -1; - } else { - return v[index]; - } - } - - int at(int a) - { - if (at < 0 || at >= (int)cSize) - return -1; - - return v[a]; - } - - bool at(int at, char c) - { - if (at < 0 || at >= (int)cSize) - return false; - - v[at] = c; - - return true; + return strlen(v); } private: - void Grow(unsigned int d) + void Grow(int d) { if (d<1) return; if (d > mSize) { - mSize = d + 16; // allocate a buffer char *t = new char[d+1]; if (v) { strcpy(t, v); - t[cSize] = 0; + t[strlen(v)] = 0; delete [] v; } v = t; @@ -395,10 +87,7 @@ private: } char *v; - unsigned int mSize; - unsigned int cSize; -public: - static const int npos = -1; + int mSize; }; -#endif //_INCLUDE_CSTRING_H +#endif //_INCLUDE_CSTRING_H \ No newline at end of file diff --git a/dlls/pgsql/CVector.h b/dlls/pgsql/CVector.h index ae05c66a..79fd9d8c 100755 --- a/dlls/pgsql/CVector.h +++ b/dlls/pgsql/CVector.h @@ -76,7 +76,7 @@ template class CVector delete [] m_Data; } if (m_Size < size) - m_CurrentSize = size; + m_CurrentUsedSize = size; m_Data = newData; m_Size = size; return true; @@ -90,7 +90,6 @@ protected: T *m_Data; size_t m_Size; size_t m_CurrentUsedSize; - size_t m_CurrentSize; public: class iterator { @@ -331,7 +330,7 @@ public: { if (pos > m_CurrentUsedSize) { - ASSERT(0); +// ASSERT(0); } return m_Data[pos]; } @@ -340,7 +339,7 @@ public: { if (pos > m_CurrentUsedSize) { - ASSERT(0); +// ASSERT(0); } return m_Data[pos]; } @@ -398,7 +397,7 @@ public: if (where != m_Data) --where; // validate iter - if (where < m_Data || where >= (m_Data + m_CurrentUsedSize)) + if (where < m_Data || where >= (m_Data + m_CurrentSize)) return false; ++m_CurrentUsedSize; @@ -416,7 +415,7 @@ public: void erase(iterator where) { // validate iter - if (where < m_Data || where >= (m_Data + m_CurrentUsedSize)) + if (where < m_Data || where >= (m_Data + m_CurrentSize)) return false; if (m_CurrentUsedSize > 1) @@ -438,5 +437,4 @@ public: } }; -#endif // __CVECTOR_H__ - +#endif // __CVECTOR_H__ \ No newline at end of file diff --git a/dlls/pgsql/pgsql_amx.h b/dlls/pgsql/pgsql_amx.h index 83427e93..17609ddc 100755 --- a/dlls/pgsql/pgsql_amx.h +++ b/dlls/pgsql/pgsql_amx.h @@ -1,7 +1,7 @@ #include #include #include -#include +#include "libpq-fe.h" #include "CVector.h" #include "CString.h" #include "amxxmodule.h"