Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #ifndef SkTemplates_DEFINED | 10 #ifndef SkTemplates_DEFINED |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 /** | 482 /** |
| 483 * Returns void* because this object does not initialize the | 483 * Returns void* because this object does not initialize the |
| 484 * memory. Use placement new for types that require a cons. | 484 * memory. Use placement new for types that require a cons. |
| 485 */ | 485 */ |
| 486 void* get() { return fStorage.get(); } | 486 void* get() { return fStorage.get(); } |
| 487 const void* get() const { return fStorage.get(); } | 487 const void* get() const { return fStorage.get(); } |
| 488 private: | 488 private: |
| 489 SkAlignedSStorage<sizeof(T)*N> fStorage; | 489 SkAlignedSStorage<sizeof(T)*N> fStorage; |
| 490 }; | 490 }; |
| 491 | 491 |
| 492 /** | |
| 493 * sk_at_scope_end(stmt) evaluates stmt when the current scope ends. | |
| 494 * | |
| 495 * E.g. | |
| 496 * | |
| 497 * int x = 5; | |
| 498 * { | |
| 499 * sk_at_scope_end(x--); | |
| 500 * SkASSERT(x == 5); | |
| 501 * } | |
| 502 * SkASSERT(x == 4); | |
| 503 */ | |
| 504 | |
| 505 template <typename Fn> | |
| 506 class SkScoped { | |
|
bungeman-skia
2016/08/24 21:39:49
As far as naming goes, the current proposal (p0052
| |
| 507 public: | |
| 508 SkScoped(Fn&& fn) : fFn(std::move(fn)) {} | |
| 509 ~SkScoped() { fFn(); } | |
| 510 | |
| 511 private: | |
| 512 // It makes no sense to copy SkScoped. | |
| 513 SkScoped (const SkScoped&) = delete; | |
| 514 SkScoped& operator=(const SkScoped&) = delete; | |
| 515 | |
| 516 // We could potentially make moving SkScoped work. | |
| 517 SkScoped (SkScoped&&) = delete; | |
| 518 SkScoped& operator=(SkScoped&&) = delete; | |
| 519 | |
| 520 Fn fFn; | |
| 521 }; | |
| 522 | |
| 523 template <typename Fn> | |
| 524 static inline SkScoped<Fn> sk_make_scoped(Fn&& fn) { return { std::move(fn) }; } | |
| 525 | |
| 526 #define SCOPED_NAMEx(n) scoped_ ## n | |
| 527 #define SCOPED_NAME(n) SCOPED_NAMEx(n) | |
|
bungeman-skia
2016/08/24 21:39:49
These names seem a bit generic for something that
| |
| 528 | |
| 529 #define sk_at_scope_end(stmt) \ | |
|
bungeman-skia
2016/08/24 21:39:49
You evil person making this define look like a fun
| |
| 530 SK_UNUSED auto&& SCOPED_NAME(__COUNTER__) = sk_make_scoped([&] { stmt; }) | |
|
bungeman-skia
2016/08/24 21:39:49
Looks like we've been using SK_MACRO_APPEND_LINE f
| |
| 531 | |
| 492 #endif | 532 #endif |
| OLD | NEW |