Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/express/dcast.cxx

Go to the documentation of this file.
00001 // Filename: dcast.cxx
00002 // Created by:  drose (07Aug01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "dcast.h"
00020 #include "config_express.h"
00021 
00022 #ifdef _WIN32
00023 #include <windows.h>  // for IsBadWritePtr()
00024 #endif
00025 
00026 
00027 #ifndef NDEBUG
00028 ////////////////////////////////////////////////////////////////////
00029 //     Function: _dcast_verify
00030 //  Description: This function performs the actual check that the
00031 //               indicated TypedObject pointer is of the intended
00032 //               type.
00033 ////////////////////////////////////////////////////////////////////
00034 bool
00035 _dcast_verify(TypeHandle want_handle, size_t want_size, 
00036               const TypedObject *ptr) {
00037   if (get_verify_dcast()) {
00038     if ((ptr == (const TypedObject *)NULL)
00039 #if defined(_DEBUG) && defined(_WIN32)
00040         || IsBadWritePtr((TypedObject *)ptr, want_size)
00041 #endif
00042         ) {
00043       express_cat->warning()
00044         << "Attempt to cast NULL or invalid pointer to " 
00045         << want_handle << "\n";
00046       return false;
00047     }
00048     if (!ptr->is_of_type(want_handle)) {
00049       express_cat->error()
00050         << "Attempt to cast pointer from " << ptr->get_type()
00051         << " to " << want_handle << "\n";
00052       if (ptr->get_type() == TypedObject::get_class_type()) {
00053         express_cat->error(false)
00054           << "Perhaps pointer was inadvertently deleted?\n";
00055       }
00056       return false;
00057     }
00058   }
00059 
00060   return true;
00061 }
00062 #endif  // NDEBUG
00063 

Generated on Fri May 2 00:38:23 2003 for Panda by doxygen1.3