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_functionals.h

Go to the documentation of this file.
00001 /* 
00002  * File:        comstl_functionals.h
00003  *
00004  * Purpose:     Contains COM specific predicates and functionals.
00005  *
00006  * Created:
00007  * Updated:     11th September 2004
00008  *
00009  * Home:        http://stlsoft.org/
00010  *
00011  * Copyright (c) 2002-2004, Matthew Wilson and Synesis Software
00012  * All rights reserved.
00013  *
00014  * Redistribution and use in source and binary forms, with or without
00015  * modification, are permitted provided that the following conditions are met:
00016  *
00017  * - Redistributions of source code must retain the above copyright notice, this
00018  *   list of conditions and the following disclaimer.
00019  * - Redistributions in binary form must reproduce the above copyright notice,
00020  *   this list of conditions and the following disclaimer in the documentation
00021  *   and/or other materials provided with the distribution.
00022  * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
00023  *   any contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00027  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00029  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00030  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00031  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00032  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00033  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00034  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00035  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00036  * POSSIBILITY OF SUCH DAMAGE.
00037  *
00038  * 
00039 
00040 
00044 
00045 #ifndef COMSTL_INCL_H_COMSTL_FUNCTIONALS
00046 #define COMSTL_INCL_H_COMSTL_FUNCTIONALS
00047 
00048 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00049 # define COMSTL_VER_H_COMSTL_FUNCTIONALS_MAJOR      2
00050 # define COMSTL_VER_H_COMSTL_FUNCTIONALS_MINOR      0
00051 # define COMSTL_VER_H_COMSTL_FUNCTIONALS_REVISION   1
00052 # define COMSTL_VER_H_COMSTL_FUNCTIONALS_EDIT       37
00053 #endif /* !__STLSOFT_DOCUMENTATION_SKIP_SECTION */
00054 
00055 /* 
00056  * Includes
00057  */
00058 
00059 #ifndef COMSTL_INCL_H_COMSTL
00060 # include "comstl.h"                    // Include the COMSTL root header
00061 #endif /* !COMSTL_INCL_H_COMSTL */
00062 #ifndef COMSTL_INCL_H_COMSTL_REFCOUNT_FUNCTIONS
00063 # include "comstl_refcount_functions.h" // safe_addref, safe_release
00064 #endif /* !COMSTL_INCL_H_COMSTL_REFCOUNT_FUNCTIONS */
00065 #include <functional>
00066 
00067 /* 
00068  * Namespace
00069  *
00070  * The COMSTL components are contained within the comstl namespace. This is
00071  * actually an alias for stlsoft::comstl_project,
00072  *
00073  * The definition matrix is as follows:
00074  *
00075  * _STLSOFT_NO_NAMESPACE    _COMSTL_NO_NAMESPACE    comstl definition
00076  * ---------------------    --------------------    -----------------
00077  *  not defined              not defined             = stlsoft::comstl_project
00078  *  not defined              defined                 not defined
00079  *  defined                  not defined             comstl
00080  *  defined                  defined                 not defined
00081  *
00082  */
00083 
00084 #ifndef _COMSTL_NO_NAMESPACE
00085 # if defined(_STLSOFT_NO_NAMESPACE) || \
00086      defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00087 /* There is no stlsoft namespace, so must define ::comstl */
00088 namespace comstl
00089 {
00090 # else
00091 /* Define stlsoft::comstl_project */
00092 
00093 namespace stlsoft
00094 {
00095 
00096 namespace comstl_project
00097 {
00098 
00099 # endif /* _STLSOFT_NO_NAMESPACE */
00100 #endif /* !_COMSTL_NO_NAMESPACE */
00101 
00102 /* 
00103  * Functionals
00104  */
00105 
00113 template <ss_typename_param_k I>
00114 struct interface_release
00115     : public comstl_ns_qual_std(unary_function)<I*, void>
00116 {
00117 public:
00118     typedef I   interface_type;
00119 
00123     void operator ()(interface_type *pi)
00124     {
00125         safe_release(pi);
00126     }
00127 };
00128 
00136 template <ss_typename_param_k I>
00137 struct interface_addref
00138     : public comstl_ns_qual_std(unary_function)<I*, void>
00139 {
00140 public:
00141     typedef I   interface_type;
00142 
00146     void operator ()(interface_type *pi)
00147     {
00148         safe_addref(pi);
00149     }
00150 };
00151 
00158 template< ss_typename_param_k R
00159         , ss_typename_param_k T
00160         >
00161 class std_mem_fun_t
00162     : public comstl_ns_qual_std(unary_function)<T*, R>
00163 {
00164 public:
00165     typedef R                               return_type;
00166     typedef T                               operand_class_type;
00167     typedef return_type (STDAPICALLTYPE T::*method_type)();
00168 
00169 public:
00173     ss_explicit_k std_mem_fun_t(method_type f)
00174         : m_f(f)
00175     {}
00176 
00180     return_type operator ()(operand_class_type *pt) const
00181     {
00182         return (pt->*m_f)();
00183     }
00184 
00185 private:
00186     method_type m_f;
00187 };
00188 
00190 template <class R, class T>
00191 inline std_mem_fun_t<R, T> std_mem_fun(R (STDAPICALLTYPE T::*f)())
00192 {
00193     return std_mem_fun_t<R, T>(f);
00194 }
00195 
00202 template< ss_typename_param_k R
00203         , ss_typename_param_k T
00204         >
00205 class std_mem_fun_ref_t
00206     : public comstl_ns_qual_std(unary_function)<T&, R>
00207 {
00208 public:
00209     typedef R                               return_type;
00210     typedef T                               operand_class_type;
00211     typedef return_type (STDAPICALLTYPE T::*method_type)();
00212 
00213 public:
00217     ss_explicit_k std_mem_fun_ref_t(method_type f)
00218         : m_f(f)
00219     {}
00220 
00224     return_type operator ()(operand_class_type &t) const
00225     {
00226         return (t.*m_f)();
00227     }
00228 
00229 private:
00230     method_type m_f;
00231 };
00232 
00234 template <class R, class T>
00235 inline std_mem_fun_ref_t<R, T> std_mem_fun_ref(R (STDAPICALLTYPE T::*f)())
00236 {
00237     return std_mem_fun_ref_t<R, T>(f);
00238 }
00239 
00240 
00245 struct BSTR_close
00246     : public comstl_ns_qual_std(unary_function)<BSTR, void>
00247 {
00251    void operator ()(BSTR s) const
00252     {
00253         ::SysFreeString(s);
00254     }
00255 };
00256 
00261 struct olestring_close
00262     : public comstl_ns_qual_std(unary_function)<LPOLESTR, void>
00263 {
00267     void operator ()(LPOLESTR s) const
00268     {
00269         ::CoTaskMemFree(s);
00270     }
00271 };
00272 
00277 struct task_memory_close
00278     : public comstl_ns_qual_std(unary_function)<void *, void>
00279 {
00283     void operator ()(void *p) const
00284     {
00285         ::CoTaskMemFree(p);
00286     }
00287 };
00288 
00293 struct VARIANT_close
00294     : public comstl_ns_qual_std(unary_function)<VARIANT&, void>
00295 {
00299     void operator ()(VARIANT &v) const
00300     {
00301         ::VariantClear(&v);
00302     }
00303 };
00304 
00306 // Unit-testing
00307 
00308 #ifdef STLSOFT_UNITTEST
00309 
00310 namespace unittest
00311 {
00312     ss_bool_t test_comstl_functionals(unittest_reporter *r)
00313     {
00314         using stlsoft::unittest::unittest_initialiser;
00315 
00316         ss_bool_t               bSuccess    =   true;
00317 
00318         unittest_initialiser    init(r, "COMSTL", "functionals", __FILE__);
00319 
00320 #if 0
00321         if(<<TODO>>)
00322         {
00323             r->report("<<TODO>> failed ", __LINE__);
00324             bSuccess = false;
00325         }
00326 #endif /* 0 */
00327 
00328         return bSuccess;
00329     }
00330 
00331     unittest_registrar    unittest_comstl_functionals(test_comstl_functionals);
00332 
00333 } // namespace unittest
00334 
00335 #endif /* STLSOFT_UNITTEST */
00336 
00337 /* 
00338 
00339 #ifndef _COMSTL_NO_NAMESPACE
00340 # if defined(_STLSOFT_NO_NAMESPACE) || \
00341      defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00342 } // namespace comstl
00343 # else
00344 } // namespace comstl_project
00345 } // namespace stlsoft
00346 # endif /* _STLSOFT_NO_NAMESPACE */
00347 #endif /* !_COMSTL_NO_NAMESPACE */
00348 
00349 /* 
00350 
00351 #endif /* !COMSTL_INCL_H_COMSTL_FUNCTIONALS */
00352 
00353 /* 

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