Panda3D
panda
src
express
dcast.cxx
Go to the documentation of this file.
1
/**
2
* PANDA 3D SOFTWARE
3
* Copyright (c) Carnegie Mellon University. All rights reserved.
4
*
5
* All use of this software is subject to the terms of the revised BSD
6
* license. You should have received a copy of this license along
7
* with this source code in a file named "LICENSE."
8
*
9
* @file dcast.cxx
10
* @author drose
11
* @date 2001-08-07
12
*/
13
14
#include "
dcast.h
"
15
#include "
config_express.h
"
16
17
#ifdef _WIN32
18
#ifndef WIN32_LEAN_AND_MEAN
19
#define WIN32_LEAN_AND_MEAN 1
20
#endif
21
#include <windows.h>
// for IsBadWritePtr()
22
#endif
23
24
/**
25
* This function performs the actual check that the indicated TypedObject
26
* pointer is of the intended type.
27
*/
28
bool
29
_dcast_verify
(
TypeHandle
want_handle,
size_t
want_size,
30
const
TypedObject
*ptr) {
31
#ifdef DO_DCAST
32
if
(get_verify_dcast()) {
33
if
(ptr ==
nullptr
) {
34
// This is allowed these days. It used to be an error, but what the
35
// heck.
36
return
true
;
37
}
38
#if defined(_DEBUG) && defined(_WIN32)
39
if
(IsBadWritePtr((
TypedObject
*)ptr, want_size)) {
40
express_cat->warning()
41
<<
"Attempt to cast invalid pointer to "
42
<< want_handle <<
"\n"
;
43
return
false
;
44
}
45
#endif
46
if
(!ptr->
is_of_type
(want_handle)) {
47
express_cat->error()
48
<<
"Attempt to cast pointer from "
<< ptr->get_type()
49
<<
" to "
<< want_handle <<
"\n"
;
50
if
(ptr->get_type() == TypedObject::get_class_type()) {
51
express_cat->error(
false
)
52
<<
"Perhaps pointer was inadvertently deleted?\n"
;
53
}
54
return
false
;
55
}
56
}
57
#endif // DO_DCAST
58
59
return
true
;
60
}
dcast.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition:
typeHandle.h:81
_dcast_verify
bool _dcast_verify(TypeHandle want_handle, size_t want_size, const TypedObject *ptr)
This function performs the actual check that the indicated TypedObject pointer is of the intended typ...
Definition:
dcast.cxx:29
config_express.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypedObject::is_of_type
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
Definition:
typedObject.I:28
TypedObject
This is an abstract class that all classes which use TypeHandle, and also provide virtual functions t...
Definition:
typedObject.h:88
Generated on Mon Sep 14 2020 15:06:51 for Panda3D by
1.8.20