DriveHQ Start Menu
Cloud Drive Mapping
Folder Sync
Cloud Backup
True Drop Box
FTP/SFTP Hosting
Group Account
DriveHQ Start Menu
Online File Server
My Storage
|
Manage Shares
|
Publishes
|
Drop Boxes
|
Group Account
WebDAV Drive Mapping
Cloud Drive Home
|
WebDAV Guide
|
Drive Mapping Tool
|
Drive Mapping URL
Complete Data Backup
Backup Guide
|
Online Backup Tool
|
Cloud-to-Cloud Backup
FTP, Email & Web Service
FTP Home
|
FTP Hosting FAQ
|
Email Hosting
|
EmailManager
|
Web Hosting
Help & Resources
About
|
Enterprise Service
|
Partnership
|
Comparisons
|
Support
Quick Links
Security and Privacy
Download Software
Service Manual
Use Cases
Group Account
Online Help
Blog
Contact
Cloud Surveillance
Sign Up
Login
Features
Business Features
Online File Server
FTP Hosting
Cloud Drive Mapping
Cloud File Backup
Email Backup & Hosting
Cloud File Sharing
Folder Synchronization
Group Management
True Drop Box
Full-text Search
AD Integration/SSO
Mobile Access
IP Camera & DVR Solution
More...
Personal Features
Personal Cloud Drive
Backup All Devices
Mobile APPs
Personal Web Hosting
Sub-Account (for Kids)
Home/PC/Kids Monitoring
More...
Software
DriveHQ Drive Mapping Tool
DriveHQ FileManager
DriveHQ Online Backup
DriveHQ Mobile Apps
Pricing
Business Plans & Pricing
Personal Plans & Pricing
Price Comparison with Others
Feature Comparison with Others
Install Mobile App
Sign up
Creating account...
Invalid character in username! Only 0-9, a-z, A-Z, _, -, . allowed.
Username is required!
Invalid email address!
E-mail is required!
Password is required!
Password is invalid!
Password and confirmation do not match.
Confirm password is required!
I accept
Membership Agreement
Please read the Membership Agreement and check "I accept"!
Free Quick Sign-up
Sign-up Page
Log in
Signing in...
Username or e-mail address is required!
Password is required!
Keep me logged in
Quick Login
Forgot Password
Up
Upload
Download
Share
Publish
New Folder
New File
Copy
Cut
Delete
Paste
Rate
Upgrade
Rotate
Effect
Edit
Slide
History
#ifndef BOOST_SMART_CAST_HPP #define BOOST_SMART_CAST_HPP // MS compatible compilers support #pragma once #if defined(_MSC_VER) && (_MSC_VER >= 1020) # pragma once #endif /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // smart_cast.hpp: // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . // Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // See http://www.boost.org/libs/serialization for updates, documentation, and revision history. // casting of pointers and references. // In casting between different C++ classes, there are a number of // rules that have to be kept in mind in deciding whether to use // static_cast or dynamic_cast. // a) dynamic casting can only be applied when one of the types is polymorphic // Otherwise static_cast must be used. // b) only dynamic casting can do runtime error checking // use of static_cast is generally un checked even when compiled for debug // c) static_cast would be considered faster than dynamic_cast. // If casting is applied to a template parameter, there is no apriori way // to know which of the two casting methods will be permitted or convenient. // smart_cast uses C++ type_traits, and program debug mode to select the // most convenient cast to use. #include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
namespace boost { namespace smart_cast_impl { template
struct reference { struct polymorphic { struct linear { template
static T cast(U & u){ return static_cast
(u); } }; struct cross { template
static T cast(U & u){ return dynamic_cast
(u); } }; template
static T cast(U & u){ // if we're in debug mode #if ! defined(NDEBUG) \ || defined(__BORLANDC__) && (__BORLANDC__ <= 0x560) \ || defined(__MWERKS__) // do a checked dynamic cast return cross::cast(u); #else // borland 5.51 chokes here so we can't use it // note: if remove_reference isn't function for these types // cross casting will be selected this will work but will // not be the most efficient method. This will conflict with // the original smart_cast motivation. typedef BOOST_DEDUCED_TYPENAME mpl::eval_if< BOOST_DEDUCED_TYPENAME mpl::and_< mpl::not_
::type, U > >, mpl::not_
::type > > >, // borland chokes w/o full qualification here mpl::identity
, mpl::identity
>::type typex; // typex works around gcc 2.95 issue return typex::cast(u); #endif } }; struct non_polymorphic { template
static T cast(U & u){ return static_cast
(u); } }; template
static T cast(U & u){ #if defined(__BORLANDC__) return mpl::eval_if< boost::is_polymorphic
, mpl::identity
, mpl::identity
>::type::cast(u); #else typedef BOOST_DEDUCED_TYPENAME mpl::eval_if< boost::is_polymorphic
, mpl::identity
, mpl::identity
>::type typex; return typex::cast(u); #endif } }; template
struct pointer { struct polymorphic { // unfortunately, this below fails to work for virtual base // classes. need has_virtual_base to do this. // Subject for further study #if 0 struct linear { template
static T cast(U * u){ return static_cast
(u); } }; struct cross { template
static T cast(U * u){ T tmp = dynamic_cast
(u); #ifndef NDEBUG if ( tmp == 0 ) throw std::bad_cast(); #endif return tmp; } }; template
static T cast(U * u){ // if we're in debug mode #if ! defined(NDEBUG) || defined(__BORLANDC__) && (__BORLANDC__ <= 0x560) // do a checked dynamic cast return cross::cast(u); #else // borland 5.51 chokes here so we can't use it // note: if remove_pointer isn't function for these types // cross casting will be selected this will work but will // not be the most efficient method. This will conflict with // the original smart_cast motivation. typedef BOOST_DEDUCED_TYPENAME mpl::eval_if< BOOST_DEDUCED_TYPENAME mpl::and_< mpl::not_
::type, U > >, mpl::not_
::type > > >, // borland chokes w/o full qualification here mpl::identity
, mpl::identity
>::type typex; return typex::cast(u); #endif } #else template
static T cast(U * u){ T tmp = dynamic_cast
(u); #ifndef NDEBUG if ( tmp == 0 ) throw std::bad_cast(); #endif return tmp; } #endif }; struct non_polymorphic { template
static T cast(U * u){ return static_cast
(u); } }; template
static T cast(U * u){ #if defined(__BORLANDC__) return mpl::eval_if< boost::is_polymorphic
, mpl::identity
, mpl::identity
>::type::cast(u); #else typedef BOOST_DEDUCED_TYPENAME mpl::eval_if< boost::is_polymorphic
, mpl::identity
, mpl::identity
>::type typex; return typex::cast(u); #endif } }; template
struct void_pointer { template
static TPtr cast(UPtr uptr){ return static_cast
(uptr); } }; template
struct error { // if we get here, its because we are using one argument in the // cast on a system which doesn't support partial template // specialization template
static T cast(U u){ BOOST_STATIC_ASSERT(sizeof(T)==0); return * static_cast
(NULL); } }; } // smart_cast_impl // this implements: // smart_cast
(Source * s) // smart_cast
(s) // note that it will fail with // smart_cast
(s) template
T smart_cast(U u) { typedef BOOST_DEDUCED_TYPENAME mpl::eval_if< BOOST_DEDUCED_TYPENAME mpl::or_< boost::is_same
, boost::is_same
, boost::is_same
, boost::is_same
>, mpl::identity
>, // else BOOST_DEDUCED_TYPENAME mpl::eval_if
, mpl::identity
>, // else BOOST_DEDUCED_TYPENAME mpl::eval_if
, mpl::identity
>, // else mpl::identity
> > > >::type typex; return typex::cast(u); } // this implements: // smart_cast_reference
(Source & s) template
T smart_cast_reference(U & u) { return smart_cast_impl::reference
::cast(u); } } // namespace boost #endif // BOOST_SMART_CAST_HPP
smart_cast.hpp
Page URL
File URL
Prev
92/113
Next
Download
( 10 KB )
Note: The DriveHQ service banners will NOT be displayed if the file owner is a paid member.
Comments
Total ratings:
0
Average rating:
Not Rated
Would you like to comment?
Join DriveHQ
for a free account, or
Logon
if you are already a member.