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
00048 #ifndef COMSTL_INCL_COMSTL_UTIL_HPP_VALUE_POLICIES
00049 #define COMSTL_INCL_COMSTL_UTIL_HPP_VALUE_POLICIES
00050
00051 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00052 # define COMSTL_VER_COMSTL_UTIL_HPP_VALUE_POLICIES_MAJOR 5
00053 # define COMSTL_VER_COMSTL_UTIL_HPP_VALUE_POLICIES_MINOR 1
00054 # define COMSTL_VER_COMSTL_UTIL_HPP_VALUE_POLICIES_REVISION 1
00055 # define COMSTL_VER_COMSTL_UTIL_HPP_VALUE_POLICIES_EDIT 164
00056 #endif
00057
00058
00059
00060
00061
00062 #ifndef COMSTL_INCL_COMSTL_H_COMSTL
00063 # include <comstl/comstl.h>
00064 #endif
00065 #ifndef COMSTL_INCL_COMSTL_STRING_H_OLESTRING_FUNCTIONS
00066 # include <comstl/string/olestring_functions.h>
00067 #endif
00068 #ifndef STLSOFT_INCL_STLSOFT_CONVERSION_HPP_SAP_CAST
00069 # include <stlsoft/conversion/sap_cast.hpp>
00070 #endif
00071
00072 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00073 # ifndef COMSTL_INCL_COMSTL_ERROR_HPP_EXCEPTIONS
00074 # include <comstl/error/exceptions.hpp>
00075 # endif
00076 #endif
00077
00078
00079
00080
00081
00082 #ifndef _COMSTL_NO_NAMESPACE
00083 # if defined(_STLSOFT_NO_NAMESPACE) || \
00084 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00085
00086 namespace comstl
00087 {
00088 # else
00089
00090
00091 namespace stlsoft
00092 {
00093
00094 namespace comstl_project
00095 {
00096
00097 # endif
00098 #endif
00099
00100
00101
00102
00103
00111 struct GUID_policy
00112 {
00113 public:
00114 typedef GUID value_type;
00115
00116 public:
00120 static void init(value_type* ) stlsoft_throw_0()
00121 {}
00126 static void copy(value_type* dest, value_type const* src)
00127 {
00128 *dest = *src;
00129 }
00133 static void clear(value_type* ) stlsoft_throw_0()
00134 {}
00135 };
00136
00137
00145 struct BSTR_policy
00146 {
00147 public:
00148 typedef BSTR value_type;
00149
00150 public:
00155 static void init(value_type* p) stlsoft_throw_0()
00156 {
00157 *p = NULL;
00158 }
00167 static void copy(value_type* dest, value_type const* src)
00168 {
00169 *dest = ::SysAllocString(*src);
00170
00171 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00172 if( NULL == *dest &&
00173 NULL != *src &&
00174 L'\0' != (*src)[0])
00175 {
00176 throw com_exception("failed to copy BSTR", E_OUTOFMEMORY);
00177 }
00178 #endif
00179 }
00184 static void clear(value_type* p) stlsoft_throw_0()
00185 {
00186 ::SysFreeString(*p);
00187 }
00188 };
00189
00190
00198 struct LPOLESTR_policy
00199 {
00200 public:
00201 typedef LPOLESTR value_type;
00202
00203 public:
00208 static void init(value_type* p) stlsoft_throw_0()
00209 {
00210 *p = NULL;
00211 }
00220 static void copy(value_type* dest, value_type const* src)
00221 {
00222 *dest = olestring_dup(*src);
00223
00224 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00225 if( NULL == *dest &&
00226 NULL != *src)
00227 {
00228 throw com_exception("failed to copy OLE string", E_OUTOFMEMORY);
00229 }
00230 #endif
00231 }
00236 static void clear(value_type* p) stlsoft_throw_0()
00237 {
00238 olestring_destroy(*p);
00239 }
00240 };
00241
00242
00250 struct VARIANT_policy
00251 {
00252 public:
00253 typedef VARIANT value_type;
00254
00255 public:
00260 static void init(value_type* p) stlsoft_throw_0()
00261 {
00262 ::VariantInit(p);
00263 }
00272 static void copy(value_type* dest, value_type const* src)
00273 {
00274 HRESULT hr = ::VariantCopy(dest, const_cast<VARIANT*>(src));
00275
00276 if(FAILED(hr))
00277 {
00278 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00279 throw com_exception("failed to copy VARIANT", hr);
00280 #endif
00281 }
00282 }
00287 static void clear(value_type* p) stlsoft_throw_0()
00288 {
00289 ::VariantClear(p);
00290 }
00291 };
00292
00293
00303 template <ss_typename_param_k I>
00304 struct interface_policy
00305 {
00306 public:
00307 typedef I interface_type;
00308 typedef interface_type* value_type;
00309
00310 public:
00315 static void init(value_type* p) stlsoft_throw_0()
00316 {
00317 *p = NULL;
00318 }
00324 static void copy(value_type* dest, value_type const* src)
00325 {
00326 *dest = *src;
00327 if(NULL != *dest)
00328 {
00329 (*dest)->AddRef();
00330 }
00331 }
00337 static void clear(value_type* p) stlsoft_throw_0()
00338 {
00339 if(NULL != *p)
00340 {
00341 (*p)->Release();
00342 *p = NULL;
00343 }
00344 }
00345 };
00346
00347
00355 struct LPUNKNOWN_policy
00356 {
00357 public:
00358 typedef LPUNKNOWN value_type;
00359
00360 public:
00365 static void init(value_type* p) stlsoft_throw_0()
00366 {
00367 *p = NULL;
00368 }
00374 static void copy(value_type* dest, value_type const* src)
00375 {
00376 *dest = *src;
00377 if(NULL != *dest)
00378 {
00379 (*dest)->AddRef();
00380 }
00381 }
00387 static void clear(value_type* p) stlsoft_throw_0()
00388 {
00389 if(NULL != *p)
00390 {
00391 (*p)->Release();
00392 *p = NULL;
00393 }
00394 }
00395 };
00396
00397
00405 struct STATSTG_policy
00406 {
00407 public:
00408 typedef STATSTG value_type;
00409
00410 public:
00415 static void init(value_type* p) stlsoft_throw_0()
00416 {
00417 p->pwcsName = NULL;
00418 }
00429 static void copy(value_type* dest, value_type const* src)
00430 {
00431 *dest = *src;
00432 if(NULL != src->pwcsName)
00433 {
00434 dest->pwcsName = olestring_dup(src->pwcsName);
00435
00436 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00437 if(NULL == dest->pwcsName)
00438 {
00439 throw com_exception("failed to copy OLE string when copying STATSTG", E_OUTOFMEMORY);
00440 }
00441 #endif
00442 };
00443 }
00448 static void clear(value_type* p) stlsoft_throw_0()
00449 {
00450 olestring_destroy(p->pwcsName);
00451 }
00452 };
00453
00454
00462 struct FORMATETC_policy
00463 {
00464 public:
00465 typedef FORMATETC value_type;
00466
00467 public:
00472 static void init(value_type* p) stlsoft_throw_0()
00473 {
00474 p->ptd = NULL;
00475 }
00486 static void copy(value_type* dest, value_type const* src)
00487 {
00488 *dest = *src;
00489 if(NULL != dest->ptd)
00490 {
00491 dest->ptd = static_cast<DVTARGETDEVICE*>(::CoTaskMemAlloc(src->ptd->tdSize));
00492
00493 if(NULL == dest->ptd)
00494 {
00495 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00496 throw com_exception("failed to copy DVTARGETDEVICE when copying FORMATETC", E_OUTOFMEMORY);
00497 #endif
00498 }
00499 else
00500 {
00501 BYTE const* src_begin = stlsoft_ns_qual(sap_cast)<BYTE const*>(&src->ptd);
00502 BYTE const* src_end = src_begin + src->ptd->tdSize;
00503 BYTE* dest_begin = stlsoft_ns_qual(sap_cast)<BYTE*>(&dest->ptd);
00504
00505 for(; src_begin != src_end; ++src_begin, ++dest_begin)
00506 {
00507 *dest_begin = *src_begin;
00508 }
00509 }
00510 }
00511 }
00516 static void clear(value_type* p) stlsoft_throw_0()
00517 {
00518 ::CoTaskMemFree(p->ptd);
00519 }
00520 };
00521
00522
00523
00524 #ifndef _COMSTL_NO_NAMESPACE
00525 # if defined(_STLSOFT_NO_NAMESPACE) || \
00526 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00527 }
00528 # else
00529 }
00530 }
00531 # endif
00532 #endif
00533
00534
00535
00536 #endif
00537
00538