1 /* 2 =========================================================================== 3 Copyright (C) 2000 - 2013, Raven Software, Inc. 4 Copyright (C) 2001 - 2013, Activision, Inc. 5 Copyright (C) 2013 - 2015, OpenJK contributors 6 7 This file is part of the OpenJK source code. 8 9 OpenJK is free software; you can redistribute it and/or modify it 10 under the terms of the GNU General Public License version 2 as 11 published by the Free Software Foundation. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program; if not, see <http://www.gnu.org/licenses/>. 20 =========================================================================== 21 */ 22 23 #pragma once 24 25 #include "../qcommon/q_shared.h" 26 27 // Filename:- sstring.h 28 // 29 // Gil's string template, used to replace Microsoft's <string> vrsion which doesn't compile under certain stl map<> 30 // conditions... 31 32 33 template<int MaxSize> 34 class sstring 35 { 36 struct SStorage 37 { 38 char data[MaxSize]; 39 }; 40 SStorage mStorage; 41 public: 42 /* don't figure we need this 43 template<int oMaxSize> 44 sstring(const sstring<oMaxSize> &o) 45 { 46 assert(strlen(o.mStorage.data)<MaxSize); 47 strcpy(mStorage.data,o.mStorage.data); 48 } 49 */ sstring(const sstring<MaxSize> & o)50 sstring(const sstring<MaxSize> &o) 51 { 52 //strcpy(mStorage.data,o.mStorage.data); 53 Q_strncpyz(mStorage.data,o.mStorage.data,sizeof(mStorage.data)); 54 } sstring(const char * s)55 sstring(const char *s) 56 { 57 //assert(strlen(s)<MaxSize); 58 //strcpy(mStorage.data,s); 59 Q_strncpyz(mStorage.data,s,sizeof(mStorage.data)); 60 } sstring()61 sstring() 62 { 63 mStorage.data[0]=0; 64 } 65 /* don't figure we need this 66 template<int oMaxSize> 67 sstring<oMaxSize> & operator =(const sstring<oMaxSize> &o) 68 { 69 assert(strlen(o.mStorage.data)<MaxSize); 70 strcpy(mStorage.data,o.mStorage.data); 71 return *this; 72 } 73 */ 74 sstring<MaxSize> & operator=(const sstring<MaxSize> &o) 75 { 76 //strcpy(mStorage.data,o.mStorage.data); 77 Q_strncpyz(mStorage.data,o.mStorage.data,sizeof(mStorage.data)); 78 return *this; 79 } 80 sstring<MaxSize> & operator=(const char *s) 81 { 82 assert(strlen(s)<MaxSize); 83 //strcpy(mStorage.data,s); 84 Q_strncpyz(mStorage.data,s,sizeof(mStorage.data)); 85 return *this; 86 } c_str()87 char *c_str() 88 { 89 return mStorage.data; 90 } c_str()91 const char *c_str() const 92 { 93 return mStorage.data; 94 } capacity()95 int capacity() const 96 { 97 return MaxSize; 98 } length()99 int length() const 100 { 101 return strlen(mStorage.data); 102 } empty()103 bool empty() const 104 { 105 return mStorage.data[0] == '\0'; //FIXME: might want to check MaxSize instead? 106 } 107 bool operator==(const sstring<MaxSize> &o) const 108 { 109 if (!Q_stricmp(mStorage.data,o.mStorage.data)) 110 { 111 return true; 112 } 113 return false; 114 } 115 bool operator!=(const sstring<MaxSize> &o) const 116 { 117 if (Q_stricmp(mStorage.data,o.mStorage.data)!=0) 118 { 119 return true; 120 } 121 return false; 122 } 123 bool operator<(const sstring<MaxSize> &o) const 124 { 125 if (Q_stricmp(mStorage.data,o.mStorage.data)<0) 126 { 127 return true; 128 } 129 return false; 130 } 131 bool operator>(const sstring<MaxSize> &o) const 132 { 133 if (Q_stricmp(mStorage.data,o.mStorage.data)>0) 134 { 135 return true; 136 } 137 return false; 138 } 139 }; 140 141 typedef sstring<MAX_QPATH> sstring_t; 142 143 /////////////////// eof //////////////////// 144