• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

RakString.h

Go to the documentation of this file.
00001 #ifndef __RAK_STRING_H
00002 #define __RAK_STRING_H 
00003 
00004 #include "Export.h"
00005 #include "DS_List.h"
00006 #include "RakNetTypes.h" // int64_t
00007 #include <stdio.h>
00008 #include "stdarg.h"
00009 
00010 class SimpleMutex;
00011 
00012 namespace RakNet
00013 {
00014 
00015 class BitStream;
00016 
00022 class RAK_DLL_EXPORT RakString
00023 {
00024 public:
00025         // Constructors
00026         RakString();
00027         RakString(char input);
00028         RakString(unsigned char input);
00029         RakString(const unsigned char *format, ...);
00030         RakString(const char *format, ...);
00031         ~RakString();
00032         RakString( const RakString & rhs);
00033 
00035         operator const char* () const {return sharedString->c_str;}
00036 
00038         const char *C_String(void) const {return sharedString->c_str;}
00039 
00040         // Lets you modify the string. Do not make the string longer - however, you can make it shorter, or change the contents.
00041         // Pointer is only valid in the scope of RakString itself
00042         char *C_StringUnsafe(void) {Clone(); return sharedString->c_str;}
00043 
00045         RakString& operator = ( const RakString& rhs );
00046         RakString& operator = ( const char *str );
00047         RakString& operator = ( char *str );
00048         RakString& operator = ( const char c );
00049 
00051         RakString& operator +=( const RakString& rhs);
00052         RakString& operator += ( const char *str );
00053         RakString& operator += ( char *str );
00054         RakString& operator += ( const char c );
00055 
00057         unsigned char operator[] ( const unsigned int position ) const;
00058 
00059         
00066         size_t Find(const char *stringToFind,size_t pos = 0 );
00067 
00069         bool operator==(const RakString &rhs) const;
00070         bool operator==(const char *str) const;
00071         bool operator==(char *str) const;
00072 
00073         // Comparison
00074         bool operator < ( const RakString& right ) const;
00075         bool operator <= ( const RakString& right ) const;
00076         bool operator > ( const RakString& right ) const;
00077         bool operator >= ( const RakString& right ) const;
00078 
00080         bool operator!=(const RakString &rhs) const;
00081         bool operator!=(const char *str) const;
00082         bool operator!=(char *str) const;
00083 
00085         const char * ToLower(void);
00086 
00088         const char * ToUpper(void);
00089 
00091         void Set(const char *format, ...);
00092 
00100         RakString Assign(const char *str,size_t pos, size_t n );
00101 
00103         bool IsEmpty(void) const;
00104 
00106         size_t GetLength(void) const;
00107 
00109         void Replace(unsigned index, unsigned count, unsigned char c);
00110 
00112         void SetChar( unsigned index, unsigned char c );
00113 
00115         void SetChar( unsigned index, RakNet::RakString s );
00116 
00118         void Truncate(unsigned length);
00119 
00120         // Gets the substring starting at index for count characters
00121         RakString SubStr(unsigned int index, unsigned int count) const;
00122 
00124         void Erase(unsigned int index, unsigned int count);
00125 
00127         void TerminateAtFirstCharacter(char c);
00129         void TerminateAtLastCharacter(char c);
00130         
00132         void RemoveCharacter(char c);
00133 
00136         static RakNet::RakString NonVariadic(const char *str);
00137 
00139         static unsigned long ToInteger(const char *str);
00140         static unsigned long ToInteger(const RakString &rs);
00141 
00142         // Like strncat, but for a fixed length
00143         void AppendBytes(const char *bytes, unsigned int count);
00144 
00146         int StrCmp(const RakString &rhs) const;
00147 
00149         int StrICmp(const RakString &rhs) const;
00150 
00152         void Clear(void);
00153 
00155         void Printf(void);
00156 
00158         void FPrintf(FILE *fp);
00159 
00161         bool IPAddressMatch(const char *IP);
00162 
00164         bool ContainsNonprintableExceptSpaces(void) const;
00165 
00167         bool IsEmailAddress(void) const;
00168 
00170         RakNet::RakString& URLEncode(void);
00171 
00173         RakNet::RakString& URLDecode(void);
00174 
00176         RakNet::RakString& SQLEscape(void);
00177 
00179         RakNet::RakString& MakeFilePath(void);
00180 
00183         static void FreeMemory(void);
00185         static void FreeMemoryNoMutex(void);
00186 
00189         void Serialize(BitStream *bs) const;
00190 
00192         static void Serialize(const char *str, BitStream *bs);
00193 
00199         void SerializeCompressed(BitStream *bs, int languageId=0, bool writeLanguageId=false) const;
00200 
00202         static void SerializeCompressed(const char *str, BitStream *bs, int languageId=0, bool writeLanguageId=false);
00203 
00207         bool Deserialize(BitStream *bs);
00208 
00210         static bool Deserialize(char *str, BitStream *bs);
00211 
00217         bool DeserializeCompressed(BitStream *bs, bool readLanguageId=false);
00218 
00220         static bool DeserializeCompressed(char *str, BitStream *bs, bool readLanguageId=false);
00221 
00222         static const char *ToString(int64_t i);
00223         static const char *ToString(uint64_t i);
00224 
00226         static size_t GetSizeToAllocate(size_t bytes)
00227         {
00228                 const size_t smallStringSize = 128-sizeof(unsigned int)-sizeof(size_t)-sizeof(char*)*2;
00229                 if (bytes<=smallStringSize)
00230                         return smallStringSize;
00231                 else
00232                         return bytes*2;
00233         }
00234 
00236         struct SharedString
00237         {
00238                 SimpleMutex *refCountMutex;
00239                 unsigned int refCount;
00240                 size_t bytesUsed;
00241                 char *bigString;
00242                 char *c_str;
00243                 char smallString[128-sizeof(unsigned int)-sizeof(size_t)-sizeof(char*)*2];              
00244         };
00245 
00247         RakString( SharedString *_sharedString );
00248 
00250         SharedString *sharedString;
00251 
00252 //      static SimpleMutex poolMutex;
00253 //      static DataStructures::MemoryPool<SharedString> pool;
00255         static SharedString emptyString;
00256 
00257         //static SharedString *sharedStringFreeList;
00258         //static unsigned int sharedStringFreeListAllocationCount;
00261         static DataStructures::List<SharedString*> freeList;
00262 
00264         static unsigned int nPos;
00265 
00266 
00267         static int RakStringComp( RakString const &key, RakString const &data );
00268 
00269         static void LockMutex(void);
00270         static void UnlockMutex(void);
00271 
00272 protected:
00273         void Allocate(size_t len);
00274         void Assign(const char *str);
00275         void Assign(const char *str, va_list ap);
00276         
00277         void Clone(void);
00278         void Free(void);
00279         unsigned char ToLower(unsigned char c);
00280         unsigned char ToUpper(unsigned char c);
00281         void Realloc(SharedString *sharedString, size_t bytes);
00282 };
00283 
00284 }
00285 
00286 const RakNet::RakString RAK_DLL_EXPORT operator+(const RakNet::RakString &lhs, const RakNet::RakString &rhs);
00287 
00288 
00289 #endif

Generated on Thu Sep 30 2010 01:27:26 for RakNet by  doxygen 1.7.1