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  

stlsoft_conversion_veneer.h

Go to the documentation of this file.
00001 /* 
00002  * File:        stlsoft_conversion_veneer.h
00003  *
00004  * Purpose:     Raw conversion veneer class.
00005  *
00006  * Created:     30th July 2002
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 STLSOFT_INCL_H_STLSOFT_CONVERSION_VENEER
00046 #define STLSOFT_INCL_H_STLSOFT_CONVERSION_VENEER
00047 
00048 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00049 # define STLSOFT_VER_H_STLSOFT_CONVERSION_VENEER_MAJOR      2
00050 # define STLSOFT_VER_H_STLSOFT_CONVERSION_VENEER_MINOR      0
00051 # define STLSOFT_VER_H_STLSOFT_CONVERSION_VENEER_REVISION   1
00052 # define STLSOFT_VER_H_STLSOFT_CONVERSION_VENEER_EDIT       30
00053 #endif /* !__STLSOFT_DOCUMENTATION_SKIP_SECTION */
00054 
00055 /* 
00056  * Includes
00057  */
00058 
00059 #ifndef STLSOFT_INCL_H_STLSOFT
00060 # include "stlsoft.h"               // Include the STLSoft root header
00061 #endif /* !STLSOFT_INCL_H_STLSOFT */
00062 #ifndef STLSOFT_INCL_H_STLSOFT_CONSTRAINTS
00063 # include "stlsoft_constraints.h"   // must_be_same_size constraint
00064 #endif /* !STLSOFT_INCL_H_STLSOFT_CONSTRAINTS */
00065 
00066 /* 
00067  * Namespace
00068  */
00069 
00070 #ifndef _STLSOFT_NO_NAMESPACE
00071 namespace stlsoft
00072 {
00073 #endif /* _STLSOFT_NO_NAMESPACE */
00074 
00075 /* 
00076  * Classes
00077  */
00078 
00079 // class invalid_conversion
00084 template<   ss_typename_param_k T
00085         ,   ss_typename_param_k C
00086         >
00087 struct invalid_conversion
00088 {
00089 protected:
00091     typedef void    invalid_type;
00092 public:
00094     typedef T       value_type;
00096     typedef C       conversion_type;
00097 
00098 public:
00100     static invalid_type convert_pointer(value_type * /* pv */)
00101     {}
00102 
00104     static invalid_type convert_const_pointer(value_type const * /* pv */)
00105     {}
00106 
00108     static invalid_type convert_reference(value_type &/* v */)
00109     {}
00110 
00112     static invalid_type convert_const_reference(value_type const &/* v */)
00113     {}
00114 
00116     struct pointer_conversion
00117     {
00118         invalid_type operator ()(value_type * /* pv */)
00119         {}
00120     };
00121 
00123     struct pointer_const_conversion
00124     {
00125         invalid_type operator ()(value_type const * /* pv */)
00126         {}
00127     };
00128 
00130     struct reference_conversion
00131     {
00132         invalid_type operator ()(value_type &/* v */)
00133         {}
00134     };
00135 
00137     struct reference_const_conversion
00138     {
00139         invalid_type operator ()(value_type const &/* v */)
00140         {}
00141     };
00142 
00143 };
00144 
00145 // class static_conversion
00150 template<   ss_typename_param_k T
00151         ,   ss_typename_param_k C
00152         >
00153 struct static_conversion
00154 {
00155 public:
00157     typedef T       value_type;
00159     typedef C       conversion_type;
00160 
00161 public:
00163     static conversion_type *convert_pointer(value_type *pv)
00164     {
00165         return static_cast<conversion_type*>(pv);
00166     }
00167 
00169     static conversion_type const *convert_const_pointer(value_type const *pv)
00170     {
00171         return static_cast<conversion_type const*>(pv);
00172     }
00173 
00175     static conversion_type &convert_reference(value_type &v)
00176     {
00177         return static_cast<conversion_type&>(v);
00178     }
00179 
00181     static conversion_type const &convert_const_reference(value_type const &v)
00182     {
00183         return static_cast<conversion_type const&>(v);
00184     }
00185 
00187     struct pointer_conversion
00188     {
00189         conversion_type *operator ()(value_type *pv)
00190         {
00191             return convert_pointer(pv);
00192         }
00193     };
00194 
00196     struct pointer_const_conversion
00197     {
00198         conversion_type const *operator ()(value_type const *pv)
00199         {
00200             return convert_const_pointer(pv);
00201         }
00202     };
00203 
00205     struct reference_conversion
00206     {
00207         conversion_type &operator ()(value_type &v)
00208         {
00209             return convert_reference(v);
00210         }
00211     };
00212 
00214     struct reference_const_conversion
00215     {
00216         conversion_type const &operator ()(value_type const &v)
00217         {
00218             return convert_const_reference(v);
00219         }
00220     };
00221 
00222 };
00223 
00224 // class dynamic_conversion
00229 template<   ss_typename_param_k T
00230         ,   ss_typename_param_k C
00231         >
00232 struct dynamic_conversion
00233 {
00234 public:
00236     typedef T       value_type;
00238     typedef C       conversion_type;
00239 
00240 public:
00242     static conversion_type *convert_pointer(value_type *pv)
00243     {
00244         return dynamic_cast<conversion_type*>(pv);
00245     }
00246 
00248     static conversion_type const *convert_const_pointer(value_type const *pv)
00249     {
00250         return dynamic_cast<conversion_type const*>(pv);
00251     }
00252 
00254     static conversion_type &convert_reference(value_type &v)
00255     {
00256         return dynamic_cast<conversion_type&>(v);
00257     }
00258 
00260     static conversion_type const &convert_const_reference(value_type const &v)
00261     {
00262         return dynamic_cast<conversion_type const&>(v);
00263     }
00264 
00266     struct pointer_conversion
00267     {
00268         conversion_type *operator ()(value_type *pv)
00269         {
00270             return convert_pointer(pv);
00271         }
00272     };
00273 
00275     struct pointer_const_conversion
00276     {
00277         conversion_type const *operator ()(value_type const *pv)
00278         {
00279             return convert_const_pointer(pv);
00280         }
00281     };
00282 
00284     struct reference_conversion
00285     {
00286         conversion_type &operator ()(value_type &v)
00287         {
00288             return convert_reference(v);
00289         }
00290     };
00291 
00293     struct reference_const_conversion
00294     {
00295         conversion_type const &operator ()(value_type const &v)
00296         {
00297             return convert_const_reference(v);
00298         }
00299     };
00300 
00301 };
00302 
00303 // class reinterpret_conversion
00308 template<   ss_typename_param_k T
00309         ,   ss_typename_param_k C
00310         >
00311 struct reinterpret_conversion
00312 {
00313 public:
00315     typedef T       value_type;
00317     typedef C       conversion_type;
00318 
00319 public:
00321     static conversion_type *convert_pointer(value_type *pv)
00322     {
00323         return reinterpret_cast<conversion_type*>(pv);
00324     }
00325 
00327     static conversion_type const *convert_const_pointer(value_type const *pv)
00328     {
00329         return reinterpret_cast<conversion_type const*>(pv);
00330     }
00331 
00333     static conversion_type &convert_reference(value_type &v)
00334     {
00335         return reinterpret_cast<conversion_type&>(v);
00336     }
00337 
00339     static conversion_type const &convert_const_reference(value_type const &v)
00340     {
00341         return reinterpret_cast<conversion_type const&>(v);
00342     }
00343 
00345     struct pointer_conversion
00346     {
00347         conversion_type *operator ()(value_type *pv)
00348         {
00349             return convert_pointer(pv);
00350         }
00351     };
00352 
00354     struct pointer_const_conversion
00355     {
00356         conversion_type const *operator ()(value_type const *pv)
00357         {
00358             return convert_const_pointer(pv);
00359         }
00360     };
00361 
00363     struct reference_conversion
00364     {
00365         conversion_type &operator ()(value_type &v)
00366         {
00367             return convert_reference(v);
00368         }
00369     };
00370 
00372     struct reference_const_conversion
00373     {
00374         conversion_type const &operator ()(value_type const &v)
00375         {
00376             return convert_const_reference(v);
00377         }
00378     };
00379 
00380 };
00381 
00382 // class c_conversion
00387 template<   ss_typename_param_k T
00388         ,   ss_typename_param_k C
00389         >
00390 struct c_conversion
00391 {
00392 public:
00394     typedef T       value_type;
00396     typedef C       conversion_type;
00397 
00398 public:
00400     static conversion_type *convert_pointer(value_type *pv)
00401     {
00402         return (conversion_type*)(pv);
00403     }
00404 
00406     static conversion_type const *convert_const_pointer(value_type const *pv)
00407     {
00408         return (conversion_type const*)(pv);
00409     }
00410 
00412     static conversion_type &convert_reference(value_type &v)
00413     {
00414         return (conversion_type&)(v);
00415     }
00416 
00418     static conversion_type const &convert_const_reference(value_type const &v)
00419     {
00420         return (conversion_type const&)(v);
00421     }
00422 
00424     struct pointer_conversion
00425     {
00426         conversion_type *operator ()(value_type *pv)
00427         {
00428             return convert_pointer(pv);
00429         }
00430     };
00431 
00433     struct pointer_const_conversion
00434     {
00435         conversion_type const *operator ()(value_type const *pv)
00436         {
00437             return convert_const_pointer(pv);
00438         }
00439     };
00440 
00442     struct reference_conversion
00443     {
00444         conversion_type &operator ()(value_type &v)
00445         {
00446             return convert_reference(v);
00447         }
00448     };
00449 
00451     struct reference_const_conversion
00452     {
00453         conversion_type const &operator ()(value_type const &v)
00454         {
00455             return convert_const_reference(v);
00456         }
00457     };
00458 
00459 };
00460 
00461 // class conversion_veneer
00471 template<   ss_typename_param_k T
00472         ,   ss_typename_param_k C
00473 #ifdef __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_FUNDAMENTAL_ARGUMENT_SUPPORT
00474         ,   ss_typename_param_k V = T
00475         ,   ss_typename_param_k P = invalid_conversion<T, C>
00476         ,   ss_typename_param_k R = invalid_conversion<T, C>
00477         ,   ss_typename_param_k PC = P
00478         ,   ss_typename_param_k RC = R
00479 #else
00480         ,   ss_typename_param_k V
00481         ,   ss_typename_param_k P
00482         ,   ss_typename_param_k R
00483         ,   ss_typename_param_k PC
00484         ,   ss_typename_param_k RC
00485 #endif /* __STLSOFT_CF_TEMPLATE_CLASS_DEFAULT_FUNDAMENTAL_ARGUMENT_SUPPORT */
00486         >
00487 class conversion_veneer
00488     : public T
00489 {
00490 public:
00492     typedef T                                                   parent_class_type;
00494     typedef C                                                   conversion_type;
00496     typedef V                                                   value_type;
00498     typedef ss_typename_type_k P::pointer_conversion            pointer_conversion_type;
00500     typedef ss_typename_type_k R::reference_conversion          reference_conversion_type;
00502     typedef ss_typename_type_k PC::pointer_const_conversion     pointer_const_conversion_type;
00504     typedef ss_typename_type_k RC::reference_const_conversion   reference_const_conversion_type;
00506     typedef conversion_veneer<T, C, V, P, R, PC, RC>            class_type;
00507 
00508 // Construction
00509 public:
00511     conversion_veneer()
00512     {
00513         stlsoft_constraint_must_be_same_size(T, class_type);
00514     }
00515 
00517     conversion_veneer(class_type const &rhs)
00518         : parent_class_type(rhs)
00519     {
00520         stlsoft_constraint_must_be_same_size(T, class_type);
00521     }
00522 
00524     conversion_veneer(value_type const &rhs)
00525         : parent_class_type(rhs)
00526     {
00527         stlsoft_constraint_must_be_same_size(T, class_type);
00528     }
00529 
00530 #ifdef __STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
00531     // For compilers that support member templates, the following constructors
00532     // are provided.
00533 
00535     template <ss_typename_param_k N1>
00536     ss_explicit_k conversion_veneer(N1 &n1)
00537         : parent_class_type(n1)
00538     {}
00540     template <ss_typename_param_k N1>
00541     ss_explicit_k conversion_veneer(N1 *n1)
00542         : parent_class_type(n1)
00543     {}
00544 
00546     template <ss_typename_param_k N1, ss_typename_param_k N2>
00547     conversion_veneer(N1 n1, N2 n2)
00548         : parent_class_type(n1, n2)
00549     {}
00550 
00552     template <ss_typename_param_k N1, ss_typename_param_k N2, ss_typename_param_k N3>
00553     conversion_veneer(N1 n1, N2 n2, N3 n3)
00554         : parent_class_type(n1, n2, n3)
00555     {}
00556 
00558     template <ss_typename_param_k N1, ss_typename_param_k N2, ss_typename_param_k N3, ss_typename_param_k N4>
00559     conversion_veneer(N1 n1, N2 n2, N3 n3, N4 n4)
00560         : parent_class_type(n1, n2, n3, n4)
00561     {}
00562 
00564     template <ss_typename_param_k N1, ss_typename_param_k N2, ss_typename_param_k N3, ss_typename_param_k N4, ss_typename_param_k N5>
00565     conversion_veneer(N1 n1, N2 n2, N3 n3, N4 n4, N5 n5)
00566         : parent_class_type(n1, n2, n3, n4, n5)
00567     {}
00568 
00570     template <ss_typename_param_k N1, ss_typename_param_k N2, ss_typename_param_k N3, ss_typename_param_k N4, ss_typename_param_k N5, ss_typename_param_k N6>
00571     conversion_veneer(N1 n1, N2 n2, N3 n3, N4 n4, N5 n5, N6 n6)
00572         : parent_class_type(n1, n2, n3, n4, n5, n6)
00573     {}
00574 
00576     template <ss_typename_param_k N1, ss_typename_param_k N2, ss_typename_param_k N3, ss_typename_param_k N4, ss_typename_param_k N5, ss_typename_param_k N6, ss_typename_param_k N7>
00577     conversion_veneer(N1 n1, N2 n2, N3 n3, N4 n4, N5 n5, N6 n6, N7 n7)
00578         : parent_class_type(n1, n2, n3, n4, n5, n6, n7)
00579     {}
00580 
00582     template <ss_typename_param_k N1, ss_typename_param_k N2, ss_typename_param_k N3, ss_typename_param_k N4, ss_typename_param_k N5, ss_typename_param_k N6, ss_typename_param_k N7, ss_typename_param_k N8>
00583     conversion_veneer(N1 n1, N2 n2, N3 n3, N4 n4, N5 n5, N6 n6, N7 n7, N8 n8)
00584         : parent_class_type(n1, n2, n3, n4, n5, n6, n7, n8)
00585     {}
00586 #endif // __STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT
00587 
00589     class_type &operator =(class_type const &rhs)
00590     {
00591         static_cast<parent_class_type&>(*this) = rhs;
00592 
00593         return *this;
00594     }
00595 
00597     class_type &operator =(value_type const &rhs)
00598     {
00599         static_cast<parent_class_type&>(*this) = rhs;
00600 
00601         return *this;
00602     }
00603 
00604 #ifdef __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00605 
00606     template <ss_typename_param_k T1>
00607     class_type &operator =(T1 rhs)
00608     {
00609         static_cast<parent_class_type&>(*this) = rhs;
00610 
00611         return *this;
00612     }
00613 #endif // __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00614 
00615     // Note that the copy constructor is not defined, and will NOT be defined copy ctor/operator not made
00616 
00617 // Conversions
00618 public:
00620     operator conversion_type &()
00621     {
00622         return reference_conversion_type()(*this);
00623     }
00625     operator conversion_type const &() const
00626     {
00627         return reference_const_conversion_type()(*this);
00628     }
00629 
00631     conversion_type * operator &()
00632     {
00633         // Take a local reference, such that the application of the address-of
00634         // operator will allow user-defined conversions of the parent_class_type
00635         // to be applied.
00636         parent_class_type   &_this  =   *this;
00637 
00638         return pointer_conversion_type()(&_this);
00639     }
00641     conversion_type const * operator &() const
00642     {
00643         // Take a local reference, such that the application of the address-of
00644         // operator will allow user-defined conversions of the parent_class_type
00645         // to be applied.
00646         parent_class_type const &_this  =   *this;
00647 
00648         return pointer_const_conversion_type()(&_this);
00649     }
00650 };
00651 
00652 /* 
00653 
00654 #ifndef _STLSOFT_NO_NAMESPACE
00655 } // namespace stlsoft
00656 #endif /* _STLSOFT_NO_NAMESPACE */
00657 
00658 /* 
00659 
00660 #endif /* !STLSOFT_INCL_H_STLSOFT_CONVERSION_VENEER */
00661 
00662 /* 

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