1<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3<!-- 4(C) Copyright 2002-4 Robert Ramey - http://www.rrsd.com . 5Use, modification and distribution is subject to the Boost Software 6License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 7http://www.boost.org/LICENSE_1_0.txt) 8--> 9<head> 10<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 11<link rel="stylesheet" type="text/css" href="../../../boost.css"> 12<link rel="stylesheet" type="text/css" href="style.css"> 13<title>Serialization - BOOST_STATIC_WARNING</title> 14</head> 15<body link="#0000ff" vlink="#800080"> 16<table border="0" cellpadding="7" cellspacing="0" width="100%" summary="header"> 17 <tr> 18 <td valign="top" width="300"> 19 <h3><a href="../../../index.htm"><img height="86" width="277" alt="C++ Boost" src="../../../boost.png" border="0"></a></h3> 20 </td> 21 <td valign="top"> 22 <h1 align="center">Serialization</h1> 23 <h2 align="center"><code>void_cast</code></h2> 24 </td> 25 </tr> 26</table> 27<hr> 28<h3>Motivation</h3> 29C++ includes the operator <code style="white-space: normal">dynamic_cast<T>(U * u)</code> 30for casting a pointer at runtime between two related types. However, this can only be 31used for polymorphic classes. That is, it can only be used with related classes which have at least one virtual function. 32Limiting the serializaton of pointers to only such classes would diminish the applicability 33of the library. 34 35<h3>Usage</h3> 36 37The following functions are defined in the header 38<a target="void_cast" href="../../../boost/serialization/void_cast.hpp">void_cast.hpp</a>. 39They are declared in the namespace 40<code style="white-space: normal">boost::serialization</code>. 41 42<dl> 43<dt><h4><pre><code> 44template<class Derived, class Base> 45const void_cast_detail::void_caster & 46void_cast_register( 47 Derived const * derived = NULL, 48 Base * const base = NULL 49); 50</code></pre></h4></dt> 51<dd> 52This function "registers" a pair of related types. It stores the fact that 53<code style="white-space: normal">Derived</code> is immediately derived from 54<code style="white-space: normal">Base</code> in a global table. 55<ul> 56 <li>This "registration" can be invoked anywhere in the program. The table is built at 57 pre-runtime and is available anywhere else in the program. 58 <li>only adjacent base/derived pairs need be registered. That is, 59 <pre><code> 60 void_cast_register<A, B>(); 61 void_cast_register<B, C>(); 62 </code></pre> 63 automatically derives the fact that A can be upcast to C and vice-versa. 64</ul> 65</dd> 66 67<dt><h4><pre><code> 68void * 69void_upcast( 70 extended_type_info const & derived_type, 71 extended_type_info const & base_type, 72 void * const t 73); 74</code></pre></h4></dt> 75 76<dt><h4><pre><code> 77void * 78void_downcast( 79 extended_type_info const & derived_type, 80 extended_type_info const & base_type, 81 void * const t 82); 83</code></pre></h4></dt> 84<dd> 85These functions cast a void pointer from one type to another. The source and 86definition types are specified by passing references to the corresponding 87<a href="extended_type_info.html"><code style="white-space: normal"> 88extended_type_info</code></a> 89records. An attempt to cast between types not "registered" with 90<code style="white-space: normal">void_cast_register</code> 91will throw a 92<a href="exceptions.html"><code style="white-space: normal">boost::archive::archive_exception</code></a> 93with value equal to 94<code style="white-space: normal">unregistered_cast</code> 95</dd> 96</dl> 97 98<hr> 99<p><i>© Copyright <a href="http://www.rrsd.com">Robert Ramey</a> 2002-2004. 100Distributed under the Boost Software License, Version 1.0. (See 101accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 102</i></p> 103</body> 104</html> 105