String 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. #ifndef OSGTEXT_STRING
  14. #define OSGTEXT_STRING 1
  15. #include <vector>
  16. #include <set>
  17. #include <string>
  18. #include <osgText/Export>
  19. namespace osgText {
  20. // ******************************** HACK **********************************
  21. // Following class is needed to work around a DLL export problem. See file
  22. // include/osg/PrimitiveSet for details.
  23. class VectorUInt: public std::vector<unsigned int>
  24. {
  25. typedef std::vector<value_type> vector_type;
  26. public:
  27. VectorUInt(): vector_type() {}
  28. VectorUInt(const VectorUInt &copy): vector_type(copy) {}
  29. VectorUInt(unsigned int* beg, unsigned int* end): vector_type(beg, end) {}
  30. explicit VectorUInt(unsigned int n): vector_type(n) {}
  31. };
  32. // **************************************************************************
  33. class Text;
  34. class OSGTEXT_EXPORT String : public VectorUInt
  35. {
  36. public:
  37. typedef VectorUInt vector_type;
  38. /**
  39. * Types of string encodings supported
  40. */
  41. enum Encoding
  42. {
  43. ENCODING_UNDEFINED, /// not using Unicode
  44. ENCODING_ASCII = ENCODING_UNDEFINED,/// unsigned char ASCII
  45. ENCODING_UTF8, /// 8-bit unicode transformation format
  46. ENCODING_UTF16, /// 16-bit signature
  47. ENCODING_UTF16_BE, /// 16-bit big-endian
  48. ENCODING_UTF16_LE, /// 16-bit little-endian
  49. ENCODING_UTF32, /// 32-bit signature
  50. ENCODING_UTF32_BE, /// 32-bit big-endian
  51. ENCODING_UTF32_LE, /// 32-bit little-endian
  52. ENCODING_SIGNATURE, /// detect encoding from signature
  53. ENCODING_CURRENT_CODE_PAGE /// Use Windows Current Code Page ecoding
  54. };
  55. String() {}
  56. String(const String& str);
  57. String(const std::string& str) { set(str); }
  58. String(const wchar_t* text) { set(text); }
  59. String(const std::string& text,Encoding encoding) { set(text,encoding); }
  60. String& operator = (const String& str);
  61. void set(const std::string& str);
  62. /** Set the text using a wchar_t string,
  63. * which is converted to an internal TextString.*/
  64. void set(const wchar_t* text);
  65. /** Set the text using a Unicode encoded std::string, which is converted to an internal TextString.
  66. * The encoding parameter specifies which Unicode encoding is used in the std::string. */
  67. void set(const std::string& text,Encoding encoding);
  68. /** returns a UTF8 encoded version of this osgText::String.*/
  69. std::string createUTF8EncodedString() const;
  70. protected:
  71. };
  72. }
  73. #endif