Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Unified Diff: core/cross/types.h

Issue 131116: This adds in the GYP files needed for our GYP build. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/o3d/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/core.gyp ('k') | import/import.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/cross/types.h
===================================================================
--- core/cross/types.h (revision 19090)
+++ core/cross/types.h (working copy)
@@ -105,6 +105,30 @@
// We can add more sophisticated per-platform #defines as necessary here
#define IS_LITTLE_ENDIAN 1
+// 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 macro. We used to do a
+// dynamic_cast there in debug mode just 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.
+
+template<typename To, typename From> // use like this: down_cast<T*>(foo);
+inline To down_cast(From* f) { // 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);
+}
+
namespace o3d {
// String
« no previous file with comments | « core/core.gyp ('k') | import/import.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698