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

Side by Side Diff: Source/wtf/Assertions.h

Issue 309083003: Add macros to define comparison operators to compare by reference or pointer interchangeably (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/rendering/RenderObject.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 #if ASSERT_DISABLED 355 #if ASSERT_DISABLED
356 #define RELEASE_ASSERT(assertion) (UNLIKELY(!(assertion)) ? (IMMEDIATE_CRASH()) : (void)0) 356 #define RELEASE_ASSERT(assertion) (UNLIKELY(!(assertion)) ? (IMMEDIATE_CRASH()) : (void)0)
357 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) RELEASE_ASSERT(assertion) 357 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) RELEASE_ASSERT(assertion)
358 #define RELEASE_ASSERT_NOT_REACHED() IMMEDIATE_CRASH() 358 #define RELEASE_ASSERT_NOT_REACHED() IMMEDIATE_CRASH()
359 #else 359 #else
360 #define RELEASE_ASSERT(assertion) ASSERT(assertion) 360 #define RELEASE_ASSERT(assertion) ASSERT(assertion)
361 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) ASSERT_WITH_MESSAGE(assertio n, __VA_ARGS__) 361 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) ASSERT_WITH_MESSAGE(assertio n, __VA_ARGS__)
362 #define RELEASE_ASSERT_NOT_REACHED() ASSERT_NOT_REACHED() 362 #define RELEASE_ASSERT_NOT_REACHED() ASSERT_NOT_REACHED()
363 #endif 363 #endif
364 364
365 /* DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES */
366
367 // Allow equality comparisons of Objects by reference or pointer, interchangeabl y.
368 #define DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES(thisType) \
369 inline bool operator==(const thisType& a, const thisType& b) { return &a == &b; } \
370 inline bool operator==(const thisType& a, const thisType* b) { return &a == b; } \
371 inline bool operator==(const thisType* a, const thisType& b) { return a == & b; } \
372 inline bool operator!=(const thisType& a, const thisType& b) { return !(a == b); } \
373 inline bool operator!=(const thisType& a, const thisType* b) { return !(a == b); } \
374 inline bool operator!=(const thisType* a, const thisType& b) { return !(a == b); }
375
376 #define DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES_REFCOUNTED(thisType) \
377 DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES(thisType) \
378 inline bool operator==(const PassRefPtr<thisType>& a, const thisType& b) { r eturn a.get() == &b; } \
379 inline bool operator==(const thisType& a, const PassRefPtr<thisType>& b) { r eturn &a == b.get(); } \
380 inline bool operator!=(const PassRefPtr<thisType>& a, const thisType& b) { r eturn !(a == b); } \
381 inline bool operator!=(const thisType& a, const PassRefPtr<thisType>& b) { r eturn !(a == b); }
382
365 /* DEFINE_TYPE_CASTS */ 383 /* DEFINE_TYPE_CASTS */
366 384
367 #define DEFINE_TYPE_CASTS(thisType, argumentType, argumentName, pointerPredicate , referencePredicate) \ 385 #define DEFINE_TYPE_CASTS(thisType, argumentType, argumentName, pointerPredicate , referencePredicate) \
368 inline thisType* to##thisType(argumentType* argumentName) \ 386 inline thisType* to##thisType(argumentType* argumentName) \
369 { \ 387 { \
370 ASSERT_WITH_SECURITY_IMPLICATION(!argumentName || (pointerPredicate)); \ 388 ASSERT_WITH_SECURITY_IMPLICATION(!argumentName || (pointerPredicate)); \
371 return static_cast<thisType*>(argumentName); \ 389 return static_cast<thisType*>(argumentName); \
372 } \ 390 } \
373 inline const thisType* to##thisType(const argumentType* argumentName) \ 391 inline const thisType* to##thisType(const argumentType* argumentName) \
374 { \ 392 { \
375 ASSERT_WITH_SECURITY_IMPLICATION(!argumentName || (pointerPredicate)); \ 393 ASSERT_WITH_SECURITY_IMPLICATION(!argumentName || (pointerPredicate)); \
376 return static_cast<const thisType*>(argumentName); \ 394 return static_cast<const thisType*>(argumentName); \
377 } \ 395 } \
378 inline thisType& to##thisType(argumentType& argumentName) \ 396 inline thisType& to##thisType(argumentType& argumentName) \
379 { \ 397 { \
380 ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate); \ 398 ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate); \
381 return static_cast<thisType&>(argumentName); \ 399 return static_cast<thisType&>(argumentName); \
382 } \ 400 } \
383 inline const thisType& to##thisType(const argumentType& argumentName) \ 401 inline const thisType& to##thisType(const argumentType& argumentName) \
384 { \ 402 { \
385 ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate); \ 403 ASSERT_WITH_SECURITY_IMPLICATION(referencePredicate); \
386 return static_cast<const thisType&>(argumentName); \ 404 return static_cast<const thisType&>(argumentName); \
387 } \ 405 } \
388 void to##thisType(const thisType*); \ 406 void to##thisType(const thisType*); \
389 void to##thisType(const thisType&) 407 void to##thisType(const thisType&)
390 408
391 #endif /* WTF_Assertions_h */ 409 #endif /* WTF_Assertions_h */
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderObject.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698