1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/sourcehook/sh_list.h Fri Aug 12 17:44:53 2005 +0000
1.3 @@ -0,0 +1,247 @@
1.4 +/* ======== SourceMM ========
1.5 +* Copyright (C) 2004-2005 Metamod:Source Development Team
1.6 +* No warranties of any kind
1.7 +*
1.8 +* License: zlib/libpng
1.9 +*
1.10 +* Author(s): David "BAILOPAN" Anderson
1.11 +* ============================
1.12 +*/
1.13 +
1.14 +#ifndef _INCLUDE_SMM_LIST_H
1.15 +#define _INCLUDE_SMM_LIST_H
1.16 +
1.17 +namespace SourceHook
1.18 +{
1.19 +//This class is from CSDM_amxx by BAILOPAN
1.20 +//
1.21 +template <class T>
1.22 +class List
1.23 +{
1.24 +public:
1.25 + class iterator;
1.26 + friend class iterator;
1.27 + class ListNode
1.28 + {
1.29 + public:
1.30 + ListNode(const T & o) : obj(o) { };
1.31 + ListNode() { };
1.32 + T obj;
1.33 + ListNode *next;
1.34 + ListNode *prev;
1.35 + };
1.36 +private:
1.37 + ListNode *_Initialize()
1.38 + {
1.39 + ListNode *n = (ListNode *)malloc(sizeof(ListNode));
1.40 + n->next = NULL;
1.41 + n->prev = NULL;
1.42 + return n;
1.43 + }
1.44 +public:
1.45 + List() : m_Head(_Initialize()), m_Size(0)
1.46 + {
1.47 + }
1.48 + List(const List &src) : m_Head(_Initialize()), m_Size(0)
1.49 + {
1.50 + iterator iter;
1.51 + for (iter=src.begin(); iter!=src.end(); iter++)
1.52 + push_back( (*iter) );
1.53 + }
1.54 + ~List()
1.55 + {
1.56 + clear();
1.57 + if (m_Head)
1.58 + {
1.59 + free(m_Head);
1.60 + m_Head = NULL;
1.61 + }
1.62 + }
1.63 + void push_back(const T &obj)
1.64 + {
1.65 + ListNode *node = new ListNode(obj);
1.66 +
1.67 + if (!m_Head->prev)
1.68 + {
1.69 + //link in the node as the first item
1.70 + node->next = m_Head;
1.71 + node->prev = m_Head;
1.72 + m_Head->prev = node;
1.73 + m_Head->next = node;
1.74 + } else {
1.75 + node->prev = m_Head->prev;
1.76 + node->next = m_Head;
1.77 + m_Head->prev->next = node;
1.78 + m_Head->prev = node;
1.79 + }
1.80 + m_Size++;
1.81 + }
1.82 + size_t size()
1.83 + {
1.84 + return m_Size;
1.85 + }
1.86 + void clear()
1.87 + {
1.88 + ListNode *node = m_Head->next;
1.89 + ListNode *temp;
1.90 + m_Head->next = NULL;
1.91 + m_Head->prev = NULL;
1.92 + while (node && node != m_Head)
1.93 + {
1.94 + temp = node->next;
1.95 + delete node;
1.96 + node = temp;
1.97 + }
1.98 + m_Size = 0;
1.99 + }
1.100 + bool empty()
1.101 + {
1.102 + return (m_Head->next == NULL);
1.103 + }
1.104 + T & back()
1.105 + {
1.106 + return m_Head->prev->obj;
1.107 + }
1.108 +private:
1.109 + ListNode *m_Head;
1.110 + size_t m_Size;
1.111 +public:
1.112 + class iterator
1.113 + {
1.114 + friend class List;
1.115 + public:
1.116 + iterator()
1.117 + {
1.118 + m_This = NULL;
1.119 + }
1.120 + iterator(const List &src)
1.121 + {
1.122 + m_This = src.m_Head;
1.123 + }
1.124 + iterator(ListNode *n) : m_This(n)
1.125 + {
1.126 + }
1.127 + iterator(const iterator &where)
1.128 + {
1.129 + m_This = where.m_This;
1.130 + }
1.131 + iterator & operator--()
1.132 + {
1.133 + if (m_This)
1.134 + m_This = m_This->prev;
1.135 + return *this;
1.136 + }
1.137 + //pre increment
1.138 + iterator & operator++()
1.139 + {
1.140 + if (m_This)
1.141 + m_This = m_This->next;
1.142 + return *this;
1.143 + }
1.144 + iterator operator++(int)
1.145 + {
1.146 + iterator old(*this);
1.147 + if (m_This)
1.148 + m_This = m_This->next;
1.149 + return old;
1.150 + }
1.151 + T & operator * () const
1.152 + {
1.153 + return m_This->obj;
1.154 + }
1.155 + T & operator * ()
1.156 + {
1.157 + return m_This->obj;
1.158 + }
1.159 + T * operator -> () const
1.160 + {
1.161 + return &(m_This->obj);
1.162 + }
1.163 + bool operator != (iterator &where)
1.164 + {
1.165 + return (m_This != where.m_This);
1.166 + }
1.167 + bool operator ==(iterator &where)
1.168 + {
1.169 + return (m_This == where.m_This);
1.170 + }
1.171 + private:
1.172 + ListNode *m_This;
1.173 + };
1.174 +public:
1.175 + iterator begin() const
1.176 + {
1.177 + if (m_Size)
1.178 + return iterator(m_Head->next);
1.179 + else
1.180 + return iterator(m_Head);
1.181 + }
1.182 + iterator end() const
1.183 + {
1.184 + return iterator(m_Head);
1.185 + }
1.186 + iterator erase(iterator &where)
1.187 + {
1.188 + ListNode *pNode = where.m_This;
1.189 + iterator iter(where);
1.190 + iter++;
1.191 +
1.192 + //If we are both the head and tail...
1.193 + if (m_Head->next == pNode && m_Head->prev == pNode)
1.194 + {
1.195 + m_Head->next = NULL;
1.196 + m_Head->prev = NULL;
1.197 + } else if (m_Head->next == pNode) {
1.198 + //we are only the first
1.199 + pNode->next->prev = m_Head;
1.200 + m_Head->next = pNode->next;
1.201 + } else if (m_Head->prev == pNode) {
1.202 + //we are the tail
1.203 + pNode->prev->next = m_Head;
1.204 + m_Head->prev = pNode->prev;
1.205 + } else {
1.206 + //middle unlink
1.207 + pNode->prev->next = pNode->next;
1.208 + pNode->next->prev = pNode->prev;
1.209 + }
1.210 +
1.211 + delete pNode;
1.212 + m_Size--;
1.213 +
1.214 + return iter;
1.215 + }
1.216 +public:
1.217 + void remove(const T & obj)
1.218 + {
1.219 + iterator b;
1.220 + for (b=begin(); b!=end(); b++)
1.221 + {
1.222 + if ( (*b) == obj )
1.223 + {
1.224 + erase( b );
1.225 + break;
1.226 + }
1.227 + }
1.228 + }
1.229 + template <typename U>
1.230 + iterator find(const U & equ)
1.231 + {
1.232 + iterator iter;
1.233 + for (iter=begin(); iter!=end(); iter++)
1.234 + {
1.235 + if ( (*iter) == equ )
1.236 + return iter;
1.237 + }
1.238 + return end();
1.239 + }
1.240 + List & operator =(List &src)
1.241 + {
1.242 + iterator iter;
1.243 + for (iter=src.begin(); iter!=src.end(); iter++)
1.244 + push_back( (*iter) );
1.245 + return *this;
1.246 + }
1.247 +};
1.248 +}; //NAMESPACE
1.249 +
1.250 +#endif //_INCLUDE_CSDM_LIST_H
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/sourcehook/sh_string.h Fri Aug 12 17:44:53 2005 +0000
2.3 @@ -0,0 +1,369 @@
2.4 +/* ======== SourceMM ========
2.5 +* Copyright (C) 2004-2005 Metamod:Source Development Team
2.6 +* No warranties of any kind
2.7 +*
2.8 +* License: zlib/libpng
2.9 +*
2.10 +* Author(s): David "BAILOPAN" Anderson
2.11 +* ============================
2.12 +*/
2.13 +
2.14 +/* AMX Mod X
2.15 + *
2.16 + * by the AMX Mod X Development Team
2.17 + * originally developed by OLO
2.18 + */
2.19 +
2.20 +#ifndef _INCLUDE_CSTRING_H
2.21 +#define _INCLUDE_CSTRING_H
2.22 +
2.23 +#include <string.h>
2.24 +#include <stdio.h>
2.25 +
2.26 +namespace SourceHook
2.27 +{
2.28 +
2.29 +class String
2.30 +{
2.31 +public:
2.32 + String()
2.33 + {
2.34 + v = NULL;
2.35 + a_size = 0;
2.36 + //assign("");
2.37 + }
2.38 +
2.39 + ~String()
2.40 + {
2.41 + if (v)
2.42 + delete [] v;
2.43 + }
2.44 +
2.45 + String(const char *src)
2.46 + {
2.47 + v = NULL;
2.48 + a_size = 0;
2.49 + assign(src);
2.50 + }
2.51 +
2.52 + String(String &src)
2.53 + {
2.54 + v = NULL;
2.55 + a_size = 0;
2.56 + assign(src.c_str());
2.57 + }
2.58 +
2.59 + const char *c_str() { return v?v:""; }
2.60 +
2.61 + const char *c_str() const { return v?v:""; }
2.62 +
2.63 + void append(const char *t)
2.64 + {
2.65 + Grow(size() + strlen(t) + 1);
2.66 + strcat(v, t);
2.67 + }
2.68 +
2.69 + void append(const char c)
2.70 + {
2.71 + size_t len = size();
2.72 + Grow(len + 2);
2.73 + v[len] = c;
2.74 + v[len + 1] = '\0';
2.75 + }
2.76 +
2.77 + void append(String &d)
2.78 + {
2.79 + append(d.c_str());
2.80 + }
2.81 +
2.82 + void assign(const String &src)
2.83 + {
2.84 + assign(src.c_str());
2.85 + }
2.86 +
2.87 + void assign(const char *d)
2.88 + {
2.89 + if (!d)
2.90 + {
2.91 + clear();
2.92 + } else {
2.93 + Grow(strlen(d) + 1, false);
2.94 + strcpy(v, d);
2.95 + }
2.96 + }
2.97 +
2.98 + void clear()
2.99 + {
2.100 + if (v)
2.101 + v[0] = '\0';
2.102 + }
2.103 +
2.104 + int compare (const char *d)
2.105 + {
2.106 + if (!v)
2.107 + return strcmp("", d);
2.108 + else
2.109 + return strcmp(v, d);
2.110 + }
2.111 +
2.112 + //Added this for amxx inclusion
2.113 + bool empty()
2.114 + {
2.115 + if (!v)
2.116 + return true;
2.117 +
2.118 + if (v[0] == '\0')
2.119 + return true;
2.120 +
2.121 + return false;
2.122 + }
2.123 +
2.124 + size_t size()
2.125 + {
2.126 + if (v)
2.127 + return strlen(v);
2.128 + else
2.129 + return 0;
2.130 + }
2.131 +
2.132 + int find(const char c, int index = 0)
2.133 + {
2.134 + size_t len = size();
2.135 + if (len < 1)
2.136 + return npos;
2.137 + if (index >= (int)len || index < 0)
2.138 + return npos;
2.139 + unsigned int i = 0;
2.140 + for (i=index; i<(int)len; i++)
2.141 + {
2.142 + if (v[i] == c)
2.143 + {
2.144 + return i;
2.145 + }
2.146 + }
2.147 +
2.148 + return npos;
2.149 + }
2.150 +
2.151 + bool is_space(int c)
2.152 + {
2.153 + if (c == '\f' || c == '\n' ||
2.154 + c == '\t' || c == '\r' ||
2.155 + c == '\v' || c == ' ')
2.156 + {
2.157 + return true;
2.158 + }
2.159 +
2.160 + return false;
2.161 + }
2.162 +
2.163 + void trim()
2.164 + {
2.165 + if (!v)
2.166 + return;
2.167 +
2.168 + unsigned int i = 0;
2.169 + unsigned int j = 0;
2.170 + size_t len = strlen(v);
2.171 +
2.172 + if (len == 1)
2.173 + {
2.174 + if (is_space(v[i]))
2.175 + {
2.176 + clear();
2.177 + return;
2.178 + }
2.179 + }
2.180 +
2.181 + unsigned char c0 = v[0];
2.182 +
2.183 + if (is_space(c0))
2.184 + {
2.185 + for (i=0; i<len; i++)
2.186 + {
2.187 + if (!is_space(v[i]) || (is_space(v[i]) && ((unsigned char)i==len-1)))
2.188 + {
2.189 + erase(0, i);
2.190 + break;
2.191 + }
2.192 + }
2.193 + }
2.194 +
2.195 + len = strlen(v);
2.196 +
2.197 + if (len < 1)
2.198 + {
2.199 + return;
2.200 + }
2.201 +
2.202 + if (is_space(v[len-1]))
2.203 + {
2.204 + for (i=len-1; i>=0; i--)
2.205 + {
2.206 + if (!is_space(v[i])
2.207 + || (is_space(v[i]) && i==0))
2.208 + {
2.209 + erase(i+1, j);
2.210 + break;
2.211 + }
2.212 + j++;
2.213 + }
2.214 + }
2.215 +
2.216 + if (len == 1)
2.217 + {
2.218 + if (is_space(v[0]))
2.219 + {
2.220 + clear();
2.221 + return;
2.222 + }
2.223 + }
2.224 + }
2.225 +
2.226 + void erase(unsigned int start, int num = npos)
2.227 + {
2.228 + if (!v)
2.229 + return;
2.230 + unsigned int i = 0;
2.231 + size_t len = size();
2.232 + //check for bounds
2.233 + if (num == npos || start+num > len-num+1)
2.234 + num = len - start;
2.235 + //do the erasing
2.236 + bool copyflag = false;
2.237 + for (i=0; i<len; i++)
2.238 + {
2.239 + if (i>=start && i<start+num)
2.240 + {
2.241 + if (i+num < len)
2.242 + {
2.243 + v[i] = v[i+num];
2.244 + } else {
2.245 + v[i] = 0;
2.246 + }
2.247 + copyflag = true;
2.248 + } else if (copyflag) {
2.249 + if (i+num < len)
2.250 + {
2.251 + v[i] = v[i+num];
2.252 + } else {
2.253 + v[i] = 0;
2.254 + }
2.255 + }
2.256 + }
2.257 + len -= num;
2.258 + v[len] = 0;
2.259 + }
2.260 +
2.261 + String substr(unsigned int index, int num = npos)
2.262 + {
2.263 + if (!v)
2.264 + {
2.265 + String b("");
2.266 + return b;
2.267 + }
2.268 +
2.269 + String ns;
2.270 +
2.271 + size_t len = size();
2.272 +
2.273 + if (index >= len || !v)
2.274 + return ns;
2.275 +
2.276 + if (num == npos)
2.277 + {
2.278 + num = len - index;
2.279 + } else if (index+num >= len) {
2.280 + num = len - index;
2.281 + }
2.282 +
2.283 + unsigned int i = 0, j=0;
2.284 + unsigned int nslen = num + 2;
2.285 +
2.286 + ns.Grow(nslen);
2.287 +
2.288 + for (i=index; i<index+num; i++)
2.289 + ns.append(v[i]);
2.290 +
2.291 + return ns;
2.292 + }
2.293 +
2.294 + void toLower()
2.295 + {
2.296 + if (!v)
2.297 + return;
2.298 + unsigned int i = 0;
2.299 + size_t len = strlen(v);
2.300 + for (i=0; i<len; i++)
2.301 + {
2.302 + if (v[i] >= 65 && v[i] <= 90)
2.303 + v[i] &= ~(1<<5);
2.304 + }
2.305 + }
2.306 +
2.307 + String & operator = (const String &src)
2.308 + {
2.309 + assign(src);
2.310 + return *this;
2.311 + }
2.312 +
2.313 + String & operator = (const char *src)
2.314 + {
2.315 + assign(src);
2.316 + return *this;
2.317 +
2.318 + }
2.319 +
2.320 + char operator [] (unsigned int index)
2.321 + {
2.322 + if (index > size() || !v)
2.323 + {
2.324 + return -1;
2.325 + } else {
2.326 + return v[index];
2.327 + }
2.328 + }
2.329 +
2.330 + int at(int a)
2.331 + {
2.332 + if (a < 0 || a >= (int)size() || !v)
2.333 + return -1;
2.334 +
2.335 + return v[a];
2.336 + }
2.337 +
2.338 + bool at(int at, char c)
2.339 + {
2.340 + if (at < 0 || at >= (int)size() || !v)
2.341 + return false;
2.342 +
2.343 + v[at] = c;
2.344 +
2.345 + return true;
2.346 + }
2.347 +
2.348 +private:
2.349 + void Grow(unsigned int d, bool copy=true)
2.350 + {
2.351 + if (d <= a_size)
2.352 + return;
2.353 + char *n = new char[d + 1];
2.354 + if (copy && v)
2.355 + strcpy(n, v);
2.356 + if (v)
2.357 + delete [] v;
2.358 + else
2.359 + strcpy(n, "");
2.360 + v = n;
2.361 + a_size = d + 1;
2.362 + }
2.363 +
2.364 + char *v;
2.365 + unsigned int a_size;
2.366 +public:
2.367 + static const int npos = -1;
2.368 +};
2.369 +
2.370 +}; //NAMESPACE
2.371 +
2.372 +#endif //_INCLUDE_CSTRING_H
3.1 --- a/sourcehook/smm_list.h Fri Aug 12 17:33:59 2005 +0000
3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
3.3 @@ -1,244 +0,0 @@
3.4 -/* ======== SourceMM ========
3.5 -* Copyright (C) 2004-2005 Metamod:Source Development Team
3.6 -* No warranties of any kind
3.7 -*
3.8 -* License: zlib/libpng
3.9 -*
3.10 -* Author(s): David "BAILOPAN" Anderson
3.11 -* ============================
3.12 -*/
3.13 -
3.14 -#ifndef _INCLUDE_SMM_LIST_H
3.15 -#define _INCLUDE_SMM_LIST_H
3.16 -
3.17 -//This class is from CSDM_amxx by BAILOPAN
3.18 -//
3.19 -template <class T>
3.20 -class List
3.21 -{
3.22 -public:
3.23 - class iterator;
3.24 - friend class iterator;
3.25 - class ListNode
3.26 - {
3.27 - public:
3.28 - ListNode(const T & o) : obj(o) { };
3.29 - ListNode() { };
3.30 - T obj;
3.31 - ListNode *next;
3.32 - ListNode *prev;
3.33 - };
3.34 -private:
3.35 - ListNode *_Initialize()
3.36 - {
3.37 - ListNode *n = (ListNode *)malloc(sizeof(ListNode));
3.38 - n->next = NULL;
3.39 - n->prev = NULL;
3.40 - return n;
3.41 - }
3.42 -public:
3.43 - List() : m_Head(_Initialize()), m_Size(0)
3.44 - {
3.45 - }
3.46 - List(const List &src) : m_Head(_Initialize()), m_Size(0)
3.47 - {
3.48 - iterator iter;
3.49 - for (iter=src.begin(); iter!=src.end(); iter++)
3.50 - push_back( (*iter) );
3.51 - }
3.52 - ~List()
3.53 - {
3.54 - clear();
3.55 - if (m_Head)
3.56 - {
3.57 - free(m_Head);
3.58 - m_Head = NULL;
3.59 - }
3.60 - }
3.61 - void push_back(const T &obj)
3.62 - {
3.63 - ListNode *node = new ListNode(obj);
3.64 -
3.65 - if (!m_Head->prev)
3.66 - {
3.67 - //link in the node as the first item
3.68 - node->next = m_Head;
3.69 - node->prev = m_Head;
3.70 - m_Head->prev = node;
3.71 - m_Head->next = node;
3.72 - } else {
3.73 - node->prev = m_Head->prev;
3.74 - node->next = m_Head;
3.75 - m_Head->prev->next = node;
3.76 - m_Head->prev = node;
3.77 - }
3.78 - m_Size++;
3.79 - }
3.80 - size_t size()
3.81 - {
3.82 - return m_Size;
3.83 - }
3.84 - void clear()
3.85 - {
3.86 - ListNode *node = m_Head->next;
3.87 - ListNode *temp;
3.88 - m_Head->next = NULL;
3.89 - m_Head->prev = NULL;
3.90 - while (node && node != m_Head)
3.91 - {
3.92 - temp = node->next;
3.93 - delete node;
3.94 - node = temp;
3.95 - }
3.96 - m_Size = 0;
3.97 - }
3.98 - bool empty()
3.99 - {
3.100 - return (m_Head->next == NULL);
3.101 - }
3.102 - T & back()
3.103 - {
3.104 - return m_Head->prev->obj;
3.105 - }
3.106 -private:
3.107 - ListNode *m_Head;
3.108 - size_t m_Size;
3.109 -public:
3.110 - class iterator
3.111 - {
3.112 - friend class List;
3.113 - public:
3.114 - iterator()
3.115 - {
3.116 - m_This = NULL;
3.117 - }
3.118 - iterator(const List &src)
3.119 - {
3.120 - m_This = src.m_Head;
3.121 - }
3.122 - iterator(ListNode *n) : m_This(n)
3.123 - {
3.124 - }
3.125 - iterator(const iterator &where)
3.126 - {
3.127 - m_This = where.m_This;
3.128 - }
3.129 - iterator & operator--()
3.130 - {
3.131 - if (m_This)
3.132 - m_This = m_This->prev;
3.133 - return *this;
3.134 - }
3.135 - //pre increment
3.136 - iterator & operator++()
3.137 - {
3.138 - if (m_This)
3.139 - m_This = m_This->next;
3.140 - return *this;
3.141 - }
3.142 - iterator operator++(int)
3.143 - {
3.144 - iterator old(*this);
3.145 - if (m_This)
3.146 - m_This = m_This->next;
3.147 - return old;
3.148 - }
3.149 - T & operator * () const
3.150 - {
3.151 - return m_This->obj;
3.152 - }
3.153 - T & operator * ()
3.154 - {
3.155 - return m_This->obj;
3.156 - }
3.157 - T * operator -> () const
3.158 - {
3.159 - return &(m_This->obj);
3.160 - }
3.161 - bool operator != (iterator &where)
3.162 - {
3.163 - return (m_This != where.m_This);
3.164 - }
3.165 - bool operator ==(iterator &where)
3.166 - {
3.167 - return (m_This == where.m_This);
3.168 - }
3.169 - private:
3.170 - ListNode *m_This;
3.171 - };
3.172 -public:
3.173 - iterator begin() const
3.174 - {
3.175 - if (m_Size)
3.176 - return iterator(m_Head->next);
3.177 - else
3.178 - return iterator(m_Head);
3.179 - }
3.180 - iterator end() const
3.181 - {
3.182 - return iterator(m_Head);
3.183 - }
3.184 - iterator erase(iterator &where)
3.185 - {
3.186 - ListNode *pNode = where.m_This;
3.187 - iterator iter(where);
3.188 - iter++;
3.189 -
3.190 - //If we are both the head and tail...
3.191 - if (m_Head->next == pNode && m_Head->prev == pNode)
3.192 - {
3.193 - m_Head->next = NULL;
3.194 - m_Head->prev = NULL;
3.195 - } else if (m_Head->next == pNode) {
3.196 - //we are only the first
3.197 - pNode->next->prev = m_Head;
3.198 - m_Head->next = pNode->next;
3.199 - } else if (m_Head->prev == pNode) {
3.200 - //we are the tail
3.201 - pNode->prev->next = m_Head;
3.202 - m_Head->prev = pNode->prev;
3.203 - } else {
3.204 - //middle unlink
3.205 - pNode->prev->next = pNode->next;
3.206 - pNode->next->prev = pNode->prev;
3.207 - }
3.208 -
3.209 - delete pNode;
3.210 - m_Size--;
3.211 -
3.212 - return iter;
3.213 - }
3.214 -public:
3.215 - void remove(const T & obj)
3.216 - {
3.217 - iterator b;
3.218 - for (b=begin(); b!=end(); b++)
3.219 - {
3.220 - if ( (*b) == obj )
3.221 - {
3.222 - erase( b );
3.223 - break;
3.224 - }
3.225 - }
3.226 - }
3.227 - template <typename U>
3.228 - iterator find(const U & equ)
3.229 - {
3.230 - iterator iter;
3.231 - for (iter=begin(); iter!=end(); iter++)
3.232 - {
3.233 - if ( (*iter) == equ )
3.234 - return iter;
3.235 - }
3.236 - return end();
3.237 - }
3.238 - List & operator =(List &src)
3.239 - {
3.240 - iterator iter;
3.241 - for (iter=src.begin(); iter!=src.end(); iter++)
3.242 - push_back( (*iter) );
3.243 - return *this;
3.244 - }
3.245 -};
3.246 -
3.247 -#endif //_INCLUDE_CSDM_LIST_H
4.1 --- a/sourcehook/smm_string.h Fri Aug 12 17:33:59 2005 +0000
4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
4.3 @@ -1,364 +0,0 @@
4.4 -/* ======== SourceMM ========
4.5 -* Copyright (C) 2004-2005 Metamod:Source Development Team
4.6 -* No warranties of any kind
4.7 -*
4.8 -* License: zlib/libpng
4.9 -*
4.10 -* Author(s): David "BAILOPAN" Anderson
4.11 -* ============================
4.12 -*/
4.13 -
4.14 -/* AMX Mod X
4.15 - *
4.16 - * by the AMX Mod X Development Team
4.17 - * originally developed by OLO
4.18 - */
4.19 -
4.20 -#ifndef _INCLUDE_CSTRING_H
4.21 -#define _INCLUDE_CSTRING_H
4.22 -
4.23 -#include <string.h>
4.24 -#include <stdio.h>
4.25 -
4.26 -class String
4.27 -{
4.28 -public:
4.29 - String()
4.30 - {
4.31 - v = NULL;
4.32 - a_size = 0;
4.33 - //assign("");
4.34 - }
4.35 -
4.36 - ~String()
4.37 - {
4.38 - if (v)
4.39 - delete [] v;
4.40 - }
4.41 -
4.42 - String(const char *src)
4.43 - {
4.44 - v = NULL;
4.45 - a_size = 0;
4.46 - assign(src);
4.47 - }
4.48 -
4.49 - String(String &src)
4.50 - {
4.51 - v = NULL;
4.52 - a_size = 0;
4.53 - assign(src.c_str());
4.54 - }
4.55 -
4.56 - const char *c_str() { return v?v:""; }
4.57 -
4.58 - const char *c_str() const { return v?v:""; }
4.59 -
4.60 - void append(const char *t)
4.61 - {
4.62 - Grow(size() + strlen(t) + 1);
4.63 - strcat(v, t);
4.64 - }
4.65 -
4.66 - void append(const char c)
4.67 - {
4.68 - size_t len = size();
4.69 - Grow(len + 2);
4.70 - v[len] = c;
4.71 - v[len + 1] = '\0';
4.72 - }
4.73 -
4.74 - void append(String &d)
4.75 - {
4.76 - append(d.c_str());
4.77 - }
4.78 -
4.79 - void assign(const String &src)
4.80 - {
4.81 - assign(src.c_str());
4.82 - }
4.83 -
4.84 - void assign(const char *d)
4.85 - {
4.86 - if (!d)
4.87 - {
4.88 - clear();
4.89 - } else {
4.90 - Grow(strlen(d) + 1, false);
4.91 - strcpy(v, d);
4.92 - }
4.93 - }
4.94 -
4.95 - void clear()
4.96 - {
4.97 - if (v)
4.98 - v[0] = '\0';
4.99 - }
4.100 -
4.101 - int compare (const char *d)
4.102 - {
4.103 - if (!v)
4.104 - return strcmp("", d);
4.105 - else
4.106 - return strcmp(v, d);
4.107 - }
4.108 -
4.109 - //Added this for amxx inclusion
4.110 - bool empty()
4.111 - {
4.112 - if (!v)
4.113 - return true;
4.114 -
4.115 - if (v[0] == '\0')
4.116 - return true;
4.117 -
4.118 - return false;
4.119 - }
4.120 -
4.121 - size_t size()
4.122 - {
4.123 - if (v)
4.124 - return strlen(v);
4.125 - else
4.126 - return 0;
4.127 - }
4.128 -
4.129 - int find(const char c, int index = 0)
4.130 - {
4.131 - size_t len = size();
4.132 - if (len < 1)
4.133 - return npos;
4.134 - if (index >= (int)len || index < 0)
4.135 - return npos;
4.136 - unsigned int i = 0;
4.137 - for (i=index; i<(int)len; i++)
4.138 - {
4.139 - if (v[i] == c)
4.140 - {
4.141 - return i;
4.142 - }
4.143 - }
4.144 -
4.145 - return npos;
4.146 - }
4.147 -
4.148 - bool is_space(int c)
4.149 - {
4.150 - if (c == '\f' || c == '\n' ||
4.151 - c == '\t' || c == '\r' ||
4.152 - c == '\v' || c == ' ')
4.153 - {
4.154 - return true;
4.155 - }
4.156 -
4.157 - return false;
4.158 - }
4.159 -
4.160 - void trim()
4.161 - {
4.162 - if (!v)
4.163 - return;
4.164 -
4.165 - unsigned int i = 0;
4.166 - unsigned int j = 0;
4.167 - size_t len = strlen(v);
4.168 -
4.169 - if (len == 1)
4.170 - {
4.171 - if (is_space(v[i]))
4.172 - {
4.173 - clear();
4.174 - return;
4.175 - }
4.176 - }
4.177 -
4.178 - unsigned char c0 = v[0];
4.179 -
4.180 - if (is_space(c0))
4.181 - {
4.182 - for (i=0; i<len; i++)
4.183 - {
4.184 - if (!is_space(v[i]) || (is_space(v[i]) && ((unsigned char)i==len-1)))
4.185 - {
4.186 - erase(0, i);
4.187 - break;
4.188 - }
4.189 - }
4.190 - }
4.191 -
4.192 - len = strlen(v);
4.193 -
4.194 - if (len < 1)
4.195 - {
4.196 - return;
4.197 - }
4.198 -
4.199 - if (is_space(v[len-1]))
4.200 - {
4.201 - for (i=len-1; i>=0; i--)
4.202 - {
4.203 - if (!is_space(v[i])
4.204 - || (is_space(v[i]) && i==0))
4.205 - {
4.206 - erase(i+1, j);
4.207 - break;
4.208 - }
4.209 - j++;
4.210 - }
4.211 - }
4.212 -
4.213 - if (len == 1)
4.214 - {
4.215 - if (is_space(v[0]))
4.216 - {
4.217 - clear();
4.218 - return;
4.219 - }
4.220 - }
4.221 - }
4.222 -
4.223 - void erase(unsigned int start, int num = npos)
4.224 - {
4.225 - if (!v)
4.226 - return;
4.227 - unsigned int i = 0;
4.228 - size_t len = size();
4.229 - //check for bounds
4.230 - if (num == npos || start+num > len-num+1)
4.231 - num = len - start;
4.232 - //do the erasing
4.233 - bool copyflag = false;
4.234 - for (i=0; i<len; i++)
4.235 - {
4.236 - if (i>=start && i<start+num)
4.237 - {
4.238 - if (i+num < len)
4.239 - {
4.240 - v[i] = v[i+num];
4.241 - } else {
4.242 - v[i] = 0;
4.243 - }
4.244 - copyflag = true;
4.245 - } else if (copyflag) {
4.246 - if (i+num < len)
4.247 - {
4.248 - v[i] = v[i+num];
4.249 - } else {
4.250 - v[i] = 0;
4.251 - }
4.252 - }
4.253 - }
4.254 - len -= num;
4.255 - v[len] = 0;
4.256 - }
4.257 -
4.258 - String substr(unsigned int index, int num = npos)
4.259 - {
4.260 - if (!v)
4.261 - {
4.262 - String b("");
4.263 - return b;
4.264 - }
4.265 -
4.266 - String ns;
4.267 -
4.268 - size_t len = size();
4.269 -
4.270 - if (index >= len || !v)
4.271 - return ns;
4.272 -
4.273 - if (num == npos)
4.274 - {
4.275 - num = len - index;
4.276 - } else if (index+num >= len) {
4.277 - num = len - index;
4.278 - }
4.279 -
4.280 - unsigned int i = 0, j=0;
4.281 - unsigned int nslen = num + 2;
4.282 -
4.283 - ns.Grow(nslen);
4.284 -
4.285 - for (i=index; i<index+num; i++)
4.286 - ns.append(v[i]);
4.287 -
4.288 - return ns;
4.289 - }
4.290 -
4.291 - void toLower()
4.292 - {
4.293 - if (!v)
4.294 - return;
4.295 - unsigned int i = 0;
4.296 - size_t len = strlen(v);
4.297 - for (i=0; i<len; i++)
4.298 - {
4.299 - if (v[i] >= 65 && v[i] <= 90)
4.300 - v[i] &= ~(1<<5);
4.301 - }
4.302 - }
4.303 -
4.304 - String & operator = (const String &src)
4.305 - {
4.306 - assign(src);
4.307 - return *this;
4.308 - }
4.309 -
4.310 - String & operator = (const char *src)
4.311 - {
4.312 - assign(src);
4.313 - return *this;
4.314 -
4.315 - }
4.316 -
4.317 - char operator [] (unsigned int index)
4.318 - {
4.319 - if (index > size() || !v)
4.320 - {
4.321 - return -1;
4.322 - } else {
4.323 - return v[index];
4.324 - }
4.325 - }
4.326 -
4.327 - int at(int a)
4.328 - {
4.329 - if (a < 0 || a >= (int)size() || !v)
4.330 - return -1;
4.331 -
4.332 - return v[a];
4.333 - }
4.334 -
4.335 - bool at(int at, char c)
4.336 - {
4.337 - if (at < 0 || at >= (int)size() || !v)
4.338 - return false;
4.339 -
4.340 - v[at] = c;
4.341 -
4.342 - return true;
4.343 - }
4.344 -
4.345 -private:
4.346 - void Grow(unsigned int d, bool copy=true)
4.347 - {
4.348 - if (d <= a_size)
4.349 - return;
4.350 - char *n = new char[d + 1];
4.351 - if (copy && v)
4.352 - strcpy(n, v);
4.353 - if (v)
4.354 - delete [] v;
4.355 - else
4.356 - strcpy(n, "");
4.357 - v = n;
4.358 - a_size = d + 1;
4.359 - }
4.360 -
4.361 - char *v;
4.362 - unsigned int a_size;
4.363 -public:
4.364 - static const int npos = -1;
4.365 -};
4.366 -
4.367 -#endif //_INCLUDE_CSTRING_H
5.1 --- a/sourcehook/sourcehook.h Fri Aug 12 17:33:59 2005 +0000
5.2 +++ b/sourcehook/sourcehook.h Fri Aug 12 17:44:53 2005 +0000
5.3 @@ -68,7 +68,7 @@
5.4 #include "FastDelegate.h"
5.5 #include "sh_memfuncinfo.h"
5.6 #include "sh_memory.h"
5.7 -#include "smm_list.h"
5.8 +#include "sh_list.h"
5.9 #include <vector>
5.10 #include <map>
5.11
6.1 --- a/sourcehook/test/main.cpp Fri Aug 12 17:33:59 2005 +0000
6.2 +++ b/sourcehook/test/main.cpp Fri Aug 12 17:44:53 2005 +0000
6.3 @@ -6,7 +6,6 @@
6.4 #include <string>
6.5 #include <list>
6.6 #include "sourcehook_impl.h"
6.7 -#include "smm_list.h"
6.8
6.9 using namespace std;
6.10
7.1 --- a/sourcemm/CPlugin.cpp Fri Aug 12 17:33:59 2005 +0000
7.2 +++ b/sourcemm/CPlugin.cpp Fri Aug 12 17:44:53 2005 +0000
7.3 @@ -389,7 +389,7 @@
7.4 {
7.5 PluginIter i;
7.6
7.7 - List<SourceMM::CPluginManager::CPlugin *> remqueue;
7.8 + SourceHook::List<SourceMM::CPluginManager::CPlugin *> remqueue;
7.9
7.10 for (i=m_Plugins.begin(); i!=m_Plugins.end(); i++)
7.11 remqueue.push_back( (*i) );
7.12 @@ -476,7 +476,7 @@
7.13
7.14 void CPluginManager::UnregAllConCmds(CPlugin *pl)
7.15 {
7.16 - List<ConCommandBase *>::iterator i;
7.17 + SourceHook::List<ConCommandBase *>::iterator i;
7.18
7.19 for (i=pl->m_Cvars.begin(); i!=pl->m_Cvars.end(); i++)
7.20 g_SMConVarAccessor.Unregister( (*i) );
8.1 --- a/sourcemm/CPlugin.h Fri Aug 12 17:33:59 2005 +0000
8.2 +++ b/sourcemm/CPlugin.h Fri Aug 12 17:44:53 2005 +0000
8.3 @@ -21,8 +21,8 @@
8.4 #include <convar.h>
8.5 #include "IPluginManager.h"
8.6 #include "oslink.h"
8.7 -#include "smm_list.h"
8.8 -#include "smm_string.h"
8.9 +#include "sh_list.h"
8.10 +#include "sh_string.h"
8.11
8.12 /**
8.13 * History of plugin versions: (M=min, C=current)
8.14 @@ -54,14 +54,14 @@
8.15 CPlugin();
8.16 public:
8.17 PluginId m_Id;
8.18 - String m_File;
8.19 + SourceHook::String m_File;
8.20 Pl_Status m_Status;
8.21 PluginId m_Source;
8.22 ISmmPlugin *m_API;
8.23 HINSTANCE m_Lib;
8.24 factories fac_list;
8.25 - List<ConCommandBase *> m_Cvars;
8.26 - List<ConCommandBase *> m_Cmds;
8.27 + SourceHook::List<ConCommandBase *> m_Cvars;
8.28 + SourceHook::List<ConCommandBase *> m_Cmds;
8.29 };
8.30 public:
8.31 CPluginManager();
8.32 @@ -102,8 +102,8 @@
8.33 bool Retry(PluginId id, char *error, size_t len);
8.34
8.35 //Internal iterators
8.36 - List<SourceMM::CPluginManager::CPlugin *>::iterator _begin();
8.37 - List<SourceMM::CPluginManager::CPlugin *>::iterator _end();
8.38 + SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator _begin();
8.39 + SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator _end();
8.40 private:
8.41 //These are identical internal functions for the wrappers above.
8.42 CPlugin *_Load(const char *file, PluginId source, char *error, size_t maxlen);
8.43 @@ -113,12 +113,12 @@
8.44 void UnregAllConCmds(CPlugin *pl);
8.45 private:
8.46 PluginId m_LastId;
8.47 - List<CPlugin *> m_Plugins;
8.48 + SourceHook::List<CPlugin *> m_Plugins;
8.49 bool m_AllLoaded;
8.50 };
8.51 };
8.52
8.53 -typedef List<SourceMM::CPluginManager::CPlugin *>::iterator PluginIter;
8.54 +typedef SourceHook::List<SourceMM::CPluginManager::CPlugin *>::iterator PluginIter;
8.55
8.56 /** @brief Singleton for plugin manager */
8.57 extern SourceMM::CPluginManager g_PluginMngr;
9.1 --- a/sourcemm/concommands.cpp Fri Aug 12 17:33:59 2005 +0000
9.2 +++ b/sourcemm/concommands.cpp Fri Aug 12 17:44:53 2005 +0000
9.3 @@ -12,8 +12,8 @@
9.4 #include "CSmmAPI.h"
9.5 #include "concommands.h"
9.6 #include "CPlugin.h"
9.7 -#include "smm_string.h"
9.8 -#include "smm_list.h"
9.9 +#include "sh_string.h"
9.10 +#include "sh_list.h"
9.11
9.12 /**
9.13 * @brief Console Command Implementations
9.14 @@ -50,7 +50,7 @@
9.15
9.16 void SMConVarAccessor::MarkCommandsAsGameDLL()
9.17 {
9.18 - for (List<ConCommandBase*>::iterator iter = m_RegisteredCommands.begin();
9.19 + for (SourceHook::List<ConCommandBase*>::iterator iter = m_RegisteredCommands.begin();
9.20 iter != m_RegisteredCommands.end(); ++iter)
9.21 {
9.22 (*iter)->AddFlags(FCVAR_GAMEDLL);
9.23 @@ -203,7 +203,7 @@
9.24 CONMSG("Plugin %d is not loaded.\n", id);
9.25 } else {
9.26 CONMSG("Console commands for %s:\n", pl->m_API->GetName());
9.27 - List<ConCommandBase *>::iterator ci;
9.28 + SourceHook::List<ConCommandBase *>::iterator ci;
9.29 size_t count = 0;
9.30
9.31 for (ci=pl->m_Cmds.begin(); ci!=pl->m_Cmds.end(); ci++)
9.32 @@ -234,7 +234,7 @@
9.33 CONMSG("Plugin %d is not loaded.\n", id);
9.34 } else {
9.35 CONMSG("Registered cvars for %s:\n", pl->m_API->GetName());
9.36 - List<ConCommandBase *>::iterator ci;
9.37 + SourceHook::List<ConCommandBase *>::iterator ci;
9.38 size_t count = 0;
9.39
9.40 for (ci=pl->m_Cvars.begin(); ci!=pl->m_Cvars.end(); ci++)
10.1 --- a/sourcemm/concommands.h Fri Aug 12 17:33:59 2005 +0000
10.2 +++ b/sourcemm/concommands.h Fri Aug 12 17:44:53 2005 +0000
10.3 @@ -20,11 +20,11 @@
10.4 #include <eiface.h>
10.5 #include "sourcemm.h"
10.6 #include <convar.h>
10.7 -#include "smm_list.h"
10.8 +#include "sh_list.h"
10.9
10.10 class SMConVarAccessor : public IConCommandBaseAccessor
10.11 {
10.12 - List<ConCommandBase*> m_RegisteredCommands;
10.13 + SourceHook::List<ConCommandBase*> m_RegisteredCommands;
10.14 public:
10.15 virtual bool RegisterConCommandBase(ConCommandBase *pCommand);
10.16 bool Register(ConCommandBase *pCommand);
11.1 --- a/sourcemm/sourcemm.cpp Fri Aug 12 17:33:59 2005 +0000
11.2 +++ b/sourcemm/sourcemm.cpp Fri Aug 12 17:44:53 2005 +0000
11.3 @@ -34,8 +34,8 @@
11.4 EngineInfo g_Engine = {NULL, NULL, NULL, NULL};
11.5 SourceHook::CSourceHookImpl g_SourceHook;
11.6 SourceHook::ISourceHook *g_SHPtr;
11.7 -String g_ModPath;
11.8 -String g_BinPath;
11.9 +SourceHook::String g_ModPath;
11.10 +SourceHook::String g_BinPath;
11.11 PluginId g_PLID = Pl_Console; //Technically, SourceMM is the "Console" plugin... :p
11.12 bool bInShutdown = false;
11.13 bool bInFirstLevel = true;
12.1 --- a/sourcemm/sourcemm.h Fri Aug 12 17:33:59 2005 +0000
12.2 +++ b/sourcemm/sourcemm.h Fri Aug 12 17:44:53 2005 +0000
12.3 @@ -78,10 +78,10 @@
12.4 extern SourceHook::CSourceHookImpl g_SourceHook;
12.5
12.6 /** @brief Mod path (important!)*/
12.7 -extern String g_ModPath;
12.8 +extern SourceHook::String g_ModPath;
12.9
12.10 /** @brief Path to server binary */
12.11 -extern String g_BinPath;
12.12 +extern SourceHook::String g_BinPath;
12.13
12.14 /** @brief Global variable for SourceHook macros */
12.15 extern SourceHook::ISourceHook *g_SHPtr;
13.1 --- a/sourcemm/sourcemm.vcproj Fri Aug 12 17:33:59 2005 +0000
13.2 +++ b/sourcemm/sourcemm.vcproj Fri Aug 12 17:44:53 2005 +0000
13.3 @@ -181,15 +181,6 @@
13.4 RelativePath=".\resource.h">
13.5 </File>
13.6 <File
13.7 - RelativePath=".\smm_list.h">
13.8 - </File>
13.9 - <File
13.10 - RelativePath=".\smm_string.h">
13.11 - </File>
13.12 - <File
13.13 - RelativePath=".\smm_vector.h">
13.14 - </File>
13.15 - <File
13.16 RelativePath=".\sourcemm.h">
13.17 </File>
13.18 <File
13.19 @@ -221,6 +212,9 @@
13.20 Name="SourceHook"
13.21 Filter="">
13.22 <File
13.23 + RelativePath="..\sourcehook\sh_string.h">
13.24 + </File>
13.25 + <File
13.26 RelativePath="..\sourcehook\sourcehook.cpp">
13.27 </File>
13.28 <Filter