mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-11 16:32:59 +00:00
Bug 819523 part 2. Allow Nullable<> of various array types to work sanely. r=jlebar
This commit is contained in:
parent
6efc316628
commit
3dfc80459c
@ -1370,6 +1370,10 @@ public:
|
||||
return mImpl.ref();
|
||||
}
|
||||
|
||||
// If we ever decide to add conversion operators for optional arrays
|
||||
// like the ones Nullable has, we'll need to ensure that Maybe<> has
|
||||
// the boolean before the actual data.
|
||||
|
||||
private:
|
||||
// Forbid copy-construction and assignment
|
||||
Optional(const Optional& other) MOZ_DELETE;
|
||||
|
@ -9,6 +9,10 @@
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
|
||||
template<typename E, class Allocator> class nsTArray;
|
||||
template<typename E> class InfallibleTArray;
|
||||
template<typename E> class FallibleTArray;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
@ -17,17 +21,19 @@ template <typename T>
|
||||
struct Nullable
|
||||
{
|
||||
private:
|
||||
T mValue;
|
||||
// mIsNull MUST COME FIRST because otherwise the casting in our array
|
||||
// conversion operators would shift where it is found in the struct.
|
||||
bool mIsNull;
|
||||
T mValue;
|
||||
|
||||
public:
|
||||
Nullable()
|
||||
: mIsNull(true)
|
||||
{}
|
||||
|
||||
Nullable(T aValue)
|
||||
: mValue(aValue)
|
||||
, mIsNull(false)
|
||||
explicit Nullable(T aValue)
|
||||
: mIsNull(false)
|
||||
, mValue(aValue)
|
||||
{}
|
||||
|
||||
void SetValue(T aValue) {
|
||||
@ -60,6 +66,30 @@ public:
|
||||
bool IsNull() const {
|
||||
return mIsNull;
|
||||
}
|
||||
|
||||
// Make it possible to use a const Nullable of an array type with other
|
||||
// array types.
|
||||
template<typename U, typename Allocator>
|
||||
operator const Nullable< nsTArray<U, Allocator> >&() const {
|
||||
// Make sure that T is ok to reinterpret to nsTArray<U, Allocator>
|
||||
const nsTArray<U, Allocator>& arr = mValue;
|
||||
(void)arr;
|
||||
return *reinterpret_cast<const Nullable< nsTArray<U, Allocator> >*>(this);
|
||||
}
|
||||
template<typename U>
|
||||
operator const Nullable< InfallibleTArray<U> >&() const {
|
||||
// Make sure that T is ok to reinterpret to InfallibleTArray<U>
|
||||
const InfallibleTArray<U>& arr = mValue;
|
||||
(void)arr;
|
||||
return *reinterpret_cast<const Nullable< InfallibleTArray<U> >*>(this);
|
||||
}
|
||||
template<typename U>
|
||||
operator const Nullable< FallibleTArray<U> >&() const {
|
||||
// Make sure that T is ok to reinterpret to FallibleTArray<U>
|
||||
const FallibleTArray<U>& arr = mValue;
|
||||
(void)arr;
|
||||
return *reinterpret_cast<const Nullable< FallibleTArray<U> >*>(this);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
Loading…
Reference in New Issue
Block a user