string 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Filename: string
  2. // Created by: drose (12May00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. // This file, and all the other files in this directory, aren't
  15. // intended to be compiled--they're just parsed by CPPParser (and
  16. // interrogate) in lieu of the actual system headers, to generate the
  17. // interrogate database.
  18. #ifndef STRING_H
  19. #define STRING_H
  20. #include <stdtypedefs.h>
  21. #include <cwchar>
  22. #include <stdint.h>
  23. namespace std {
  24. template<class charT> struct char_traits;
  25. template<class T> class allocator;
  26. template<> struct char_traits<char> {
  27. using char_type = char;
  28. using int_type = int;
  29. using state_type = mbstate_t;
  30. };
  31. template<> struct char_traits<char16_t> {
  32. using char_type = char16_t;
  33. using int_type = uint_least16_t;
  34. using state_type = mbstate_t;
  35. };
  36. template<> struct char_traits<char32_t> {
  37. using char_type = char32_t;
  38. using int_type = uint_least32_t;
  39. using state_type = mbstate_t;
  40. };
  41. template<> struct char_traits<wchar_t> {
  42. using char_type = wchar_t;
  43. using int_type = wint_t;
  44. using state_type = mbstate_t;
  45. };
  46. template<class CharT, class Traits = std::char_traits<CharT>, class Allocator = std::allocator<CharT> >
  47. class basic_string {
  48. public:
  49. struct iterator;
  50. struct const_iterator;
  51. struct reverse_iterator;
  52. struct const_reverse_iterator;
  53. typedef typename size_t size_type;
  54. static const size_t npos = -1;
  55. basic_string();
  56. basic_string(const basic_string<CharT> &copy);
  57. void operator = (const basic_string<CharT> &copy);
  58. basic_string(const CharT *string);
  59. ~basic_string();
  60. const CharT *c_str() const;
  61. size_t length() const;
  62. CharT at(size_t pos) const;
  63. CharT operator[](size_t pos) const;
  64. CharT &operator[](size_t pos);
  65. };
  66. typedef basic_string<char> string;
  67. typedef basic_string<wchar_t> wstring;
  68. typedef basic_string<char16_t> u16string;
  69. typedef basic_string<char32_t> u32string;
  70. template<class T> struct hash;
  71. template<> struct hash<string>;
  72. template<> struct hash<u16string>;
  73. template<> struct hash<u32string>;
  74. template<> struct hash<wstring>;
  75. inline namespace literals {
  76. inline namespace string_literals {
  77. string operator "" s(const char *str, size_t len);
  78. wstring operator "" s(const wchar_t *str, size_t len);
  79. u16string operator "" s(const char16_t *str, size_t len);
  80. u32string operator "" s(const char32_t *str, size_t len);
  81. }
  82. }
  83. }
  84. #endif