STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ... ATLSTL - Template Software for the Active Template Library COMSTL - The Standard Template Library meets the Component Object Model .netSTL - Standard Template Library meets the Microsoft.NET Common Language Runtime InetSTL - The Standard Template Library meets WinInet MFCSTL - Template Software for the Microsoft Foundation Classes UNIXSTL - Template Software for the UNIX Operating System WinSTL - where the Standard Template Library meets the Win32 API

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

comstl_value_policies.h

Go to the documentation of this file.
00001 /* 
00002  * File:        comstl_value_policies.h (originally MOEnSeq.h, ::SynesisCom)
00003  *
00004  * Purpose:     Value policies that work with STL sequence types for IEnumXXXX
00005  *              enumerator interfaces.
00006  *
00007  * Created:     17th September 1998
00008  * Updated:     11th September 2004
00009  *
00010  * Home:        http://stlsoft.org/
00011  *
00012  * Copyright (c) 1998-2004, Matthew Wilson and Synesis Software
00013  * All rights reserved.
00014  *
00015  * Redistribution and use in source and binary forms, with or without
00016  * modification, are permitted provided that the following conditions are met:
00017  *
00018  * - Redistributions of source code must retain the above copyright notice, this
00019  *   list of conditions and the following disclaimer.
00020  * - Redistributions in binary form must reproduce the above copyright notice,
00021  *   this list of conditions and the following disclaimer in the documentation
00022  *   and/or other materials provided with the distribution.
00023  * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
00024  *   any contributors may be used to endorse or promote products derived from
00025  *   this software without specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00028  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00031  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00032  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00033  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00034  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00035  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00036  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00037  * POSSIBILITY OF SUCH DAMAGE.
00038  *
00039  * 
00040 
00041 
00045 
00046 #ifndef COMSTL_INCL_H_COMSTL_VALUE_POLICIES
00047 #define COMSTL_INCL_H_COMSTL_VALUE_POLICIES
00048 
00049 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00050 # define COMSTL_VER_H_COMSTL_VALUE_POLICIES_MAJOR       3
00051 # define COMSTL_VER_H_COMSTL_VALUE_POLICIES_MINOR       0
00052 # define COMSTL_VER_H_COMSTL_VALUE_POLICIES_REVISION    1
00053 # define COMSTL_VER_H_COMSTL_VALUE_POLICIES_EDIT        143
00054 #endif /* !__STLSOFT_DOCUMENTATION_SKIP_SECTION */
00055 
00056 /* 
00057  * Includes
00058  */
00059 
00060 #ifndef COMSTL_INCL_H_COMSTL
00061 # include "comstl.h"                       // Include the COMSTL root header
00062 #endif /* !COMSTL_INCL_H_COMSTL */
00063 #ifndef COMSTL_INCL_H_COMSTL_REFCOUNT_FUNCTIONS
00064 # include "comstl_refcount_functions.h"    // safe_release, etc.
00065 #endif /* !COMSTL_INCL_H_COMSTL_REFCOUNT_FUNCTIONS */
00066 #ifndef COMSTL_INCL_H_COMSTL_OLESTRING_FUNCTIONS
00067 # include "comstl_olestring_functions.h"   // olestring_dup, etc.
00068 #endif /* !COMSTL_INCL_H_COMSTL_OLESTRING_FUNCTIONS */
00069 #ifndef STLSOFT_INCL_H_STLSOFT_SAP_CAST
00070 # include "stlsoft_sap_cast.h"
00071 #endif /* !STLSOFT_INCL_H_STLSOFT_SAP_CAST */
00072 
00073 /* 
00074  * Namespace
00075  *
00076  * The COMSTL components are contained within the comstl namespace. This is
00077  * actually an alias for stlsoft::comstl_project,
00078  *
00079  * The definition matrix is as follows:
00080  *
00081  * _STLSOFT_NO_NAMESPACE    _COMSTL_NO_NAMESPACE    comstl definition
00082  * ---------------------    --------------------    -----------------
00083  *  not defined              not defined             = stlsoft::comstl_project
00084  *  not defined              defined                 not defined
00085  *  defined                  not defined             comstl
00086  *  defined                  defined                 not defined
00087  *
00088  */
00089 
00090 #ifndef _COMSTL_NO_NAMESPACE
00091 # if defined(_STLSOFT_NO_NAMESPACE) || \
00092      defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00093 /* There is no stlsoft namespace, so must define ::comstl */
00094 namespace comstl
00095 {
00096 # else
00097 /* Define stlsoft::comstl_project */
00098 
00099 namespace stlsoft
00100 {
00101 
00102 namespace comstl_project
00103 {
00104 
00105 # endif /* _STLSOFT_NO_NAMESPACE */
00106 #endif /* !_COMSTL_NO_NAMESPACE */
00107 
00108 /* 
00109 
00114 
00115 /* 
00116  * Classes
00117  */
00118 
00120 struct GUID_policy
00121 {
00122 public:
00123     typedef GUID        value_type;
00124 
00125 public:
00127     static void init(value_type *)
00128     {}
00130     static void copy(value_type *dest, value_type const *src)
00131     {
00132         *dest = *src;
00133     }
00135     static void clear(value_type *)
00136     {}
00137 };
00138 
00139 
00141 struct BSTR_policy
00142 {
00143 public:
00144     typedef BSTR    value_type;
00145 
00146 public:
00148     static void init(value_type *p)
00149     {
00150         *p = NULL;
00151     }
00153     static void copy(value_type *dest, value_type const *src)
00154     {
00155         *dest = ::SysAllocString(*src);
00156     }
00158     static void clear(value_type *p)
00159     {
00160         ::SysFreeString(*p);
00161     }
00162 };
00163 
00164 
00166 struct LPOLESTR_policy
00167 {
00168 public:
00169     typedef LPOLESTR    value_type;
00170 
00171 public:
00173     static void init(value_type *p)
00174     {
00175         *p = NULL;
00176     }
00178     static void copy(value_type *dest, value_type const *src)
00179     {
00180         *dest = olestring_dup(*src);
00181     }
00183     static void clear(value_type *p)
00184     {
00185         olestring_destroy(*p);
00186     }
00187 };
00188 
00189 
00191 struct VARIANT_policy
00192 {
00193 public:
00194     typedef VARIANT value_type;
00195 
00196 public:
00198     static void init(value_type *p)
00199     {
00200         ::VariantInit(p);
00201     }
00203     static void copy(value_type *dest, value_type const *src)
00204     {
00205         ::VariantCopy(dest, const_cast<VARIANT*>(src));
00206     }
00208     static void clear(value_type *p)
00209     {
00210         ::VariantClear(p);
00211     }
00212 };
00213 
00214 
00218 template <ss_typename_param_k I>
00219 struct interface_policy
00220 {
00221 public:
00222     typedef I               interface_type;
00223     typedef interface_type  *value_type;
00224 
00225 public:
00227     static void init(value_type *p)
00228     {
00229         *p = NULL;
00230     }
00232     static void copy(value_type *dest, value_type const *src)
00233     {
00234         *dest = *src;
00235         safe_addref(*dest);
00236     }
00238     static void clear(value_type *p)
00239     {
00240         release_set_null(*p);
00241     }
00242 };
00243 
00244 
00246 struct LPUNKNOWN_policy
00247 {
00248 public:
00249     typedef LPUNKNOWN   value_type;
00250 
00251 public:
00253     static void init(value_type *p)
00254     {
00255         *p = NULL;
00256     }
00258     static void copy(value_type *dest, value_type const *src)
00259     {
00260         *dest = *src;
00261         safe_addref(*dest);
00262     }
00264     static void clear(value_type *p)
00265     {
00266         release_set_null(*p);
00267     }
00268 };
00269 
00270 
00272 struct STATSTG_policy
00273 {
00274 public:
00275     typedef STATSTG value_type;
00276 
00277 public:
00279     static void init(value_type *p)
00280     {
00281         p->pwcsName = NULL;
00282     }
00284     static void copy(value_type *dest, value_type const *src)
00285     {
00286         *dest = *src;
00287         if(src->pwcsName != NULL)
00288         {
00289             dest->pwcsName = olestring_dup(src->pwcsName);
00290         };
00291     }
00293     static void clear(value_type *p)
00294     {
00295         olestring_destroy(p->pwcsName);
00296     }
00297 };
00298 
00299 
00301 struct FORMATETC_policy
00302 {
00303 public:
00304     typedef FORMATETC   value_type;
00305 
00306 public:
00308     static void init(value_type *p)
00309     {
00310         p->ptd  =   NULL;
00311     }
00313     static void copy(value_type *dest, value_type const *src)
00314     {
00315         *dest = *src;
00316         if(dest->ptd != NULL)
00317         {
00318             dest->ptd = static_cast<DVTARGETDEVICE*>(::CoTaskMemAlloc(src->ptd->tdSize));
00319 
00320             if(dest->ptd != NULL)
00321             {
00322                 BYTE const  *src_begin  =   stlsoft_ns_qual(sap_cast)<BYTE const*>(&src->ptd);
00323                 BYTE const  *src_end    =   src_begin + src->ptd->tdSize;
00324                 BYTE        *dest_begin =   stlsoft_ns_qual(sap_cast)<BYTE*>(&dest->ptd);
00325 
00326                 for(; src_begin != src_end; ++src_begin, ++dest_begin)
00327                 {
00328                     *dest_begin = *src_begin;
00329                 }
00330             }
00331         }
00332     }
00334     static void clear(value_type *p)
00335     {
00336         ::CoTaskMemFree(p->ptd);
00337     }
00338 };
00339 
00340 /* 
00341 
00343 
00344 /* 
00345 
00346 #ifndef _COMSTL_NO_NAMESPACE
00347 # if defined(_STLSOFT_NO_NAMESPACE) || \
00348      defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00349 } // namespace comstl
00350 # else
00351 } // namespace stlsoft::comstl_project
00352 } // namespace stlsoft
00353 # endif /* _STLSOFT_NO_NAMESPACE */
00354 #endif /* !_COMSTL_NO_NAMESPACE */
00355 
00356 /* 
00357 
00358 #endif /* !COMSTL_INCL_H_COMSTL_VALUE_POLICIES */
00359 
00360 /* 

STLSoft Libraries documentation © Synesis Software Pty Ltd, 2001-2004