RakWString.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. #ifndef __RAK_W_STRING_H
  11. #define __RAK_W_STRING_H
  12. #include "Export.h"
  13. #include "RakNetTypes.h" // int64_t
  14. #include "RakString.h"
  15. #ifdef _WIN32
  16. #include "WindowsIncludes.h"
  17. #endif
  18. namespace RakNet
  19. {
  20. /// \brief String class for Unicode
  21. class RAK_DLL_EXPORT RakWString
  22. {
  23. public:
  24. // Constructors
  25. RakWString();
  26. RakWString( const RakString &right );
  27. RakWString( const wchar_t *input );
  28. RakWString( const RakWString & right);
  29. RakWString( const char *input );
  30. ~RakWString();
  31. /// Implicit return of wchar_t*
  32. operator wchar_t* () const {if (c_str) return c_str; return (wchar_t*) L"";}
  33. /// Same as std::string::c_str
  34. const wchar_t* C_String(void) const {if (c_str) return c_str; return (const wchar_t*) L"";}
  35. /// Assignment operators
  36. RakWString& operator = ( const RakWString& right );
  37. RakWString& operator = ( const RakString& right );
  38. RakWString& operator = ( const wchar_t * const str );
  39. RakWString& operator = ( wchar_t *str );
  40. RakWString& operator = ( const char * const str );
  41. RakWString& operator = ( char *str );
  42. /// Concatenation
  43. RakWString& operator +=( const RakWString& right);
  44. RakWString& operator += ( const wchar_t * const right );
  45. RakWString& operator += ( wchar_t *right );
  46. /// Equality
  47. bool operator==(const RakWString &right) const;
  48. // Comparison
  49. bool operator < ( const RakWString& right ) const;
  50. bool operator <= ( const RakWString& right ) const;
  51. bool operator > ( const RakWString& right ) const;
  52. bool operator >= ( const RakWString& right ) const;
  53. /// Inequality
  54. bool operator!=(const RakWString &right) const;
  55. /// Set the value of the string
  56. void Set( wchar_t *str );
  57. /// Returns if the string is empty. Also, C_String() would return ""
  58. bool IsEmpty(void) const;
  59. /// Returns the length of the string
  60. size_t GetLength(void) const;
  61. /// Has the string into an unsigned int
  62. static unsigned long ToInteger(const RakWString &rs);
  63. /// Compare strings (case sensitive)
  64. int StrCmp(const RakWString &right) const;
  65. /// Compare strings (not case sensitive)
  66. int StrICmp(const RakWString &right) const;
  67. /// Clear the string
  68. void Clear(void);
  69. /// Print the string to the screen
  70. void Printf(void);
  71. /// Print the string to a file
  72. void FPrintf(FILE *fp);
  73. /// Serialize to a bitstream, uncompressed (slightly faster)
  74. /// \param[out] bs Bitstream to serialize to
  75. void Serialize(BitStream *bs) const;
  76. /// Static version of the Serialize function
  77. static void Serialize(const wchar_t * const str, BitStream *bs);
  78. /// Deserialize what was written by Serialize
  79. /// \param[in] bs Bitstream to serialize from
  80. /// \return true if the deserialization was successful
  81. bool Deserialize(BitStream *bs);
  82. /// Static version of the Deserialize() function
  83. static bool Deserialize(wchar_t *str, BitStream *bs);
  84. protected:
  85. wchar_t* c_str;
  86. size_t c_strCharLength;
  87. };
  88. }
  89. const RakNet::RakWString RAK_DLL_EXPORT operator+(const RakNet::RakWString &lhs, const RakNet::RakWString &rhs);
  90. #endif
粤ICP备19079148号