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
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 #ifndef DOTNETSTL_INCL_H_DOTNETSTL
00060 # include "dotnetstl.h"
00061 #endif
00062 #ifndef STLSOFT_INCL_H_STLSOFT_SAP_CAST
00063 # include "stlsoft_sap_cast.h"
00064 #endif
00065 #ifdef STLSOFT_UNITTEST
00066 # include <wchar.h>
00067 #endif
00068
00069
00070
00071
00072
00073 namespace dotnetstl
00074 {
00075 #else
00076
00077
00078 namespace stlsoft
00079 {
00080
00081 namespace dotnetstl_project
00082 {
00083
00084 #endif
00085
00086
00087
00088
00089
00091 template <ss_typename_param_k C>
00092 class c_string_accessor
00093 {
00094 public:
00095 typedef C char_type;
00096 typedef C *pointer;
00097 typedef C const *const_pointer;
00098
00099
00100 public:
00104 ss_explicit_k c_string_accessor(System::String *s)
00105 : m_s(get_cstring_(s))
00106 {}
00108 ~c_string_accessor()
00109 {
00110 System::Runtime::InteropServices::Marshal::FreeHGlobal(m_s);
00111 }
00112
00113
00114 public:
00116 operator const_pointer() const
00117 {
00118 return m_s;
00119 }
00120
00121
00122 private:
00123 pointer get_cstring_(System::String *s);
00124
00125
00126 private:
00127 pointer m_s;
00128
00129
00130 private:
00131 c_string_accessor(c_string_accessor const &);
00132 c_string_accessor &operator =(c_string_accessor const &);
00133 };
00134
00136
00137
00138 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00139
00140 template <>
00141 inline c_string_accessor<ds_char_a_t>::pointer c_string_accessor<ds_char_a_t>::get_cstring_(System::String *s)
00142 {
00143 return sap_cast<ds_char_a_t*>(System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(s).ToPointer());
00144 }
00145
00146 template <>
00147 inline c_string_accessor<ds_char_w_t>::pointer c_string_accessor<ds_char_w_t>::get_cstring_(System::String *s)
00148 {
00149 return sap_cast<ds_char_w_t*>(System::Runtime::InteropServices::Marshal::StringToHGlobalUni(s).ToPointer());
00150 }
00151
00152 #endif
00153
00155
00156
00157 #ifdef STLSOFT_UNITTEST
00158
00159 namespace unittest
00160 {
00161 ss_bool_t test_dotnetstl_string_accessor(unittest_reporter *r)
00162 {
00163 using stlsoft::unittest::unittest_initialiser;
00164
00165 ss_bool_t bSuccess = true;
00166
00167 unittest_initialiser init(r, ".netSTL", "string_accessor", __FILE__);
00168
00169 System::String *s1 = new System::String("String #1");
00170 System::String *s2 = new System::String("String #2");
00171
00172 if(0 != strcmp(c_string_accessor<char>(s1), "String #1"))
00173 {
00174 r->report("c_string_accessor<char>() failed ", __LINE__);
00175 bSuccess = false;
00176 }
00177
00178 if(0 != wcscmp(c_string_accessor<wchar_t>(s2), L"String #2"))
00179 {
00180 r->report("c_string_accessor<char>() failed ", __LINE__);
00181 bSuccess = false;
00182 }
00183
00184 return bSuccess;
00185 }
00186
00187 unittest_registrar unittest_dotnetstl_string_accessor(test_dotnetstl_string_accessor);
00188
00189 }
00190
00191 #endif
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206