VTK
dox/Common/vtkUnicodeString.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkUnicodeString.h
00005   
00006 -------------------------------------------------------------------------
00007   Copyright 2008 Sandia Corporation.
00008   Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009   the U.S. Government retains certain rights in this software.
00010 -------------------------------------------------------------------------
00011 
00012   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00013   All rights reserved.
00014   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00015 
00016      This software is distributed WITHOUT ANY WARRANTY; without even
00017      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00018      PURPOSE.  See the above copyright notice for more information.
00019 
00020 =========================================================================*/
00021 
00049 #ifndef __vtkUnicodeString_h
00050 #define __vtkUnicodeString_h
00051 
00052 #include <vtkSystemIncludes.h>
00053 #include <string>
00054 #include <vector>
00055 
00056 class vtkUnicodeString;
00057 
00058 typedef vtkTypeUInt32 vtkUnicodeStringValueType;
00059 
00060 //
00061 // The following should be eventually placed in vtkSetGet.h
00062 //
00063 
00064 // This is same as extra extended template macro with an 
00065 // additional case for VTK_UNICODE_STRING
00066 #define vtkSuperExtraExtendedTemplateMacro(call)                                 \
00067   vtkExtraExtendedTemplateMacro(call);                                            \
00068   vtkTemplateMacroCase(VTK_UNICODE_STRING, vtkUnicodeString, call)
00069 
00070 class VTK_COMMON_EXPORT vtkUnicodeString
00071 {
00072 public:
00073   typedef vtkUnicodeStringValueType value_type;
00074   typedef std::string::size_type size_type;
00075 
00076   class VTK_COMMON_EXPORT const_iterator
00077   {
00078   public:
00079     typedef std::bidirectional_iterator_tag iterator_category;
00080     typedef vtkUnicodeStringValueType value_type;
00081     typedef std::string::difference_type difference_type;
00082     typedef value_type* pointer;
00083     typedef value_type& reference;
00084   
00085     const_iterator();
00086 
00087     value_type operator*() const;
00088     bool operator==(const const_iterator&) const;
00089     bool operator!=(const const_iterator&) const;
00090     const_iterator& operator++();
00091     const_iterator operator++(int);
00092     const_iterator& operator--();
00093     const_iterator operator--(int);
00094 
00095   private:
00096     const_iterator(std::string::const_iterator);
00097     friend class vtkUnicodeString;
00098     std::string::const_iterator Position;
00099   };
00100 
00102   vtkUnicodeString();
00104   vtkUnicodeString(const vtkUnicodeString&);
00107   vtkUnicodeString(size_type count, value_type character);
00109   vtkUnicodeString(const_iterator begin, const_iterator end);
00110 
00112 
00114   static bool is_utf8(const char*);
00115   static bool is_utf8(const std::string&);
00117 
00119 
00121   static vtkUnicodeString from_utf8(const char*);
00122   // Constructs a string from a half-open sequence of UTF-8 encoded characters.
00123   static vtkUnicodeString from_utf8(const char* begin, const char* end);
00124   // Constructs a string from a sequence of UTF-8 encoded characters.
00125   static vtkUnicodeString from_utf8(const std::string&);
00127 
00129   static vtkUnicodeString from_utf16(const vtkTypeUInt16*);
00130 
00132   vtkUnicodeString& operator=(const vtkUnicodeString&);
00133 
00136   const_iterator begin() const;
00139   const_iterator end() const;
00140 
00143   value_type at(size_type offset) const;
00146   value_type operator[](size_type offset) const;
00147 
00150   const char* utf8_str() const;
00153   void utf8_str(std::string& result) const;
00155   std::vector<vtkTypeUInt16> utf16_str() const;
00158   void utf16_str(std::vector<vtkTypeUInt16>& result) const;
00159 
00161   size_type byte_count() const;
00163   size_type character_count() const;
00165   bool empty() const;
00166 
00168   static const size_type npos;
00169 
00171   vtkUnicodeString& operator+=(value_type); 
00173   vtkUnicodeString& operator+=(const vtkUnicodeString& rhs);
00174   
00176   void push_back(value_type);
00177 
00179 
00180   void append(const vtkUnicodeString& value);
00181   void append(size_type count, value_type character);
00182   void append(const_iterator begin, const_iterator end);
00184 
00186 
00187   void assign(const vtkUnicodeString& value);
00188   void assign(size_type count, value_type character);
00189   void assign(const_iterator begin, const_iterator end);
00191  
00193   void clear();
00194 
00201   vtkUnicodeString fold_case() const;
00202 
00208   int compare(const vtkUnicodeString&) const;
00209 
00212   vtkUnicodeString substr(size_type offset = 0, size_type count = npos) const;
00213   
00215   void swap(vtkUnicodeString&);
00216 
00217 private:
00218   std::string Storage;
00219   class back_insert_iterator;
00220 };
00221 
00222 VTK_COMMON_EXPORT bool operator==(const vtkUnicodeString& lhs, const vtkUnicodeString& rhs);
00223 VTK_COMMON_EXPORT bool operator!=(const vtkUnicodeString& lhs, const vtkUnicodeString& rhs);
00224 VTK_COMMON_EXPORT bool operator<(const vtkUnicodeString& lhs, const vtkUnicodeString& rhs);
00225 VTK_COMMON_EXPORT bool operator<=(const vtkUnicodeString& lhs, const vtkUnicodeString& rhs);
00226 VTK_COMMON_EXPORT bool operator>=(const vtkUnicodeString& lhs, const vtkUnicodeString& rhs);
00227 VTK_COMMON_EXPORT bool operator>(const vtkUnicodeString& lhs, const vtkUnicodeString& rhs);
00228 
00229 #endif
00230