1 // file      : xsd/cxx/xml/string.hxx
2 // copyright : Copyright (c) 2005-2017 Code Synthesis Tools CC
3 // license   : GNU GPL v2 + exceptions; see accompanying LICENSE file
4 
5 #ifndef XSD_CXX_XML_STRING_HXX
6 #define XSD_CXX_XML_STRING_HXX
7 
8 #include <string>
9 #include <cstddef> // std::size_t
10 
11 #include <xercesc/util/XercesDefs.hpp> // XMLCh
12 
13 #include <xsd/cxx/config.hxx> // XSD_CXX11
14 
15 #ifdef XSD_CXX11
16 #  include <memory> // std::unique_ptr
17 #else
18 #  include <xsd/cxx/auto-array.hxx>
19 #endif
20 
21 namespace xsd
22 {
23   namespace cxx
24   {
25     namespace xml
26     {
27       // Transcode a null-terminated string.
28       //
29       template <typename C>
30       std::basic_string<C>
31       transcode (const XMLCh* s);
32 
33       // Transcode a potentially non-null-terminated string.
34       //
35       template <typename C>
36       std::basic_string<C>
37       transcode (const XMLCh* s, std::size_t length);
38 
39 
40       // For VC wchar_t and XMLCh are the same type so we cannot overload
41       // the transcode name. You should not use these functions anyway and
42       // instead use the xml::string class below.
43       //
44       template <typename C>
45       XMLCh*
46       transcode_to_xmlch (const C*);
47 
48       template <typename C>
49       XMLCh*
50       transcode_to_xmlch (const std::basic_string<C>& s);
51 
52       //
53       //
54       class string
55       {
56       public :
57         template <typename C>
string(const std::basic_string<C> & s)58         string (const std::basic_string<C>& s)
59             : s_ (transcode_to_xmlch<C> (s)) {}
60 
61         template <typename C>
string(const C * s)62         string (const C* s): s_ (transcode_to_xmlch<C> (s)) {}
63 
64         const XMLCh*
c_str() const65         c_str () const {return s_.get ();}
66 
67         XMLCh*
release()68         release () {return s_.release ();}
69 
70       private:
71         string (const string&);
72 
73         string&
74         operator= (const string&);
75 
76       private:
77 #ifdef XSD_CXX11
78         std::unique_ptr<XMLCh[]> s_;
79 #else
80         auto_array<XMLCh> s_;
81 #endif
82       };
83     }
84   }
85 }
86 
87 #endif // XSD_CXX_XML_STRING_HXX
88 
89 #include <xsd/cxx/xml/string.ixx>
90 #include <xsd/cxx/xml/string.txx>
91