sstring.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // Filename:- sstring.h
  2. //
  3. // Gil's string template, used to replace Microsoft's <string> vrsion which doesn't compile under certain stl map<>
  4. // conditions...
  5. #ifndef SSTRING_H
  6. #define SSTRING_H
  7. template<int MaxSize>
  8. class sstring
  9. {
  10. struct SStorage
  11. {
  12. char data[MaxSize];
  13. };
  14. SStorage mStorage;
  15. public:
  16. /* don't figure we need this
  17. template<int oMaxSize>
  18. sstring(const sstring<oMaxSize> &o)
  19. {
  20. assert(strlen(o.mStorage.data)<MaxSize);
  21. strcpy(mStorage.data,o.mStorage.data);
  22. }
  23. */
  24. sstring(const sstring<MaxSize> &o)
  25. {
  26. //strcpy(mStorage.data,o.mStorage.data);
  27. Q_strncpyz(mStorage.data,o.mStorage.data,sizeof(mStorage.data),qtrue);
  28. }
  29. sstring(const char *s)
  30. {
  31. //assert(strlen(s)<MaxSize);
  32. //strcpy(mStorage.data,s);
  33. Q_strncpyz(mStorage.data,s,sizeof(mStorage.data),qtrue);
  34. }
  35. sstring()
  36. {
  37. mStorage.data[0]=0;
  38. }
  39. /* don't figure we need this
  40. template<int oMaxSize>
  41. sstring<oMaxSize> & operator =(const sstring<oMaxSize> &o)
  42. {
  43. assert(strlen(o.mStorage.data)<MaxSize);
  44. strcpy(mStorage.data,o.mStorage.data);
  45. return *this;
  46. }
  47. */
  48. sstring<MaxSize> & operator=(const sstring<MaxSize> &o)
  49. {
  50. //strcpy(mStorage.data,o.mStorage.data);
  51. Q_strncpyz(mStorage.data,o.mStorage.data,sizeof(mStorage.data),qtrue);
  52. return *this;
  53. }
  54. sstring<MaxSize> & operator=(const char *s)
  55. {
  56. assert(strlen(s)<MaxSize);
  57. //strcpy(mStorage.data,s);
  58. Q_strncpyz(mStorage.data,s,sizeof(mStorage.data),qtrue);
  59. return *this;
  60. }
  61. char *c_str()
  62. {
  63. return mStorage.data;
  64. }
  65. const char *c_str() const
  66. {
  67. return mStorage.data;
  68. }
  69. int capacity() const
  70. {
  71. return MaxSize; // not sure if this should be MaxSize-1? depends if talking bytes or strlen space I guess
  72. }
  73. int length() const
  74. {
  75. return strlen(mStorage.data);
  76. }
  77. bool operator==(const sstring<MaxSize> &o) const
  78. {
  79. if (!strcmpi(mStorage.data,o.mStorage.data))
  80. {
  81. return true;
  82. }
  83. return false;
  84. }
  85. bool operator!=(const sstring<MaxSize> &o) const
  86. {
  87. if (strcmpi(mStorage.data,o.mStorage.data)!=0)
  88. {
  89. return true;
  90. }
  91. return false;
  92. }
  93. bool operator<(const sstring<MaxSize> &o) const
  94. {
  95. if (strcmpi(mStorage.data,o.mStorage.data)<0)
  96. {
  97. return true;
  98. }
  99. return false;
  100. }
  101. bool operator>(const sstring<MaxSize> &o) const
  102. {
  103. if (strcmpi(mStorage.data,o.mStorage.data)>0)
  104. {
  105. return true;
  106. }
  107. return false;
  108. }
  109. };
  110. typedef sstring<MAX_QPATH> sstring_t;
  111. #endif // #ifndef SSTRING_H
  112. /////////////////// eof ////////////////////