diff options
author | gspencer@google.com <gspencer@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-24 17:29:24 +0000 |
---|---|---|
committer | gspencer@google.com <gspencer@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-24 17:29:24 +0000 |
commit | f08f8a20f786ea60745fbb3fce5a15dc1fbc6ed0 (patch) | |
tree | 220a582448a8e0f81038a87a98a3baa739fd52ab | |
parent | caeb38f22fd69de427d56291b7932250323d96cf (diff) | |
download | chromium_src-f08f8a20f786ea60745fbb3fce5a15dc1fbc6ed0.zip chromium_src-f08f8a20f786ea60745fbb3fce5a15dc1fbc6ed0.tar.gz chromium_src-f08f8a20f786ea60745fbb3fce5a15dc1fbc6ed0.tar.bz2 |
This fixes types.h with a conditional block so that it provides down_cast<>,
but only in the GYP build. The GYP build uses a newer chrome/base that
doesn't provide down_cast<> anymore.
Review URL: http://codereview.chromium.org/146092
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19140 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | o3d/build/common.gypi | 3 | ||||
-rw-r--r-- | o3d/core/cross/types.h | 34 |
2 files changed, 37 insertions, 0 deletions
diff --git a/o3d/build/common.gypi b/o3d/build/common.gypi index 471700c..5e94b08 100644 --- a/o3d/build/common.gypi +++ b/o3d/build/common.gypi @@ -19,6 +19,9 @@ 'skiadir': 'third_party/skia/include', 'zlibdir': 'third_party/zlib', }, + 'defines': [ + 'GYP_BUILD', # Needed to make a change in base/types.h conditional. + ], 'conditions' : [ ['OS == "win"', { diff --git a/o3d/core/cross/types.h b/o3d/core/cross/types.h index 5c17851..f7b817e 100644 --- a/o3d/core/cross/types.h +++ b/o3d/core/cross/types.h @@ -105,6 +105,40 @@ // We can add more sophisticated per-platform #defines as necessary here #define IS_LITTLE_ENDIAN 1 +#if defined(GYP_BUILD) +// We only need this in the gyp build because we're using the current +// chrome/base, which doesn't have down_cast in it anymore. +// TODO(gspencer): Remove this #ifdef when we are moved fully over to +// gyp. + +// When you upcast (that is, cast a pointer from type Foo to type +// SuperclassOfFoo), it's fine to use implicit_cast<>, since upcasts +// always succeed. When you downcast (that is, cast a pointer from +// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because +// how do you know the pointer is really of type SubclassOfFoo? It +// could be a bare Foo, or of type DifferentSubclassOfFoo. Thus, when +// you downcast, you should use this template. +// +// NOTE: We used to do a dynamic_cast in debug mode to make sure it +// was the right type, but now that RTTI is completely turned off, we +// just do the implicit_cast compile-time check. +// +// Use it like this: down_cast<T*>(foo); + +template<typename To, typename From> +inline To down_cast(From* f) { // Defined as From* so we only accept pointers. + // Ensures that To is a sub-type of From *. This test is here only + // for compile-time type checking, and has no overhead in an + // optimized build at run-time, as it will be optimized away + // completely. + if (false) { + implicit_cast<From*, To>(0); + } + + return static_cast<To>(f); +} +#endif // GYP_BUILD + namespace o3d { // String |