00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00048 #ifndef DOTNETSTL_INCL_DOTNETSTL_STRING_HPP_STRING_ACCESSOR
00049 #define DOTNETSTL_INCL_DOTNETSTL_STRING_HPP_STRING_ACCESSOR
00050
00051 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00052 #define DOTNETSTL_VER_DOTNETSTL_STRING_HPP_STRING_ACCESSOR_MAJOR 4
00053 #define DOTNETSTL_VER_DOTNETSTL_STRING_HPP_STRING_ACCESSOR_MINOR 0
00054 #define DOTNETSTL_VER_DOTNETSTL_STRING_HPP_STRING_ACCESSOR_REVISION 2
00055 #define DOTNETSTL_VER_DOTNETSTL_STRING_HPP_STRING_ACCESSOR_EDIT 47
00056 #endif
00057
00058
00059
00060
00061
00062 #ifndef DOTNETSTL_INCL_DOTNETSTL_HPP_DOTNETSTL
00063 # include <dotnetstl/dotnetstl.hpp>
00064 #endif
00065 #ifndef STLSOFT_INCL_STLSOFT_CONVERSION_HPP_SAP_CAST
00066 # include <stlsoft/conversion/sap_cast.hpp>
00067 #endif
00068 #ifdef STLSOFT_UNITTEST
00069 # include <string.h>
00070 # include <wchar.h>
00071 #endif
00072
00073
00074
00075 #ifdef _STLSOFT_NO_NAMESPACE
00076
00077 namespace dotnetstl
00078 {
00079 #else
00080
00081
00082 namespace stlsoft
00083 {
00084
00085 namespace dotnetstl_project
00086 {
00087
00088 #endif
00089
00090
00091
00092
00093
00098 template <ss_typename_param_k C>
00099 class c_string_accessor
00100 {
00101 public:
00102 typedef C char_type;
00103 typedef C* pointer;
00104 typedef C const* const_pointer;
00105 typedef c_string_accessor<C> class_type;
00106 #if defined(DOTNETSTL_HAT_SYNTAX_SUPPORT)
00107 typedef System::String const ^string_pointer_const_type_;
00108 typedef System::String ^string_pointer_type_;
00109 #else
00110 typedef System::String const* string_pointer_const_type_;
00111 typedef System::String* string_pointer_type_;
00112 #endif
00113
00114
00115 public:
00119 ss_explicit_k c_string_accessor(string_pointer_const_type_ s)
00120 : m_h(get_cstring_(s))
00121 {}
00123 ~c_string_accessor() stlsoft_throw_0()
00124 {
00125 System::Runtime::InteropServices::Marshal::FreeHGlobal(m_h);
00126 }
00127
00128 c_string_accessor(c_string_accessor& rhs)
00129 : m_h(rhs.m_h)
00130 {
00131 rhs.m_h = 0;
00132 }
00133
00134
00135 public:
00137 operator const_pointer() const
00138 {
00139 #if defined(DOTNETSTL_HAT_SYNTAX_SUPPORT)
00140 IntPtr h = m_h;
00141
00142 return static_cast<const_pointer>(h.ToPointer());
00143 #else
00144 return m_h;
00145 #endif
00146 }
00147
00148
00149 private:
00150 pointer get_cstring_(string_pointer_const_type_ s);
00151
00152
00153 private:
00154 #if defined(DOTNETSTL_HAT_SYNTAX_SUPPORT)
00155 System::IntPtr m_h;
00156 #else
00157 pointer m_h;
00158 #endif
00159
00160
00161 private:
00162 c_string_accessor& operator =(class_type const&);
00163 };
00164
00166
00167
00168 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00169
00170 STLSOFT_TEMPLATE_SPECIALISATION
00171 inline c_string_accessor<ds_char_a_t>::pointer c_string_accessor<ds_char_a_t>::get_cstring_(string_pointer_const_type_ s)
00172 {
00173 return sap_cast<ds_char_a_t*>(System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(const_cast<string_pointer_type_>(s)).ToPointer());
00174 }
00175
00176 STLSOFT_TEMPLATE_SPECIALISATION
00177 inline c_string_accessor<ds_char_w_t>::pointer c_string_accessor<ds_char_w_t>::get_cstring_(string_pointer_const_type_ s)
00178 {
00179 return sap_cast<ds_char_w_t*>(System::Runtime::InteropServices::Marshal::StringToHGlobalUni(const_cast<string_pointer_type_>(s)).ToPointer());
00180 }
00181
00182 #endif
00183
00185
00186
00187 #ifdef STLSOFT_UNITTEST
00188 # include "./unittest/string_accessor_unittest_.h"
00189 #endif
00190
00191
00192
00193 #ifdef _STLSOFT_NO_NAMESPACE
00194 }
00195 #else
00196 }
00197 }
00198 #endif
00199
00200
00201
00202 #endif
00203
00204