michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=8 sts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* A class for holding the members of a union. */ michael@0: michael@0: #ifndef mozilla_dom_UnionMember_h michael@0: #define mozilla_dom_UnionMember_h michael@0: michael@0: #include "mozilla/Alignment.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: // The union type has an enum to keep track of which of its UnionMembers has michael@0: // been constructed. michael@0: template michael@0: class UnionMember michael@0: { michael@0: AlignedStorage2 mStorage; michael@0: michael@0: public: michael@0: T& SetValue() michael@0: { michael@0: new (mStorage.addr()) T(); michael@0: return *mStorage.addr(); michael@0: } michael@0: template michael@0: T& SetValue(const T1& aValue) michael@0: { michael@0: new (mStorage.addr()) T(aValue); michael@0: return *mStorage.addr(); michael@0: } michael@0: template michael@0: T& SetValue(const T1& aValue1, const T2& aValue2) michael@0: { michael@0: new (mStorage.addr()) T(aValue1, aValue2); michael@0: return *mStorage.addr(); michael@0: } michael@0: T& Value() michael@0: { michael@0: return *mStorage.addr(); michael@0: } michael@0: const T& Value() const michael@0: { michael@0: return *mStorage.addr(); michael@0: } michael@0: void Destroy() michael@0: { michael@0: mStorage.addr()->~T(); michael@0: } michael@0: }; michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_dom_UnionMember_h