Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 684 | 684 |
| 685 template<typename U> | 685 template<typename U> |
| 686 Result(const Member<U>& other) | 686 Result(const Member<U>& other) |
| 687 : m_raw(other.raw()) | 687 : m_raw(other.raw()) |
| 688 #ifndef NDEBUG | 688 #ifndef NDEBUG |
| 689 , m_doNotAllocate() | 689 , m_doNotAllocate() |
| 690 #endif | 690 #endif |
| 691 { | 691 { |
| 692 } | 692 } |
| 693 | 693 |
| 694 template<typename U> | |
|
Mads Ager (chromium)
2013/08/16 10:23:41
We really shouldn't be using this unless we really
Erik Corry
2013/08/16 11:39:27
Done.
| |
| 695 Result(const Member<U>* other) | |
| 696 : m_raw(other->raw()) | |
| 697 #ifndef NDEBUG | |
| 698 , m_doNotAllocate() | |
| 699 #endif | |
| 700 { | |
| 701 } | |
| 702 | |
| 694 ~Result() | 703 ~Result() |
| 695 { | 704 { |
| 696 } | 705 } |
| 697 | 706 |
| 698 template<typename U> | 707 template<typename U> |
| 699 Result& operator=(const Persistent<U>& other) | 708 Result& operator=(const Persistent<U>& other) |
| 700 { | 709 { |
| 701 COMPILE_ASSERT(!sizeof(T*), Result_should_never_be_assigned_to); | 710 COMPILE_ASSERT(!sizeof(T*), Result_should_never_be_assigned_to); |
| 702 return *this; | 711 return *this; |
| 703 } | 712 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 722 return *this; | 731 return *this; |
| 723 } | 732 } |
| 724 | 733 |
| 725 template<typename U> | 734 template<typename U> |
| 726 Result& operator=(const Member<U>& other) | 735 Result& operator=(const Member<U>& other) |
| 727 { | 736 { |
| 728 COMPILE_ASSERT(!sizeof(T*), Result_should_never_be_assigned_to); | 737 COMPILE_ASSERT(!sizeof(T*), Result_should_never_be_assigned_to); |
| 729 return *this; | 738 return *this; |
| 730 } | 739 } |
| 731 | 740 |
| 741 template<typename U> | |
| 742 Result& operator=(const Member<U>* other) | |
| 743 { | |
| 744 COMPILE_ASSERT(!sizeof(T*), Result_should_never_be_assigned_to); | |
| 745 return *this; | |
| 746 } | |
| 747 | |
| 732 template<typename U> bool operator==(const U* other) const { return other == m_raw; } | 748 template<typename U> bool operator==(const U* other) const { return other == m_raw; } |
| 733 template<typename U> bool operator!=(const U* other) const { return other != m_raw; } | 749 template<typename U> bool operator!=(const U* other) const { return other != m_raw; } |
| 734 | 750 |
| 735 template<typename U> bool operator==(const Handle<U>& other) const { return other.raw() == m_raw; } | 751 template<typename U> bool operator==(const Handle<U>& other) const { return other.raw() == m_raw; } |
| 736 template<typename U> bool operator!=(const Handle<U>& other) const { return other.raw() != m_raw; } | 752 template<typename U> bool operator!=(const Handle<U>& other) const { return other.raw() != m_raw; } |
| 737 | 753 |
| 738 template<typename U> bool operator==(const Result<U>& other) const { return other.m_raw == m_raw; } | 754 template<typename U> bool operator==(const Result<U>& other) const { return other.m_raw == m_raw; } |
| 739 template<typename U> bool operator!=(const Result<U>& other) const { return other.m_raw != m_raw; } | 755 template<typename U> bool operator!=(const Result<U>& other) const { return other.m_raw != m_raw; } |
| 740 | 756 |
| 741 template<typename U> bool operator==(const Persistent<U>& other) const { ret urn other.raw() == m_raw; } | 757 template<typename U> bool operator==(const Persistent<U>& other) const { ret urn other.raw() == m_raw; } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 807 } | 823 } |
| 808 | 824 |
| 809 // Mutable to allow raw() to steal the pointer when creating a | 825 // Mutable to allow raw() to steal the pointer when creating a |
| 810 // Handle from the Result. | 826 // Handle from the Result. |
| 811 mutable T* m_raw; | 827 mutable T* m_raw; |
| 812 | 828 |
| 813 #ifndef NDEBUG | 829 #ifndef NDEBUG |
| 814 mutable NoAllocation m_doNotAllocate; | 830 mutable NoAllocation m_doNotAllocate; |
| 815 #endif | 831 #endif |
| 816 | 832 |
| 833 template<typename U> friend void Visitor::visit(const class Result<U>&); | |
| 817 template<typename U> friend class Persistent; | 834 template<typename U> friend class Persistent; |
| 818 template<typename U> friend class Handle; | 835 template<typename U> friend class Handle; |
| 819 template<typename U> friend class Member; | 836 template<typename U> friend class Member; |
| 820 template<typename U> friend class Result; | 837 template<typename U> friend class Result; |
| 821 template<typename U> friend Result<U> adopt(U*); | 838 template<typename U> friend Result<U> adopt(U*); |
| 822 template<typename U> friend Result<U> adoptRawResult(U*); | 839 template<typename U> friend Result<U> adoptRawResult(U*); |
| 823 template<typename U> friend Result<U> adoptTreeShared(U*); | 840 template<typename U> friend Result<U> adoptTreeShared(U*); |
| 824 template<typename U, typename V> friend bool operator==(const Handle<U>&, co nst Result<V>&); | 841 template<typename U, typename V> friend bool operator==(const Handle<U>&, co nst Result<V>&); |
| 825 template<typename U, typename V> friend bool operator!=(const Handle<U>&, co nst Result<V>&); | 842 template<typename U, typename V> friend bool operator!=(const Handle<U>&, co nst Result<V>&); |
| 826 template<typename U, typename V> friend bool Member<U>::operator==(const Res ult<V>&); | 843 template<typename U, typename V> friend bool Member<U>::operator==(const Res ult<V>&); |
| (...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1453 // non-heap allocated hashes must arrange their own visiting. Eg. | 1470 // non-heap allocated hashes must arrange their own visiting. Eg. |
| 1454 // CollectionRoot visits the members in the collections it contains. | 1471 // CollectionRoot visits the members in the collections it contains. |
| 1455 static const bool needsVisiting = true; | 1472 static const bool needsVisiting = true; |
| 1456 | 1473 |
| 1457 static const bool needsDestruction = false; | 1474 static const bool needsDestruction = false; |
| 1458 // FIXME(oilpan): The distinction between PeekInType and PassInType is | 1475 // FIXME(oilpan): The distinction between PeekInType and PassInType is |
| 1459 // there for the sake of the reference counting handles. When they are gone | 1476 // there for the sake of the reference counting handles. When they are gone |
| 1460 // the two types can be merged into PassInType. | 1477 // the two types can be merged into PassInType. |
| 1461 typedef const typename WebCore::Handle<T>& PeekInType; | 1478 typedef const typename WebCore::Handle<T>& PeekInType; |
| 1462 typedef const typename WebCore::Handle<T>& PassInType; | 1479 typedef const typename WebCore::Handle<T>& PassInType; |
| 1480 typedef WebCore::Result<T> IteratorGetType; | |
| 1481 typedef WebCore::Result<T> IteratorConstGetType; | |
| 1482 typedef WebCore::Result<T> IteratorReferenceType; | |
| 1483 typedef WebCore::Result<T> IteratorConstReferenceType; | |
| 1484 static IteratorReferenceType getToReferenceConversion(IteratorGetType x) { r eturn x; } | |
| 1485 static IteratorConstReferenceType getToReferenceConstConversion(IteratorCons tGetType x) { return x; } | |
| 1463 // FIXME(oilpan): Similarly, there is no need for a distinction between | 1486 // FIXME(oilpan): Similarly, there is no need for a distinction between |
| 1464 // PeekType and PassOutType without reference counting. | 1487 // PeekType and PassOutType without reference counting. |
| 1465 typedef typename WebCore::Result<T> PeekType; | 1488 typedef typename WebCore::Result<T> PeekType; |
| 1466 typedef typename WebCore::Result<T> PassOutType; | 1489 typedef typename WebCore::Result<T> PassOutType; |
| 1467 | 1490 |
| 1468 template<typename U> | 1491 template<typename U> |
| 1469 static void store(const U& value, WebCore::Member<T>& storage) { storage = v alue; } | 1492 static void store(const U& value, WebCore::Member<T>& storage) { storage = v alue; } |
| 1470 | 1493 |
| 1471 static PeekType peek(const WebCore::Member<T>& value) { return value; } | 1494 static PeekType peek(const WebCore::Member<T>& value) { return value; } |
| 1472 static PassOutType passOut(const WebCore::Member<T>& value) { return value; } | 1495 static PassOutType passOut(const WebCore::Member<T>& value) { return value; } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1487 typedef PtrHash<WebCore::Member<T> > Hash; | 1510 typedef PtrHash<WebCore::Member<T> > Hash; |
| 1488 }; | 1511 }; |
| 1489 | 1512 |
| 1490 #define DEFINE_SELF_HANDLE(Type) \ | 1513 #define DEFINE_SELF_HANDLE(Type) \ |
| 1491 Result<Type> selfHandle() { return adoptRawResult(this); } \ | 1514 Result<Type> selfHandle() { return adoptRawResult(this); } \ |
| 1492 Result<const Type> selfHandle() const { return adoptRawResult(this); } | 1515 Result<const Type> selfHandle() const { return adoptRawResult(this); } |
| 1493 | 1516 |
| 1494 } | 1517 } |
| 1495 | 1518 |
| 1496 #endif | 1519 #endif |
| OLD | NEW |