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
00041
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 #ifndef ATLSTL_INCL_H_ATLSTL
00071 # include "atlstl.h"
00072 #endif
00073
00074 #if defined(__STLSOFT_COMPILER_IS_BORLAND)
00075 # error No recognised Borland compiler generates correct code when used with these functions
00076 #endif
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 #ifndef _ATLSTL_NO_NAMESPACE
00096 # if defined(_STLSOFT_NO_NAMESPACE) || \
00097 defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00098
00099 namespace atlstl
00100 {
00101 # else
00102
00103
00104 namespace stlsoft
00105 {
00106
00107 namespace atlstl_project
00108 {
00109
00110 # endif
00111 #endif
00112
00113
00114
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00146 template <ss_typename_param_k C, ss_typename_param_k T>
00147 inline HRESULT get_MemberValue(C *const cls, T *ret, T C::*mem)
00148 {
00149 return (ret == 0) ? E_POINTER : (*ret = cls->*mem, S_OK);
00150 }
00151
00163 template <ss_typename_param_k C, class T>
00164 inline HRESULT get_MemberValue(C *const cls, T **ret, T *C::*mem);
00165
00179 template <ss_typename_param_k C>
00180 inline HRESULT get_MemberValue(C *const cls, BSTR *ret, CComBSTR C::*mem)
00181 {
00182 return (ret == 0) ? E_POINTER : (*ret = (cls->*mem).Copy(), (*ret != 0 ? S_OK : E_OUTOFMEMORY));
00183 }
00184
00201 template <ss_typename_param_k C>
00202 inline HRESULT get_MemberValue(C *const cls, VARIANT *ret, CComVariant C::*mem)
00203 {
00204 return (ret == 0) ? E_POINTER : ::VariantCopy(ret, &(cls->*mem));
00205 }
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00230 template <ss_typename_param_k C, ss_typename_param_k T>
00231 inline HRESULT put_MemberValue(C *const cls, T const &newVal, T C::*mem)
00232 {
00233 return (cls->*mem = newVal, S_OK);
00234 }
00235
00246 template <ss_typename_param_k C>
00247 inline HRESULT put_MemberValue(C *const cls, BSTR newVal, CComBSTR C::*mem)
00248 {
00249 return (cls->*mem = newVal, S_OK);
00250 }
00251
00262 template <ss_typename_param_k C>
00263 inline HRESULT put_MemberValue(C *const cls, CComBSTR const &newVal, CComBSTR C::*mem)
00264 {
00265 return put_MemberValue(cls, (BSTR)newVal, mem);
00266 }
00267
00278 template <ss_typename_param_k C>
00279 inline HRESULT put_MemberValue(C *const cls, CComVariant const &newVal, CComVariant C::*mem)
00280 {
00281 return put_MemberValue(cls, (VARIANT const &)newVal, mem);
00282 }
00283
00285
00286
00287 #ifdef STLSOFT_UNITTEST
00288
00289 namespace unittest
00290 {
00291 class SimpleServer
00292 {
00293 public:
00294 SimpleServer()
00295 : m_bstrUserName("[No username]")
00296 , m_logonKey(-1)
00297 {}
00298
00299
00300 public:
00301 STDMETHODIMP SimpleServer::get_UserName( BSTR *pVal)
00302 {
00303 return get_MemberValue(this, pVal, &SimpleServer::m_bstrUserName);
00304 }
00305
00306 STDMETHODIMP SimpleServer::put_UserName( BSTR newVal)
00307 {
00308 return put_MemberValue(this, newVal, &SimpleServer::m_bstrUserName);
00309 }
00310
00311 STDMETHODIMP SimpleServer::get_LogonKey( short *pVal)
00312 {
00313 return get_MemberValue(this, pVal, &SimpleServer::m_logonKey);
00314 }
00315
00316 STDMETHODIMP SimpleServer::put_LogonKey( short newVal)
00317 {
00318 return put_MemberValue(this, newVal, &SimpleServer::m_logonKey);
00319 }
00320
00321
00322 protected:
00323 friend ss_bool_t test_atlstl_property_method_helpers(unittest_reporter *r);
00324
00325 CComBSTR m_bstrUserName;
00326 short m_logonKey;
00327 };
00328
00329 ss_bool_t test_atlstl_property_method_helpers(unittest_reporter *r)
00330 {
00331 using stlsoft::unittest::unittest_initialiser;
00332
00333 ss_bool_t bSuccess = true;
00334 HRESULT hr;
00335
00336 unittest_initialiser init(r, "ATLSTL", "property_method_helpers", __FILE__);
00337
00338 SimpleServer simpleserver;
00339 short logonKey(-1);
00340 CComBSTR bstrUserName;
00341
00342 hr = simpleserver.put_LogonKey(12);
00343 if(FAILED(hr))
00344 {
00345 r->report("call to put_LogonKey() failed ", __LINE__);
00346 bSuccess = false;
00347 }
00348
00349 hr = simpleserver.get_LogonKey(&logonKey);
00350 if(FAILED(hr))
00351 {
00352 r->report("call to get_LogonKey() failed ", __LINE__);
00353 bSuccess = false;
00354 }
00355 else
00356 {
00357 if(12 != logonKey)
00358 {
00359 r->report("put/get_MemberValue failed ", __LINE__);
00360 bSuccess = false;
00361 }
00362 }
00363
00364 simpleserver.put_UserName(L"Matty");
00365 hr = simpleserver.get_UserName(&bstrUserName);
00366 if(SUCCEEDED(hr))
00367 {
00368 if(!(bstrUserName == L"Matty"))
00369 {
00370 r->report("put/get_MemberValue failed ", __LINE__);
00371 bSuccess = false;
00372 }
00373 }
00374
00375 return bSuccess;
00376 }
00377
00378 unittest_registrar unittest_atlstl_property_method_helpers(test_atlstl_property_method_helpers);
00379
00380 }
00381
00382 #endif
00383
00384
00385
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398 #endif
00399
00400
00401
00402
00403
00404