00001 /* ///////////////////////////////////////////////////////////////////////// 00002 * File: dotnetstl/conversion/check_cast.hpp 00003 * 00004 * Purpose: A cast operator function that performs runtime verification 00005 * on the cast instance in debug builds. 00006 * 00007 * Created: 9th August 2006 00008 * Updated: 10th August 2009 00009 * 00010 * Home: http://stlsoft.org/ 00011 * 00012 * Copyright (c) 2006-2009, 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 00048 #ifndef DOTNETSTL_INCL_DOTNETSTL_CONVERSION_HPP_CHECK_CAST 00049 #define DOTNETSTL_INCL_DOTNETSTL_CONVERSION_HPP_CHECK_CAST 00050 00051 #ifndef DOTNETSTL_DOCUMENTATION_SKIP_SECTION 00052 # define DOTNETSTL_VER_DOTNETSTL_CONVERSION_HPP_CHECK_CAST_MAJOR 1 00053 # define DOTNETSTL_VER_DOTNETSTL_CONVERSION_HPP_CHECK_CAST_MINOR 0 00054 # define DOTNETSTL_VER_DOTNETSTL_CONVERSION_HPP_CHECK_CAST_REVISION 1 00055 # define DOTNETSTL_VER_DOTNETSTL_CONVERSION_HPP_CHECK_CAST_EDIT 4 00056 #endif /* !DOTNETSTL_DOCUMENTATION_SKIP_SECTION */ 00057 00058 /* ///////////////////////////////////////////////////////////////////////// 00059 * Includes 00060 */ 00061 00062 #ifndef DOTNETSTL_INCL_DOTNETSTL_HPP_DOTNETSTL 00063 # include <dotnetstl/dotnetstl.hpp> 00064 #endif /* !DOTNETSTL_INCL_DOTNETSTL_HPP_DOTNETSTL */ 00065 00066 #ifdef STLSOFT_UNITTEST 00067 # include <exception> 00068 #endif /* STLSOFT_UNITTEST */ 00069 00070 /* ///////////////////////////////////////////////////////////////////////// 00071 * Namespace 00072 */ 00073 00074 #ifdef _STLSOFT_NO_NAMESPACE 00075 /* There is no stlsoft namespace, so must define ::dotnetstl */ 00076 namespace dotnetstl 00077 { 00078 #else 00079 /* Define stlsoft::dotnet_project */ 00080 00081 namespace stlsoft 00082 { 00083 00084 namespace dotnetstl_project 00085 { 00086 00087 #endif /* _STLSOFT_NO_NAMESPACE */ 00088 00089 /* ///////////////////////////////////////////////////////////////////////// 00090 * Functions 00091 */ 00092 00101 template< ss_typename_param_k TO 00102 , ss_typename_param_k FROM 00103 > 00104 inline TO check_cast(FROM from) 00105 { 00106 #ifdef _DEBUG 00107 return __try_cast<TO>(from); 00108 #else // ? _DEBUG 00109 return static_cast<TO>(from); 00110 #endif // _DEBUG 00111 } 00112 00114 // Unit-testing 00115 00116 #ifdef STLSOFT_UNITTEST 00117 # include "./unittest/check_cast_unittest_.h" 00118 #endif /* STLSOFT_UNITTEST */ 00119 00120 /* ////////////////////////////////////////////////////////////////////// */ 00121 00122 #ifdef _STLSOFT_NO_NAMESPACE 00123 } // namespace dotnetstl 00124 #else 00125 } // namespace dotnetstl_project 00126 } // namespace stlsoft 00127 #endif /* _STLSOFT_NO_NAMESPACE */ 00128 00129 /* ////////////////////////////////////////////////////////////////////// */ 00130 00131 #endif /* !STLSOFT_INCL_STLSOFT_CONVERSION_HPP_CHECK_CAST */ 00132 00133 /* ///////////////////////////// end of file //////////////////////////// */